Skip to content

Commit a728961

Browse files
committed
working loop
1 parent 5bb61cd commit a728961

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

Thirdweb.Console/Program.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Nethereum.ABI;
99
using Nethereum.Hex.HexConvertors.Extensions;
1010
using Nethereum.Hex.HexTypes;
11+
using Nethereum.Util;
1112
using Newtonsoft.Json;
1213
using Newtonsoft.Json.Linq;
1314
using Thirdweb;
@@ -329,7 +330,7 @@
329330
var chain = 11155111; // sepolia
330331

331332
// Connect to EOA
332-
var userWallet = await InAppWallet.Create(client, email: "firekeeper+7702testing04@thirdweb.com");
333+
var userWallet = await InAppWallet.Create(client, email: "firekeeper+7702testing07@thirdweb.com");
333334
if (!await userWallet.IsConnected())
334335
{
335336
await userWallet.SendOTP();
@@ -339,11 +340,11 @@
339340
}
340341
Console.WriteLine($"User Wallet address: {await userWallet.GetAddress()}");
341342

342-
Console.WriteLine("Send it some gas if testing with ExecutionMode.EOA");
343-
Console.ReadLine();
343+
// Console.WriteLine("Send it some gas if testing with ExecutionMode.EOA");
344+
// Console.ReadLine();
344345

345346
// Upgrade EOA - This wallet explicitly uses EIP-7702 delegation to the thirdweb MinimalAccount (will delegate upon first tx)
346-
var smarterWallet = await SmarterWallet.Create(client, chain, userWallet, ExecutionMode.EOA);
347+
var smarterWallet = await SmarterWallet.Create(client: client, chainId: chain, userWallet: userWallet, sponsorGas: true);
347348
var smarterWalletAddress = await smarterWallet.GetAddress();
348349
Console.WriteLine($"Thirdweb Wallet address: {smarterWalletAddress}"); // same as userWallet address, unlike when using EIP-4337
349350

@@ -355,6 +356,20 @@
355356
var isDelegated = await Utils.IsDelegatedAccount(client, chain, smarterWalletAddress);
356357
Console.WriteLine($"Is delegated: {isDelegated}");
357358

359+
// Create a session key
360+
var sessionKeyReceipt = await smarterWallet.CreateSessionKey(
361+
new SessionSpec()
362+
{
363+
Signer = await Utils.GetAddressFromENS(client, "0xfirekeeper.eth"),
364+
IsWildcard = true,
365+
ExpiresAt = Utils.GetUnixTimeStampNow() + 86400, // 1 day
366+
CallPolicies = new List<CallSpec>(),
367+
TransferPolicies = new List<TransferSpec>(),
368+
Uid = Guid.NewGuid().ToByteArray().PadTo32Bytes()
369+
}
370+
);
371+
Console.WriteLine($"Session key receipt: {sessionKeyReceipt.TransactionHash}");
372+
358373
#endregion
359374

360375
#region Smart Ecosystem Wallet

Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ private ThirdwebRPC(ThirdwebClient client, BigInteger chainId)
168168
private async Task SendBatchAsync(List<RpcRequest> batch)
169169
{
170170
var batchJson = JsonConvert.SerializeObject(batch);
171-
Console.WriteLine($"Sending batch request: {batchJson}");
172171
var content = new StringContent(batchJson, Encoding.UTF8, "application/json");
173172

174173
try
@@ -183,7 +182,6 @@ private async Task SendBatchAsync(List<RpcRequest> batch)
183182
}
184183

185184
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
186-
Console.WriteLine(responseContent);
187185
if (responseContent.Equals("Unauthorized", StringComparison.OrdinalIgnoreCase))
188186
{
189187
throw new HttpRequestException("Unauthorized");

Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/BundlerClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public static async Task<TwExecuteResponse> TwExecute(
3030
{
3131
chainId = authorization?.ChainId.HexToNumber(),
3232
address = authorization?.Address,
33-
nonce = authorization?.Nonce.HexToNumber(),
33+
nonce = authorization?.Nonce.HexToNumber().ToString(),
3434
yParity = authorization?.YParity.HexToNumber(),
35-
r = authorization?.R,
36-
s = authorization?.S
35+
r = authorization?.R.HexToNumber().ToString(),
36+
s = authorization?.S.HexToNumber().ToString()
3737
}
3838
)
3939
.ConfigureAwait(false);

Thirdweb/Thirdweb.Wallets/SmarterWallet.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public async Task<ThirdwebTransactionReceipt> CreateSessionKey(SessionSpec sessi
5050
var userWalletAddress = await this.UserWallet.GetAddress();
5151
var sessionKeySig = await EIP712.GenerateSignature_SmartAccount_7702("MinimalAccount", "1", this.ChainId, userWalletAddress, sessionKeyParams, this.UserWallet);
5252
var sessionKeyCallData = this.UserContract.CreateCallData("createSessionWithSig", sessionKeyParams, sessionKeySig.HexToBytes());
53-
var sessionKeyTx = await ThirdwebTransaction.Create(this, new ThirdwebTransactionInput(chainId: this.ChainId, to: userWalletAddress, data: sessionKeyCallData));
54-
return await ThirdwebTransaction.SendAndWaitForTransactionReceipt(sessionKeyTx);
53+
return await this.ExecuteTransaction(new ThirdwebTransactionInput(chainId: this.ChainId, to: userWalletAddress, value: 0, data: sessionKeyCallData));
5554
}
5655

5756
#endregion
@@ -145,8 +144,7 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
145144
var signature = await EIP712.GenerateSignature_SmartAccount_7702_WrappedCalls("MinimalAccount", "1", this.ChainId, userWalletAddress, wrappedCalls, this.UserWallet);
146145
var response = await BundlerClient.TwExecute(
147146
client: this.Client,
148-
// url: $"{this.ChainId}.bundler.thirdweb.com",
149-
url: "http://localhost:8787?chain=11155111",
147+
url: $"https://{this.ChainId}.bundler.thirdweb.com",
150148
requestId: 7702,
151149
eoaAddress: userWalletAddress,
152150
wrappedCalls: wrappedCalls,
@@ -163,13 +161,7 @@ public async Task<string> SendTransaction(ThirdwebTransactionInput transaction)
163161
ct.Token.ThrowIfCancellationRequested();
164162

165163
var hashResponse = await BundlerClient
166-
.TwGetTransactionHash(
167-
client: this.Client,
168-
// url: $"{this.ChainId}.bundler.thirdweb.com",
169-
url: "http://localhost:8787?chain=11155111",
170-
requestId: 7702,
171-
queueId
172-
)
164+
.TwGetTransactionHash(client: this.Client, url: $"https://{this.ChainId}.bundler.thirdweb.com", requestId: 7702, queueId)
173165
.ConfigureAwait(false);
174166

175167
txHash = hashResponse?.TransactionHash;

0 commit comments

Comments
 (0)