|
154 | 154 | // --------------------------------------------------------------------------
|
155 | 155 |
|
156 | 156 | var chainWith7702 = 911867;
|
157 |
| -var delegationContractAddress = "0x08e47c0d38feb3d849abc01e2b7fb5d3d0d626e9"; // MinimalAccount |
| 157 | +var delegationContractAddress = "0xb012446cba783d0f7723daf96cf4c49005022307"; // MinimalAccount |
158 | 158 |
|
159 | 159 | // Required environment variables
|
160 |
| -var executorWalletAddress = Environment.GetEnvironmentVariable("ENGINE_EXECUTOR_WALLET_ADDRESS") ?? throw new Exception("ENGINE_EXECUTOR_WALLET_ADDRESS is required"); |
| 160 | +var backendWalletAddress = Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS") ?? throw new Exception("ENGINE_BACKEND_WALLET_ADDRESS is required"); |
161 | 161 | var engineUrl = Environment.GetEnvironmentVariable("ENGINE_URL") ?? throw new Exception("ENGINE_URL is required");
|
162 | 162 | var engineAccessToken = Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN") ?? throw new Exception("ENGINE_ACCESS_TOKEN is required");
|
163 | 163 |
|
164 | 164 | // --------------------------------------------------------------------------
|
165 | 165 | // Initialize Engine Wallet
|
166 | 166 | // --------------------------------------------------------------------------
|
167 | 167 |
|
168 |
| -var engineWallet = await EngineWallet.Create(client, engineUrl, engineAccessToken, executorWalletAddress, 15); |
| 168 | +var engineWallet = await EngineWallet.Create(client, engineUrl, engineAccessToken, backendWalletAddress, 15); |
169 | 169 |
|
170 | 170 | // --------------------------------------------------------------------------
|
171 | 171 | // Delegation Contract Implementation
|
|
185 | 185 | // Sign message for session key
|
186 | 186 | var sessionKeyParams = new SessionKeyParams_7702()
|
187 | 187 | {
|
188 |
| - Signer = executorWalletAddress, |
| 188 | + Signer = backendWalletAddress, |
189 | 189 | NativeTokenLimitPerTransaction = 0,
|
190 | 190 | StartTimestamp = 0,
|
191 | 191 | EndTimestamp = Utils.GetUnixTimeStampNow() + (3600 * 24),
|
|
210 | 210 | var eoaContract = await ThirdwebContract.Create(client, eoaWalletAddress, chainWith7702, delegationContract.Abi);
|
211 | 211 |
|
212 | 212 | // --------------------------------------------------------------------------
|
213 |
| -// Mint Tokens (DropERC20) to the EOA Using the Executor |
| 213 | +// Mint Tokens (DropERC20) to the EOA Using the backend session key |
214 | 214 | // --------------------------------------------------------------------------
|
215 | 215 |
|
216 | 216 | var erc20ContractAddress = "0xAA462a5BE0fc5214507FDB4fB2474a7d5c69065b"; // DropERC20
|
|
225 | 225 | "execute",
|
226 | 226 | new object[]
|
227 | 227 | {
|
228 |
| - new List<Thirdweb.Console.Call> |
| 228 | + new List<Call> |
229 | 229 | {
|
230 | 230 | new()
|
231 | 231 | {
|
|
257 | 257 | var eoaBalanceAfter = await erc20Contract.ERC20_BalanceOf(eoaWalletAddress);
|
258 | 258 | Console.WriteLine($"EOA balance after: {eoaBalanceAfter}");
|
259 | 259 |
|
| 260 | +// -------------------------------------------------------------------------- |
| 261 | +// Mint Tokens (DropERC20) to the EOA Using an alternative executor |
| 262 | +// -------------------------------------------------------------------------- |
| 263 | + |
| 264 | +// Executor wallet (managed) |
| 265 | +var executorWallet = await PrivateKeyWallet.Create(client, privateKey); |
| 266 | + |
| 267 | +// Log ERC20 balance before mint |
| 268 | +eoaBalanceBefore = await erc20Contract.ERC20_BalanceOf(eoaWalletAddress); |
| 269 | +Console.WriteLine($"EOA balance before: {eoaBalanceBefore}"); |
| 270 | + |
| 271 | +// Sign wrapped calls 712 using an authorized session key (backend wallet in this case) |
| 272 | +var wrappedCalls = new WrappedCalls() |
| 273 | +{ |
| 274 | + Calls = new List<Call> |
| 275 | + { |
| 276 | + new() |
| 277 | + { |
| 278 | + Data = erc20Contract |
| 279 | + .CreateCallData( |
| 280 | + "claim", |
| 281 | + new object[] |
| 282 | + { |
| 283 | + eoaWalletAddress, // receiver |
| 284 | + 100, // quantity |
| 285 | + Constants.NATIVE_TOKEN_ADDRESS, // currency |
| 286 | + 0, // pricePerToken |
| 287 | + new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof |
| 288 | + Array.Empty<byte>() // data |
| 289 | + } |
| 290 | + ) |
| 291 | + .HexToBytes(), |
| 292 | + To = erc20ContractAddress, |
| 293 | + Value = BigInteger.Zero |
| 294 | + } |
| 295 | + }, |
| 296 | + Uid = Guid.NewGuid().ToByteArray().BytesToHex().HexToBytes32() |
| 297 | +}; |
| 298 | +var wrappedCallsSig = await EIP712.GenerateSignature_SmartAccount_7702_WrappedCalls("MinimalAccount", "1", chainWith7702, eoaWalletAddress, wrappedCalls, engineWallet); |
| 299 | + |
| 300 | +// Create execution call data, this time in a way that can be broadcast by anyone |
| 301 | +executeCallData = eoaContract.CreateCallData("executeWithSig", wrappedCalls, wrappedCallsSig.HexToBytes()); |
| 302 | + |
| 303 | +var executeTx = await ThirdwebTransaction.Create(wallet: executorWallet, txInput: new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData)); |
| 304 | +executeReceipt = await ThirdwebTransaction.SendAndWaitForTransactionReceipt(executeTx); |
| 305 | +Console.WriteLine($"Execute receipt: {JsonConvert.SerializeObject(executeReceipt, Formatting.Indented)}"); |
| 306 | + |
| 307 | +// Log ERC20 balance after mint |
| 308 | +eoaBalanceAfter = await erc20Contract.ERC20_BalanceOf(eoaWalletAddress); |
| 309 | +Console.WriteLine($"EOA balance after: {eoaBalanceAfter}"); |
| 310 | + |
260 | 311 | #endregion
|
261 | 312 |
|
262 | 313 | #region Smart Ecosystem Wallet
|
|
0 commit comments