Skip to content

Commit 31c0119

Browse files
committed
cleanup
1 parent eced8af commit 31c0119

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Thirdweb/Thirdweb.Utils/Utils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,4 +1323,9 @@ public static async Task<ThirdwebTransactionReceipt> WaitForTransactionReceipt(T
13231323

13241324
return receipt;
13251325
}
1326+
1327+
public static bool IsDelegatedAccount(string accountCode)
1328+
{
1329+
return !accountCode.Equals($"0xef0100{Constants.MINIMAL_ACCOUNT_7702[2..]}", StringComparison.OrdinalIgnoreCase);
1330+
}
13261331
}

Thirdweb/Thirdweb.Wallets/ThirdwebWallet.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static async Task<ThirdwebWallet> Create(ThirdwebClient client, BigIntege
3838

3939
var rpc = ThirdwebRPC.GetRpcInstance(client, chainId);
4040
var code = await rpc.SendRequestAsync<string>("eth_getCode", userWalletAddress, "latest");
41-
var needsDelegation = code.ToLower() != $"0xef0100{Constants.MINIMAL_ACCOUNT_7702[2..]}".ToLower();
41+
var needsDelegation = !Utils.IsDelegatedAccount(code);
4242

4343
// Sign authorization if needed
4444
EIP7702Authorization? authorization = needsDelegation ? await userWallet.SignAuthorization(chainId, Constants.MINIMAL_ACCOUNT_7702, willSelfExecute: false) : null;
@@ -56,13 +56,12 @@ public static async Task<ThirdwebWallet> Create(ThirdwebClient client, BigIntege
5656
executorWallet,
5757
new ThirdwebTransactionInput(chainId: chainId, to: userWalletAddress, data: sessionKeyCallData, authorization: authorization)
5858
);
59-
var delegationReceipt = await ThirdwebTransaction.SendAndWaitForTransactionReceipt(delegationTx);
60-
Console.WriteLine($"Delegation receipt: {delegationReceipt}");
59+
_ = await ThirdwebTransaction.SendAndWaitForTransactionReceipt(delegationTx);
6160

6261
var newCode = await rpc.SendRequestAsync<string>("eth_getCode", userWalletAddress, "latest");
63-
if (newCode.ToLower() != $"0xef0100{Constants.MINIMAL_ACCOUNT_7702[2..]}".ToLower())
62+
if (!Utils.IsDelegatedAccount(newCode))
6463
{
65-
throw new Exception("Delegation failed");
64+
throw new Exception("Delegation failed, code was not set.");
6665
}
6766

6867
var userContract = await ThirdwebContract.Create(client, userWalletAddress, chainId, delegationContract.Abi);

0 commit comments

Comments
 (0)