|
18 | 18 | // Do not use private keys client side, use InAppWallet/SmartWallet instead |
19 | 19 | var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY"); |
20 | 20 |
|
21 | | -// Initialize client |
22 | | -var client = ThirdwebClient.Create(secretKey: secretKey); |
23 | | - |
24 | | -// Chain and contract addresses |
25 | | -var chainWith7702 = 7078815900; |
26 | | -var erc20ContractAddress = "0x852e8247A55C49dc3b7e6f8788347813e562F597"; // Mekong Token |
27 | | -var delegationContractAddress = "0x7B9E7AFd452666302352D82161B083dF792f7Cf4"; // BatchCallDelegation |
28 | | - |
29 | | -// Initialize contracts normally |
30 | | -var erc20Contract = await ThirdwebContract.Create(client: client, address: erc20ContractAddress, chain: chainWith7702); |
31 | | -var delegationContract = await ThirdwebContract.Create( |
32 | | - client: client, |
33 | | - address: delegationContractAddress, |
34 | | - chain: chainWith7702, |
35 | | - abi: /*lang=json,strict*/ |
36 | | - "[{\"anonymous\": false,\"inputs\": [{\"indexed\": true,\"internalType\": \"address\",\"name\": \"to\",\"type\": \"address\"},{\"indexed\": false,\"internalType\": \"uint256\",\"name\": \"value\",\"type\": \"uint256\"},{\"indexed\": false,\"internalType\": \"bytes\",\"name\": \"data\",\"type\": \"bytes\"}],\"name\": \"Executed\",\"type\": \"event\"},{\"inputs\": [{\"components\": [{\"internalType\": \"bytes\",\"name\": \"data\",\"type\": \"bytes\"},{\"internalType\": \"address\",\"name\": \"to\",\"type\": \"address\"},{\"internalType\": \"uint256\",\"name\": \"value\",\"type\": \"uint256\"}],\"internalType\": \"struct BatchCallDelegation.Call[]\",\"name\": \"calls\",\"type\": \"tuple[]\"}],\"name\": \"execute\",\"outputs\": [],\"stateMutability\": \"payable\",\"type\": \"function\"}]" |
37 | | -); |
38 | | - |
39 | | -// Initialize a 7702 EOA |
40 | | -var eoaWallet = await PrivateKeyWallet.Generate(client); |
41 | | -var eoaWalletAddress = await eoaWallet.GetAddress(); |
42 | | -Console.WriteLine($"EOA address: {eoaWalletAddress}"); |
43 | | - |
44 | | -// // Temporary - fund eoa wallet |
45 | | -// var fundingWallet = await PrivateKeyWallet.Create(client, privateKey); |
46 | | -// var fundingHash = ( |
47 | | -// await ThirdwebTransaction.SendAndWaitForTransactionReceipt( |
48 | | -// await ThirdwebTransaction.Create(fundingWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, value: BigInteger.Parse("0.01".ToWei()))) |
49 | | -// ) |
50 | | -// ).TransactionHash; |
51 | | -// Console.WriteLine($"Funding hash: {fundingHash}"); |
52 | | - |
53 | | -// Sign the authorization to make it point to the delegation contract |
54 | | -var authorization = await eoaWallet.SignAuthorization(chainId: chainWith7702, contractAddress: delegationContractAddress, willSelfExecute: false); |
55 | | -Console.WriteLine($"Authorization: {JsonConvert.SerializeObject(authorization, Formatting.Indented)}"); |
56 | | - |
57 | | -// Initialize another wallet, the "executor" that will hit the eoa's execute function |
58 | | -var executorWallet = await PrivateKeyWallet.Create(client, privateKey); |
59 | | -var executorWalletAddress = await executorWallet.GetAddress(); |
60 | | -Console.WriteLine($"Executor address: {executorWalletAddress}"); |
61 | | - |
62 | | -// Execute the delegation |
63 | | -var tx = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, authorization: authorization)); |
64 | | -var hash = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx)).TransactionHash; |
65 | | -Console.WriteLine($"Transaction hash: {hash}"); |
66 | | - |
67 | | -// Log erc20 balance of executor before the claim |
68 | | -var executorBalanceBefore = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
69 | | -Console.WriteLine($"Executor balance before: {executorBalanceBefore}"); |
70 | | - |
71 | | -// Prepare the claim call |
72 | | -var claimCallData = erc20Contract.CreateCallData( |
73 | | - "claim", |
74 | | - new object[] |
75 | | - { |
76 | | - executorWalletAddress, // receiver |
77 | | - 100, // quantity |
78 | | - Constants.NATIVE_TOKEN_ADDRESS, // currency |
79 | | - 0, // pricePerToken |
80 | | - new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof |
81 | | - Array.Empty<byte>() // data |
82 | | - } |
83 | | -); |
84 | | - |
85 | | -// Embed the claim call in the execute call |
86 | | -var executeCallData = delegationContract.CreateCallData("execute", new object[] { new object[] { claimCallData, eoaWalletAddress, BigInteger.Zero } }); |
87 | | - |
88 | | -// Execute from the executor wallet targeting the eoa which is pointing to the delegation contract |
89 | | -var tx2 = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData)); |
90 | | -var hash2 = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx2)).TransactionHash; |
91 | | -Console.WriteLine($"Transaction hash: {hash2}"); |
92 | | - |
93 | | -// Log erc20 balance of executor after the claim |
94 | | -var executorBalanceAfter = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
95 | | -Console.WriteLine($"Executor balance after: {executorBalanceAfter}"); |
| 21 | +// Fetch timeout options are optional, default is 120000ms |
| 22 | +var client = ThirdwebClient.Create(secretKey: secretKey, fetchTimeoutOptions: new TimeoutOptions(storage: 120000, rpc: 120000, other: 120000)); |
| 23 | + |
| 24 | +// Create a private key wallet |
| 25 | +var privateKeyWallet = await PrivateKeyWallet.Generate(client: client); |
| 26 | + |
| 27 | +// var walletAddress = await privateKeyWallet.GetAddress(); |
| 28 | +// Console.WriteLine($"PK Wallet address: {walletAddress}"); |
96 | 29 |
|
97 | 30 | #region Contract Interaction |
98 | 31 |
|
99 | 32 | // var contract = await ThirdwebContract.Create(client: client, address: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", chain: 1); |
100 | | -// var result = await contract. |
| 33 | +// var nfts = await contract.ERC721_GetAllNFTs(); |
| 34 | +// Console.WriteLine($"NFTs: {JsonConvert.SerializeObject(nfts, Formatting.Indented)}"); |
101 | 35 |
|
102 | 36 | #endregion |
103 | 37 |
|
|
110 | 44 |
|
111 | 45 | #region AA 0.6 |
112 | 46 |
|
113 | | -// var smartWallet06 = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 421614); |
| 47 | +// var smartWallet06 = await SmartWallet.Create( |
| 48 | +// personalWallet: privateKeyWallet, |
| 49 | +// chainId: 421614, |
| 50 | +// gasless: true, |
| 51 | +// factoryAddress: "0xa8deE7854fb1eA8c13b713585C81d91ea86dAD84", |
| 52 | +// entryPoint: Constants.ENTRYPOINT_ADDRESS_V06 |
| 53 | +// ); |
114 | 54 |
|
115 | 55 | // var receipt06 = await smartWallet06.ExecuteTransaction(new ThirdwebTransactionInput(chainId: 421614, to: await smartWallet06.GetAddress(), value: 0, data: "0x")); |
116 | 56 |
|
|
151 | 91 |
|
152 | 92 | #endregion |
153 | 93 |
|
| 94 | +#region EIP-7702 |
| 95 | + |
| 96 | +// // Chain and contract addresses |
| 97 | +// var chainWith7702 = 911867; |
| 98 | +// var erc20ContractAddress = "0xAA462a5BE0fc5214507FDB4fB2474a7d5c69065b"; // Fake ERC20 |
| 99 | +// var delegationContractAddress = "0x654F42b74885EE6803F403f077bc0409f1066c58"; // BatchCallDelegation |
| 100 | + |
| 101 | +// // Initialize contracts normally |
| 102 | +// var erc20Contract = await ThirdwebContract.Create(client: client, address: erc20ContractAddress, chain: chainWith7702); |
| 103 | +// var delegationContract = await ThirdwebContract.Create(client: client, address: delegationContractAddress, chain: chainWith7702); |
| 104 | + |
| 105 | +// // Initialize a (to-be) 7702 EOA |
| 106 | +// var eoaWallet = await PrivateKeyWallet.Generate(client); |
| 107 | +// var eoaWalletAddress = await eoaWallet.GetAddress(); |
| 108 | +// Console.WriteLine($"EOA address: {eoaWalletAddress}"); |
| 109 | + |
| 110 | +// // Initialize another wallet, the "executor" that will hit the eoa's (to-be) execute function |
| 111 | +// var executorWallet = await PrivateKeyWallet.Generate(client); |
| 112 | +// var executorWalletAddress = await executorWallet.GetAddress(); |
| 113 | +// Console.WriteLine($"Executor address: {executorWalletAddress}"); |
| 114 | + |
| 115 | +// // Fund the executor wallet |
| 116 | +// var fundingWallet = await PrivateKeyWallet.Create(client, privateKey); |
| 117 | +// var fundingHash = (await fundingWallet.Transfer(chainWith7702, executorWalletAddress, BigInteger.Parse("0.001".ToWei()))).TransactionHash; |
| 118 | +// Console.WriteLine($"Funded Executor Wallet: {fundingHash}"); |
| 119 | + |
| 120 | +// // Sign the authorization to make it point to the delegation contract |
| 121 | +// var authorization = await eoaWallet.SignAuthorization(chainId: chainWith7702, contractAddress: delegationContractAddress, willSelfExecute: false); |
| 122 | +// Console.WriteLine($"Authorization: {JsonConvert.SerializeObject(authorization, Formatting.Indented)}"); |
| 123 | + |
| 124 | +// // Execute the delegation |
| 125 | +// var tx = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: executorWalletAddress, authorization: authorization)); |
| 126 | +// var hash = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx)).TransactionHash; |
| 127 | +// Console.WriteLine($"Authorization execution transaction hash: {hash}"); |
| 128 | + |
| 129 | +// // Prove that code has been deployed to the eoa |
| 130 | +// var rpc = ThirdwebRPC.GetRpcInstance(client, chainWith7702); |
| 131 | +// var code = await rpc.SendRequestAsync<string>("eth_getCode", eoaWalletAddress, "latest"); |
| 132 | +// Console.WriteLine($"EOA code: {code}"); |
| 133 | + |
| 134 | +// // Log erc20 balance of executor before the claim |
| 135 | +// var executorBalanceBefore = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
| 136 | +// Console.WriteLine($"Executor balance before: {executorBalanceBefore}"); |
| 137 | + |
| 138 | +// // Prepare the claim call |
| 139 | +// var claimCallData = erc20Contract.CreateCallData( |
| 140 | +// "claim", |
| 141 | +// new object[] |
| 142 | +// { |
| 143 | +// executorWalletAddress, // receiver |
| 144 | +// 100, // quantity |
| 145 | +// Constants.NATIVE_TOKEN_ADDRESS, // currency |
| 146 | +// 0, // pricePerToken |
| 147 | +// new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof |
| 148 | +// Array.Empty<byte>() // data |
| 149 | +// } |
| 150 | +// ); |
| 151 | + |
| 152 | +// // Embed the claim call in the execute call |
| 153 | +// var executeCallData = delegationContract.CreateCallData( |
| 154 | +// method: "execute", |
| 155 | +// parameters: new object[] |
| 156 | +// { |
| 157 | +// new List<Thirdweb.Console.Call> |
| 158 | +// { |
| 159 | +// new() |
| 160 | +// { |
| 161 | +// Data = claimCallData.HexToBytes(), |
| 162 | +// To = erc20ContractAddress, |
| 163 | +// Value = BigInteger.Zero |
| 164 | +// } |
| 165 | +// } |
| 166 | +// } |
| 167 | +// ); |
| 168 | + |
| 169 | +// // Execute from the executor wallet targeting the eoa which is pointing to the delegation contract |
| 170 | +// var tx2 = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData)); |
| 171 | +// var hash2 = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx2)).TransactionHash; |
| 172 | +// Console.WriteLine($"Token claim transaction hash: {hash2}"); |
| 173 | + |
| 174 | +// // Log erc20 balance of executor after the claim |
| 175 | +// var executorBalanceAfter = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
| 176 | +// Console.WriteLine($"Executor balance after: {executorBalanceAfter}"); |
| 177 | + |
| 178 | +#endregion |
| 179 | + |
154 | 180 | #region Smart Ecosystem Wallet |
155 | 181 |
|
156 | 182 | // var eco = await EcosystemWallet.Create(client: client, ecosystemId: "ecosystem.the-bonfire", authProvider: AuthProvider.Twitch); |
|
0 commit comments