Skip to content

Commit 77f8944

Browse files
committed
eip7702
1 parent 2d7d927 commit 77f8944

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Thirdweb.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
// Console.WriteLine($"User Wallet address: {await userWallet.GetAddress()}");
345345

346346
// // Upgrade EOA - This wallet explicitly uses EIP-7702 delegation to the thirdweb MinimalAccount (will delegate upon first tx)
347-
// var thirdwebWallet = await ThirdwebWallet.Create(client, chain, userWallet, managedExecution: false);
347+
// var thirdwebWallet = await ThirdwebWallet.Create(client, chain, userWallet, ExecutionMode.EIP7702);
348348
// var thirdwebWalletAddress = await thirdwebWallet.GetAddress();
349349
// Console.WriteLine($"Thirdweb Wallet address: {thirdwebWalletAddress}"); // same as userWallet address, unlike when using EIP-4337
350350

Thirdweb/Thirdweb.Wallets/ThirdwebWallet.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
namespace Thirdweb;
66

7+
public enum ExecutionMode
8+
{
9+
EOA,
10+
EIP7702,
11+
EIP7702Sponsored
12+
}
13+
714
/// <summary>
815
/// Represents a 7702 delegated wallet with granular session key permissions and automatic session key execution.
916
/// </summary>
@@ -17,27 +24,29 @@ public class ThirdwebWallet : IThirdwebWallet
1724
internal IThirdwebWallet UserWallet { get; }
1825
internal ThirdwebContract UserContract { get; }
1926
internal BigInteger ChainId { get; }
20-
internal bool ManagedExecution { get; }
27+
internal ExecutionMode ExecutionMode { get; }
2128

2229
private EIP7702Authorization? Authorization { get; set; }
2330

24-
internal ThirdwebWallet(ThirdwebClient client, BigInteger chainId, IThirdwebWallet userWallet, ThirdwebContract userContract, EIP7702Authorization? authorization, bool managedExecution)
31+
internal ThirdwebWallet(ThirdwebClient client, BigInteger chainId, IThirdwebWallet userWallet, ThirdwebContract userContract, EIP7702Authorization? authorization, ExecutionMode executionMode)
2532
{
2633
this.Client = client;
2734
this.ChainId = chainId;
2835
this.UserWallet = userWallet;
2936
this.UserContract = userContract;
3037
this.Authorization = authorization;
31-
this.ManagedExecution = managedExecution;
38+
this.ExecutionMode = executionMode;
3239
}
3340

34-
public static async Task<ThirdwebWallet> Create(ThirdwebClient client, BigInteger chainId, IThirdwebWallet userWallet, bool managedExecution)
41+
public static async Task<ThirdwebWallet> Create(ThirdwebClient client, BigInteger chainId, IThirdwebWallet userWallet, ExecutionMode executionMode)
3542
{
3643
var userWalletAddress = await userWallet.GetAddress();
3744
var userContract = await ThirdwebContract.Create(client, userWalletAddress, chainId, Constants.MINIMAL_ACCOUNT_7702_ABI);
3845
var needsDelegation = !await Utils.IsDelegatedAccount(client, chainId, userWalletAddress);
39-
EIP7702Authorization? authorization = needsDelegation ? await userWallet.SignAuthorization(chainId, Constants.MINIMAL_ACCOUNT_7702, willSelfExecute: !managedExecution) : null;
40-
var wallet = new ThirdwebWallet(client, chainId, userWallet, userContract, authorization, managedExecution);
46+
EIP7702Authorization? authorization = needsDelegation
47+
? await userWallet.SignAuthorization(chainId, Constants.MINIMAL_ACCOUNT_7702, willSelfExecute: executionMode != ExecutionMode.EIP7702Sponsored)
48+
: null;
49+
var wallet = new ThirdwebWallet(client, chainId, userWallet, userContract, authorization, executionMode);
4150
Utils.TrackConnection(wallet);
4251
return wallet;
4352
}
@@ -122,16 +131,16 @@ public Task<string> SignTransaction(ThirdwebTransactionInput transaction)
122131
public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
123132
{
124133
// TODO: managed execution - executeWithSig
125-
if (this.ManagedExecution)
134+
if (this.ExecutionMode == ExecutionMode.EIP7702Sponsored)
126135
{
127-
throw new NotImplementedException("Managed execution is not yet implemented.");
136+
throw new NotImplementedException("EIP7702 Sponsored Execution mode is not yet implemented.");
128137

129138
// 1. Create payload with eoa address, wrapped calls, signature and optional authorizationList
130139
// 2. Send to https://{chainId}.bundler.thirdweb.com as RpcRequest w/ method tw_execute
131140
// 3. Retrieve tx hash or queue id from response
132141
// 4. Return tx hash
133142
}
134-
else
143+
else if (this.ExecutionMode == ExecutionMode.EIP7702)
135144
{
136145
var calls = new List<Call>
137146
{
@@ -165,6 +174,10 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
165174

166175
return await ThirdwebTransaction.Send(tx);
167176
}
177+
else
178+
{
179+
return await this.UserWallet.SendTransaction(transaction);
180+
}
168181
}
169182

170183
public async Task<ThirdwebTransactionReceipt> ExecuteTransaction(ThirdwebTransactionInput transaction)

0 commit comments

Comments
 (0)