|
18 | 18 | // Do not use private keys client side, use InAppWallet/SmartWallet instead |
19 | 19 | var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY"); |
20 | 20 |
|
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}"); |
| 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 | +await ThirdwebTransaction.SendAndWaitForTransactionReceipt( |
| 47 | + await ThirdwebTransaction.Create(fundingWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, value: BigInteger.Parse("0.1".ToWei()))) |
| 48 | +); |
| 49 | + |
| 50 | +// Sign the authorization to make it point to the delegation contract |
| 51 | +var authorization = await eoaWallet.SignAuthorization(chainId: chainWith7702, contractAddress: delegationContractAddress, willSelfExecute: true); |
| 52 | +Console.WriteLine($"Authorization: {JsonConvert.SerializeObject(authorization, Formatting.Indented)}"); |
| 53 | + |
| 54 | +// Execute the delegation |
| 55 | +var tx = await ThirdwebTransaction.Create(eoaWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, authorization: authorization)); |
| 56 | +var hash = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx)).TransactionHash; |
| 57 | +Console.WriteLine($"Transaction hash: {hash}"); |
| 58 | + |
| 59 | +// Initialize another wallet, the "executor" that will hit the eoa's execute function |
| 60 | +var executorWallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google); |
| 61 | +if (!await executorWallet.IsConnected()) |
| 62 | +{ |
| 63 | + _ = await executorWallet.LoginWithOauth( |
| 64 | + isMobile: false, |
| 65 | + browserOpenAction: (url) => |
| 66 | + { |
| 67 | + var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true }; |
| 68 | + _ = Process.Start(psi); |
| 69 | + } |
| 70 | + ); |
| 71 | +} |
| 72 | +var executorWalletAddress = await executorWallet.GetAddress(); |
| 73 | +Console.WriteLine($"Executor address: {executorWalletAddress}"); |
| 74 | + |
| 75 | +// Log erc20 balance of executor before the claim |
| 76 | +var executorBalanceBefore = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
| 77 | +Console.WriteLine($"Executor balance before: {executorBalanceBefore}"); |
| 78 | + |
| 79 | +// Prepare the claim call |
| 80 | +var claimCallData = erc20Contract.CreateCallData( |
| 81 | + "claim", |
| 82 | + new object[] |
| 83 | + { |
| 84 | + executorWalletAddress, // receiver |
| 85 | + 100, // quantity |
| 86 | + Constants.NATIVE_TOKEN_ADDRESS, // currency |
| 87 | + 0, // pricePerToken |
| 88 | + new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof |
| 89 | + Array.Empty<byte>() // data |
| 90 | + } |
| 91 | +); |
| 92 | + |
| 93 | +// Embed the claim call in the execute call |
| 94 | +var executeCallData = delegationContract.CreateCallData("execute", new object[] { new object[] { claimCallData, eoaWalletAddress, BigInteger.Zero } }); |
| 95 | + |
| 96 | +// Execute from the executor wallet targeting the eoa which is pointing to the delegation contract |
| 97 | +var tx2 = await ThirdwebTransaction.Create(executorWallet, new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData)); |
| 98 | +var hash2 = (await ThirdwebTransaction.SendAndWaitForTransactionReceipt(tx2)).TransactionHash; |
| 99 | +Console.WriteLine($"Transaction hash: {hash2}"); |
| 100 | + |
| 101 | +// Log erc20 balance of executor after the claim |
| 102 | +var executorBalanceAfter = await erc20Contract.ERC20_BalanceOf(executorWalletAddress); |
| 103 | +Console.WriteLine($"Executor balance after: {executorBalanceAfter}"); |
29 | 104 |
|
30 | 105 | #region Contract Interaction |
31 | 106 |
|
32 | 107 | // var contract = await ThirdwebContract.Create(client: client, address: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", chain: 1); |
33 | | -// var nfts = await contract.ERC721_GetAllNFTs(); |
34 | | -// Console.WriteLine($"NFTs: {JsonConvert.SerializeObject(nfts, Formatting.Indented)}"); |
| 108 | +// var result = await contract. |
35 | 109 |
|
36 | 110 | #endregion |
37 | 111 |
|
|
44 | 118 |
|
45 | 119 | #region AA 0.6 |
46 | 120 |
|
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 | | -// ); |
| 121 | +// var smartWallet06 = await SmartWallet.Create(personalWallet: privateKeyWallet, chainId: 421614); |
54 | 122 |
|
55 | 123 | // var receipt06 = await smartWallet06.ExecuteTransaction(new ThirdwebTransactionInput(chainId: 421614, to: await smartWallet06.GetAddress(), value: 0, data: "0x")); |
56 | 124 |
|
|
0 commit comments