|
25 | 25 | var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY"); |
26 | 26 |
|
27 | 27 | // Fetch timeout options are optional, default is 120000ms |
28 | | -var client = ThirdwebClient.Create(secretKey: secretKey, fetchTimeoutOptions: new TimeoutOptions(storage: 120000, rpc: 120000, other: 120000)); |
| 28 | +var client = ThirdwebClient.Create(secretKey: secretKey, rpcOverrides: new Dictionary<BigInteger, string> { { 11155111, "https://eth-sepolia.public.blastapi.io" } }); |
29 | 29 |
|
30 | | -// Create a private key wallet |
31 | | -var privateKeyWallet = await PrivateKeyWallet.Generate(client: client); |
| 30 | +// Create a private key wallet |
| 31 | +var privateKeyWallet = await PrivateKeyWallet.Generate(client); |
32 | 32 |
|
33 | 33 | // var walletAddress = await privateKeyWallet.GetAddress(); |
34 | 34 | // Console.WriteLine($"PK Wallet address: {walletAddress}"); |
|
229 | 229 |
|
230 | 230 | #region EIP-7702 |
231 | 231 |
|
232 | | -// // -------------------------------------------------------------------------- |
233 | | -// // Configuration |
234 | | -// // -------------------------------------------------------------------------- |
| 232 | +// // The session key signer |
| 233 | +// var executorWallet = await PrivateKeyWallet.Create(client, privateKey); // needs to be funded, for now |
235 | 234 |
|
236 | | -// var chainWith7702 = 911867; |
237 | | -// var delegationContractAddress = "0xb012446cba783d0f7723daf96cf4c49005022307"; // MinimalAccount |
238 | | - |
239 | | -// // Required environment variables |
240 | | -// var backendWalletAddress = Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS") ?? throw new Exception("ENGINE_BACKEND_WALLET_ADDRESS is required"); |
241 | | -// var engineUrl = Environment.GetEnvironmentVariable("ENGINE_URL") ?? throw new Exception("ENGINE_URL is required"); |
242 | | -// var engineAccessToken = Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN") ?? throw new Exception("ENGINE_ACCESS_TOKEN is required"); |
243 | | - |
244 | | -// // -------------------------------------------------------------------------- |
245 | | -// // Initialize Engine Wallet |
246 | | -// // -------------------------------------------------------------------------- |
247 | | - |
248 | | -// var engineWallet = await EngineWallet.Create(client, engineUrl, engineAccessToken, backendWalletAddress, 15); |
249 | | - |
250 | | -// // -------------------------------------------------------------------------- |
251 | | -// // Delegation Contract Implementation |
252 | | -// // -------------------------------------------------------------------------- |
253 | | - |
254 | | -// var delegationContract = await ThirdwebContract.Create(client, delegationContractAddress, chainWith7702); |
255 | | - |
256 | | -// // Initialize a (to-be) 7702 EOA |
257 | | -// var eoaWallet = await PrivateKeyWallet.Generate(client); |
258 | | -// var eoaWalletAddress = await eoaWallet.GetAddress(); |
259 | | -// Console.WriteLine($"EOA address: {eoaWalletAddress}"); |
260 | | - |
261 | | -// // Sign the authorization to point to the delegation contract |
262 | | -// var authorization = await eoaWallet.SignAuthorization(chainWith7702, delegationContractAddress, willSelfExecute: false); |
263 | | -// Console.WriteLine($"Authorization: {JsonConvert.SerializeObject(authorization, Formatting.Indented)}"); |
264 | | - |
265 | | -// // Sign message for session key |
266 | | -// var sessionKeyParams = new SessionKeyParams_7702() |
| 235 | +// // Session key permissions |
| 236 | +// var sessionKeyParams = new SessionSpec() |
267 | 237 | // { |
268 | | -// Signer = backendWalletAddress, |
269 | | -// NativeTokenLimitPerTransaction = 0, |
270 | | -// StartTimestamp = 0, |
271 | | -// EndTimestamp = Utils.GetUnixTimeStampNow() + (3600 * 24), |
272 | | -// ApprovedTargets = new List<string> { Constants.ADDRESS_ZERO }, |
273 | | -// Uid = Guid.NewGuid().ToByteArray() |
274 | | -// }; |
275 | | -// var sessionKeySig = await EIP712.GenerateSignature_SmartAccount_7702("MinimalAccount", "1", chainWith7702, eoaWalletAddress, sessionKeyParams, eoaWallet); |
276 | | - |
277 | | -// // Create call data for the session key |
278 | | -// var sessionKeyCallData = delegationContract.CreateCallData("createSessionKeyWithSig", sessionKeyParams, sessionKeySig.HexToBytes()); |
279 | | - |
280 | | -// // Execute the delegation & session key creation in one go, from the backend! |
281 | | -// var delegationReceipt = await engineWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: sessionKeyCallData, authorization: authorization)); |
282 | | -// Console.WriteLine($"Delegation Execution Receipt: {JsonConvert.SerializeObject(delegationReceipt, Formatting.Indented)}"); |
283 | | - |
284 | | -// // Verify contract code deployed to the EOA |
285 | | -// var rpc = ThirdwebRPC.GetRpcInstance(client, chainWith7702); |
286 | | -// var code = await rpc.SendRequestAsync<string>("eth_getCode", eoaWalletAddress, "latest"); |
287 | | -// Console.WriteLine($"EOA code: {code}"); |
288 | | - |
289 | | -// // The EOA is now a contract |
290 | | -// var eoaContract = await ThirdwebContract.Create(client, eoaWalletAddress, chainWith7702, delegationContract.Abi); |
291 | | - |
292 | | -// // -------------------------------------------------------------------------- |
293 | | -// // Mint Tokens (DropERC20) to the EOA Using the backend session key |
294 | | -// // -------------------------------------------------------------------------- |
295 | | - |
296 | | -// var erc20ContractAddress = "0xAA462a5BE0fc5214507FDB4fB2474a7d5c69065b"; // DropERC20 |
297 | | -// var erc20Contract = await ThirdwebContract.Create(client, erc20ContractAddress, chainWith7702); |
298 | | - |
299 | | -// // Log ERC20 balance before mint |
300 | | -// var eoaBalanceBefore = await erc20Contract.ERC20_BalanceOf(eoaWalletAddress); |
301 | | -// Console.WriteLine($"EOA balance before: {eoaBalanceBefore}"); |
302 | | - |
303 | | -// // Create execution call data (calling 'claim' on the DropERC20) |
304 | | -// var executeCallData = eoaContract.CreateCallData( |
305 | | -// "execute", |
306 | | -// new object[] |
| 238 | +// Signer = await executorWallet.GetAddress(), |
| 239 | +// ExpiresAt = Utils.GetUnixTimeStampNow() + (3600 * 24), |
| 240 | +// CallPolicies = new List<CallSpec>() { }, |
| 241 | +// TransferPolicies = new List<TransferSpec>() |
307 | 242 | // { |
308 | | -// new List<Call> |
| 243 | +// new() |
309 | 244 | // { |
310 | | -// new() |
311 | | -// { |
312 | | -// Data = erc20Contract |
313 | | -// .CreateCallData( |
314 | | -// "claim", |
315 | | -// new object[] |
316 | | -// { |
317 | | -// eoaWalletAddress, // receiver |
318 | | -// 100, // quantity |
319 | | -// Constants.NATIVE_TOKEN_ADDRESS, // currency |
320 | | -// 0, // pricePerToken |
321 | | -// new object[] { Array.Empty<byte>(), BigInteger.Zero, BigInteger.Zero, Constants.ADDRESS_ZERO }, // allowlistProof |
322 | | -// Array.Empty<byte>() // data |
323 | | -// } |
324 | | -// ) |
325 | | -// .HexToBytes(), |
326 | | -// To = erc20ContractAddress, |
327 | | -// Value = BigInteger.Zero |
328 | | -// } |
| 245 | +// Target = await Utils.GetAddressFromENS(client, "vitalik.eth"), |
| 246 | +// MaxValuePerUse = BigInteger.Zero, |
| 247 | +// ValueLimit = new() |
329 | 248 | // } |
330 | | -// } |
331 | | -// ); |
| 249 | +// }, |
| 250 | +// Uid = Guid.NewGuid().ToByteArray() |
| 251 | +// }; |
332 | 252 |
|
333 | | -// var executeReceipt = await engineWallet.ExecuteTransaction(new ThirdwebTransactionInput(chainId: chainWith7702, to: eoaWalletAddress, data: executeCallData)); |
334 | | -// Console.WriteLine($"Execute receipt: {JsonConvert.SerializeObject(executeReceipt, Formatting.Indented)}"); |
| 253 | +// // This wallet explicitly uses 7702 delegation to the thirdweb MinimalAccount and creates a session key from which every tx will be executed |
| 254 | +// var thirdwebWallet = await ThirdwebWallet.Create(client, 11155111, privateKeyWallet, executorWallet, sessionKeyParams); |
335 | 255 |
|
336 | | -// // Log ERC20 balance after mint |
337 | | -// var eoaBalanceAfter = await erc20Contract.ERC20_BalanceOf(eoaWalletAddress); |
338 | | -// Console.WriteLine($"EOA balance after: {eoaBalanceAfter}"); |
| 256 | +// // Simple transfer, will use the session key automatically |
| 257 | +// var receipt = await thirdwebWallet.Transfer(11155111, await Utils.GetAddressFromENS(client, "vitalik.eth"), 0); |
| 258 | +// Console.WriteLine($"Receipt: {receipt}"); |
339 | 259 |
|
340 | 260 | #endregion |
341 | 261 |
|
|
0 commit comments