Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91119f7

Browse files
committed
InAppWallet EIP7702 Session Key Integration
1 parent b6541d6 commit 91119f7

File tree

3 files changed

+59
-55
lines changed

3 files changed

+59
-55
lines changed

Thirdweb.Console/Program.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -360,48 +360,48 @@
360360

361361
#region EIP-7702
362362

363-
// var chain = 11155111; // sepolia
364-
365-
// // Connect to EOA
366-
// var smartEoa = await InAppWallet.Create(client, authProvider: AuthProvider.Google, executionMode: ExecutionMode.EIP7702Sponsored);
367-
// if (!await smartEoa.IsConnected())
368-
// {
369-
// _ = await smartEoa.LoginWithOauth(
370-
// isMobile: false,
371-
// (url) =>
372-
// {
373-
// var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
374-
// _ = Process.Start(psi);
375-
// }
376-
// );
377-
// }
378-
// var smartEoaAddress = await smartEoa.GetAddress();
379-
// Console.WriteLine($"User Wallet address: {await smartEoa.GetAddress()}");
380-
381-
// // Upgrade EOA - This wallet explicitly uses EIP-7702 delegation to the thirdweb MinimalAccount (will delegate upon first tx)
382-
383-
// // Transact, will upgrade EOA
384-
// var receipt = await smartEoa.Transfer(chainId: chain, toAddress: await Utils.GetAddressFromENS(client, "vitalik.eth"), weiAmount: 0);
385-
// Console.WriteLine($"Transfer Receipt: {receipt.TransactionHash}");
386-
387-
// // Double check that it was upgraded
388-
// var isDelegated = await Utils.IsDelegatedAccount(client, chain, smartEoaAddress);
389-
// Console.WriteLine($"Is delegated: {isDelegated}");
390-
391-
// // Create a session key
392-
// var sessionKeyReceipt = await smartEoa.CreateSessionKey(
393-
// chain,
394-
// new SessionSpec()
395-
// {
396-
// Signer = await Utils.GetAddressFromENS(client, "0xfirekeeper.eth"),
397-
// IsWildcard = true,
398-
// ExpiresAt = Utils.GetUnixTimeStampNow() + 86400, // 1 day
399-
// CallPolicies = new List<CallSpec>(),
400-
// TransferPolicies = new List<TransferSpec>(),
401-
// Uid = Guid.NewGuid().ToByteArray().PadTo32Bytes()
402-
// }
403-
// );
404-
// Console.WriteLine($"Session key receipt: {sessionKeyReceipt.TransactionHash}");
363+
var chain = 11155111; // sepolia
364+
365+
// Connect to EOA
366+
var smartEoa = await InAppWallet.Create(client, authProvider: AuthProvider.Google, executionMode: ExecutionMode.EIP7702Sponsored);
367+
if (!await smartEoa.IsConnected())
368+
{
369+
_ = await smartEoa.LoginWithOauth(
370+
isMobile: false,
371+
(url) =>
372+
{
373+
var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
374+
_ = Process.Start(psi);
375+
}
376+
);
377+
}
378+
var smartEoaAddress = await smartEoa.GetAddress();
379+
Console.WriteLine($"User Wallet address: {await smartEoa.GetAddress()}");
380+
381+
// Upgrade EOA - This wallet explicitly uses EIP-7702 delegation to the thirdweb MinimalAccount (will delegate upon first tx)
382+
383+
// Transact, will upgrade EOA
384+
var receipt = await smartEoa.Transfer(chainId: chain, toAddress: await Utils.GetAddressFromENS(client, "vitalik.eth"), weiAmount: 0);
385+
Console.WriteLine($"Transfer Receipt: {receipt.TransactionHash}");
386+
387+
// Double check that it was upgraded
388+
var isDelegated = await Utils.IsDelegatedAccount(client, chain, smartEoaAddress);
389+
Console.WriteLine($"Is delegated: {isDelegated}");
390+
391+
// Create a session key
392+
var sessionKeyReceipt = await smartEoa.CreateSessionKey(
393+
chain,
394+
new SessionSpec()
395+
{
396+
Signer = await Utils.GetAddressFromENS(client, "vitalik.eth"),
397+
IsWildcard = true,
398+
ExpiresAt = Utils.GetUnixTimeStampNow() + 86400, // 1 day
399+
CallPolicies = new List<CallSpec>(),
400+
TransferPolicies = new List<TransferSpec>(),
401+
Uid = "my-session-key-uid".HashMessage().HexToBytes()
402+
}
403+
);
404+
Console.WriteLine($"Session key receipt: {sessionKeyReceipt.TransactionHash}");
405405

406406
#endregion
407407

0 commit comments

Comments
 (0)