|
52 | 52 |
|
53 | 53 | // Create smart wallet with InAppWallet signer
|
54 | 54 | var smartWallet = await SmartWallet.Create(client: client, personalWallet: inAppWallet, factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", gasless: true, chainId: 421614);
|
55 |
| - |
56 |
| -// Grant a session key to pk wallet (advanced use case) |
57 |
| -_ = await smartWallet.CreateSessionKey( |
58 |
| - signerAddress: await privateKeyWallet.GetAddress(), |
59 |
| - approvedTargets: new List<string>() { Constants.ADDRESS_ZERO }, |
60 |
| - nativeTokenLimitPerTransactionInWei: "0", |
61 |
| - permissionStartTimestamp: "0", |
62 |
| - permissionEndTimestamp: (Utils.GetUnixTimeStampNow() + 86400).ToString(), |
63 |
| - reqValidityStartTimestamp: "0", |
64 |
| - reqValidityEndTimestamp: Utils.GetUnixTimeStampIn10Years().ToString() |
65 |
| -); |
66 |
| - |
67 |
| -// Reconnect to same smart wallet with pk wallet as signer (specifying wallet address override) |
68 |
| -smartWallet = await SmartWallet.Create( |
69 |
| - client: client, |
70 |
| - personalWallet: privateKeyWallet, |
71 |
| - factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", |
72 |
| - gasless: true, |
73 |
| - chainId: 421614, |
74 |
| - accountAddressOverride: await smartWallet.GetAddress() |
75 |
| -); |
76 |
| - |
77 |
| -// Log addresses |
78 |
| -Console.WriteLine($"PrivateKey Wallet: {await privateKeyWallet.GetAddress()}"); |
79 |
| -Console.WriteLine($"InAppWallet: {await inAppWallet.GetAddress()}"); |
80 |
| -Console.WriteLine($"Smart Wallet: {await smartWallet.GetAddress()}"); |
81 |
| - |
82 |
| -// Sign, triggering deploy as needed and 1271 verification if it's a smart wallet |
83 |
| -var message = "Hello, Thirdweb!"; |
84 |
| -var signature = await smartWallet.PersonalSign(message); |
85 |
| -Console.WriteLine($"Signed message: {signature}"); |
86 |
| - |
87 |
| -var balanceBefore = await ThirdwebContract.Read<BigInteger>(contract, "balanceOf", await smartWallet.GetAddress()); |
88 |
| -Console.WriteLine($"Balance before mint: {balanceBefore}"); |
89 |
| - |
90 |
| -var writeResult = await ThirdwebContract.Write(smartWallet, contract, "mintTo", 0, await smartWallet.GetAddress(), 100); |
91 |
| -Console.WriteLine($"Contract write result: {writeResult}"); |
92 |
| - |
93 |
| -var balanceAfter = await ThirdwebContract.Read<BigInteger>(contract, "balanceOf", await smartWallet.GetAddress()); |
94 |
| -Console.WriteLine($"Balance after mint: {balanceAfter}"); |
95 |
| - |
96 |
| -// Transaction Builder |
97 |
| -var preparedTx = await ThirdwebContract.Prepare(wallet: smartWallet, contract: contract, method: "mintTo", weiValue: 0, parameters: new object[] { await smartWallet.GetAddress(), 100 }); |
98 |
| -Console.WriteLine($"Prepared transaction: {preparedTx}"); |
99 |
| -var estimatedCosts = await ThirdwebTransaction.EstimateGasCosts(preparedTx); |
100 |
| -Console.WriteLine($"Estimated ETH gas cost: {estimatedCosts.ether}"); |
101 |
| -var totalCosts = await ThirdwebTransaction.EstimateTotalCosts(preparedTx); |
102 |
| -Console.WriteLine($"Estimated ETH total cost: {totalCosts.ether}"); |
103 |
| -var simulationData = await ThirdwebTransaction.Simulate(preparedTx); |
104 |
| -Console.WriteLine($"Simulation data: {simulationData}"); |
105 |
| -var txHash = await ThirdwebTransaction.Send(preparedTx); |
106 |
| -Console.WriteLine($"Transaction hash: {txHash}"); |
107 |
| -var receipt = await ThirdwebTransaction.WaitForTransactionReceipt(client, 421614, txHash); |
108 |
| -Console.WriteLine($"Transaction receipt: {JsonConvert.SerializeObject(receipt)}"); |
109 |
| - |
110 |
| -// Transaction Builder - raw transfer |
111 |
| -var rawTx = new TransactionInput |
112 |
| -{ |
113 |
| - From = await smartWallet.GetAddress(), |
114 |
| - To = await smartWallet.GetAddress(), |
115 |
| - Value = new HexBigInteger(BigInteger.Zero), |
116 |
| - Data = "0x", |
117 |
| -}; |
118 |
| -var preparedRawTx = await ThirdwebTransaction.Create(client: client, wallet: smartWallet, txInput: rawTx, chainId: 421614); |
119 |
| -Console.WriteLine($"Prepared raw transaction: {preparedRawTx}"); |
120 |
| -var estimatedCostsRaw = await ThirdwebTransaction.EstimateGasCosts(preparedRawTx); |
121 |
| -Console.WriteLine($"Estimated ETH gas cost: {estimatedCostsRaw.ether}"); |
122 |
| -var totalCostsRaw = await ThirdwebTransaction.EstimateTotalCosts(preparedRawTx); |
123 |
| -Console.WriteLine($"Estimated ETH total cost: {totalCostsRaw.ether}"); |
124 |
| -var simulationDataRaw = await ThirdwebTransaction.Simulate(preparedRawTx); |
125 |
| -Console.WriteLine($"Simulation data: {simulationDataRaw}"); |
126 |
| -var txHashRaw = await ThirdwebTransaction.Send(preparedRawTx); |
127 |
| -Console.WriteLine($"Raw transaction hash: {txHashRaw}"); |
128 |
| -var receiptRaw = await ThirdwebTransaction.WaitForTransactionReceipt(client, 421614, txHashRaw); |
129 |
| -Console.WriteLine($"Raw transaction receipt: {JsonConvert.SerializeObject(receiptRaw)}"); |
| 55 | +var res = await smartWallet.Authenticate("http://localhost:8000", 421614); |
| 56 | +Console.WriteLine($"Smart wallet auth result: {res}"); |
| 57 | + |
| 58 | +// // Grant a session key to pk wallet (advanced use case) |
| 59 | +// _ = await smartWallet.CreateSessionKey( |
| 60 | +// signerAddress: await privateKeyWallet.GetAddress(), |
| 61 | +// approvedTargets: new List<string>() { Constants.ADDRESS_ZERO }, |
| 62 | +// nativeTokenLimitPerTransactionInWei: "0", |
| 63 | +// permissionStartTimestamp: "0", |
| 64 | +// permissionEndTimestamp: (Utils.GetUnixTimeStampNow() + 86400).ToString(), |
| 65 | +// reqValidityStartTimestamp: "0", |
| 66 | +// reqValidityEndTimestamp: Utils.GetUnixTimeStampIn10Years().ToString() |
| 67 | +// ); |
| 68 | + |
| 69 | +// // Reconnect to same smart wallet with pk wallet as signer (specifying wallet address override) |
| 70 | +// smartWallet = await SmartWallet.Create( |
| 71 | +// client: client, |
| 72 | +// personalWallet: privateKeyWallet, |
| 73 | +// factoryAddress: "0xbf1C9aA4B1A085f7DA890a44E82B0A1289A40052", |
| 74 | +// gasless: true, |
| 75 | +// chainId: 421614, |
| 76 | +// accountAddressOverride: await smartWallet.GetAddress() |
| 77 | +// ); |
| 78 | + |
| 79 | +// // Log addresses |
| 80 | +// Console.WriteLine($"PrivateKey Wallet: {await privateKeyWallet.GetAddress()}"); |
| 81 | +// Console.WriteLine($"InAppWallet: {await inAppWallet.GetAddress()}"); |
| 82 | +// Console.WriteLine($"Smart Wallet: {await smartWallet.GetAddress()}"); |
| 83 | + |
| 84 | +// // Sign, triggering deploy as needed and 1271 verification if it's a smart wallet |
| 85 | +// var message = "Hello, Thirdweb!"; |
| 86 | +// var signature = await smartWallet.PersonalSign(message); |
| 87 | +// Console.WriteLine($"Signed message: {signature}"); |
| 88 | + |
| 89 | +// var balanceBefore = await ThirdwebContract.Read<BigInteger>(contract, "balanceOf", await smartWallet.GetAddress()); |
| 90 | +// Console.WriteLine($"Balance before mint: {balanceBefore}"); |
| 91 | + |
| 92 | +// var writeResult = await ThirdwebContract.Write(smartWallet, contract, "mintTo", 0, await smartWallet.GetAddress(), 100); |
| 93 | +// Console.WriteLine($"Contract write result: {writeResult}"); |
| 94 | + |
| 95 | +// var balanceAfter = await ThirdwebContract.Read<BigInteger>(contract, "balanceOf", await smartWallet.GetAddress()); |
| 96 | +// Console.WriteLine($"Balance after mint: {balanceAfter}"); |
| 97 | + |
| 98 | +// // Transaction Builder |
| 99 | +// var preparedTx = await ThirdwebContract.Prepare(wallet: smartWallet, contract: contract, method: "mintTo", weiValue: 0, parameters: new object[] { await smartWallet.GetAddress(), 100 }); |
| 100 | +// Console.WriteLine($"Prepared transaction: {preparedTx}"); |
| 101 | +// var estimatedCosts = await ThirdwebTransaction.EstimateGasCosts(preparedTx); |
| 102 | +// Console.WriteLine($"Estimated ETH gas cost: {estimatedCosts.ether}"); |
| 103 | +// var totalCosts = await ThirdwebTransaction.EstimateTotalCosts(preparedTx); |
| 104 | +// Console.WriteLine($"Estimated ETH total cost: {totalCosts.ether}"); |
| 105 | +// var simulationData = await ThirdwebTransaction.Simulate(preparedTx); |
| 106 | +// Console.WriteLine($"Simulation data: {simulationData}"); |
| 107 | +// var txHash = await ThirdwebTransaction.Send(preparedTx); |
| 108 | +// Console.WriteLine($"Transaction hash: {txHash}"); |
| 109 | +// var receipt = await ThirdwebTransaction.WaitForTransactionReceipt(client, 421614, txHash); |
| 110 | +// Console.WriteLine($"Transaction receipt: {JsonConvert.SerializeObject(receipt)}"); |
| 111 | + |
| 112 | +// // Transaction Builder - raw transfer |
| 113 | +// var rawTx = new TransactionInput |
| 114 | +// { |
| 115 | +// From = await smartWallet.GetAddress(), |
| 116 | +// To = await smartWallet.GetAddress(), |
| 117 | +// Value = new HexBigInteger(BigInteger.Zero), |
| 118 | +// Data = "0x", |
| 119 | +// }; |
| 120 | +// var preparedRawTx = await ThirdwebTransaction.Create(client: client, wallet: smartWallet, txInput: rawTx, chainId: 421614); |
| 121 | +// Console.WriteLine($"Prepared raw transaction: {preparedRawTx}"); |
| 122 | +// var estimatedCostsRaw = await ThirdwebTransaction.EstimateGasCosts(preparedRawTx); |
| 123 | +// Console.WriteLine($"Estimated ETH gas cost: {estimatedCostsRaw.ether}"); |
| 124 | +// var totalCostsRaw = await ThirdwebTransaction.EstimateTotalCosts(preparedRawTx); |
| 125 | +// Console.WriteLine($"Estimated ETH total cost: {totalCostsRaw.ether}"); |
| 126 | +// var simulationDataRaw = await ThirdwebTransaction.Simulate(preparedRawTx); |
| 127 | +// Console.WriteLine($"Simulation data: {simulationDataRaw}"); |
| 128 | +// var txHashRaw = await ThirdwebTransaction.Send(preparedRawTx); |
| 129 | +// Console.WriteLine($"Raw transaction hash: {txHashRaw}"); |
| 130 | +// var receiptRaw = await ThirdwebTransaction.WaitForTransactionReceipt(client, 421614, txHashRaw); |
| 131 | +// Console.WriteLine($"Raw transaction receipt: {JsonConvert.SerializeObject(receiptRaw)}"); |
130 | 132 |
|
131 | 133 |
|
132 | 134 | // Storage actions
|
|
0 commit comments