Skip to content

Commit 6388ff4

Browse files
committed
Improve API and example
1 parent 06ee56b commit 6388ff4

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

Thirdweb.Console/Program.cs

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -360,41 +360,30 @@
360360

361361
#region EIP-7702
362362

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

399388
#endregion
400389

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,31 @@ public string GenerateExternalLoginLink(string redirectUrl)
450450
return $"{redirectUrl}{queryString}";
451451
}
452452

453-
public async Task<ThirdwebTransactionReceipt> CreateSessionKey(BigInteger chainId, SessionSpec sessionKeyParams)
453+
public async Task<ThirdwebTransactionReceipt> CreateSessionKey(
454+
BigInteger chainId,
455+
string signerAddress,
456+
long durationInSeconds,
457+
bool grantFullPermissions = true,
458+
List<CallSpec> callPolicies = null,
459+
List<TransferSpec> transferPolicies = null,
460+
byte[] uid = null
461+
)
454462
{
455463
if (this.ExecutionMode is not ExecutionMode.EIP7702 and not ExecutionMode.EIP7702Sponsored)
456464
{
457465
throw new InvalidOperationException("CreateSessionKey is only supported for EIP7702 and EIP7702Sponsored execution modes.");
458466
}
459467

468+
var sessionKeyParams = new SessionSpec()
469+
{
470+
Signer = signerAddress,
471+
IsWildcard = grantFullPermissions,
472+
ExpiresAt = Utils.GetUnixTimeStampNow() + durationInSeconds,
473+
CallPolicies = callPolicies ?? new List<CallSpec>(),
474+
TransferPolicies = transferPolicies ?? new List<TransferSpec>(),
475+
Uid = uid ?? Guid.NewGuid().ToByteArray()
476+
};
477+
460478
var userWalletAddress = await this.GetAddress();
461479
var sessionKeySig = await EIP712.GenerateSignature_SmartAccount_7702("MinimalAccount", "1", chainId, userWalletAddress, sessionKeyParams, this);
462480
var userContract = await ThirdwebContract.Create(this.Client, userWalletAddress, chainId, Constants.MINIMAL_ACCOUNT_7702_ABI);

0 commit comments

Comments
 (0)