Skip to content

Commit ed105d4

Browse files
committed
Add ServerWallet implementation and deprecate EngineWallet
Introduces the ServerWallet class as a replacement for EngineWallet, including execution options and transaction handling. Marks EngineWallet as obsolete. Updates the console example to use ServerWallet and adds ENGINE_API_URL to constants. Closes TOOL-5016 --Will be merged once tested w/ auto = EIP7702 in future Engine Cloud release--
1 parent f22a57b commit ed105d4

File tree

5 files changed

+613
-15
lines changed

5 files changed

+613
-15
lines changed

Thirdweb.Console/Program.cs

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,54 @@
340340

341341
#endregion
342342

343-
#region Engine Wallet
344-
345-
// // EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
346-
// var engineWallet = await EngineWallet.Create(
347-
// client: client,
348-
// engineUrl: Environment.GetEnvironmentVariable("ENGINE_URL"),
349-
// authToken: Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN"),
350-
// walletAddress: Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS"),
351-
// timeoutSeconds: null, // no timeout
352-
// additionalHeaders: null // can set things like x-account-address if using basic session keys
353-
// );
354-
355-
// // Simple self transfer
356-
// var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0);
357-
// Console.WriteLine($"Receipt: {receipt}");
343+
#region Server Wallet
344+
345+
// You need only pass this if you are using a self-managed vault (check your dashboard Transactions tab)
346+
var myAccessToken = Environment.GetEnvironmentVariable("VAULT_ACCESS_TOKEN");
347+
348+
// ServerWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
349+
var serverWallet = await ServerWallet.Create(
350+
client: client,
351+
label: "Test",
352+
// Optional, defaults to Auto - we choose between EIP-7702, EIP-4337 or native zkSync AA execution
353+
executionOptions: new AutoExecutionOptions(),
354+
vaultAccessToken: myAccessToken
355+
);
356+
var serverWalletAddress = await serverWallet.GetAddress();
357+
Console.WriteLine($"Server Wallet address: {serverWalletAddress}");
358+
359+
var serverWalletPersonalSig = await serverWallet.PersonalSign("Hello, Thirdweb!");
360+
Console.WriteLine($"Server Wallet personal sign: {serverWalletPersonalSig}");
361+
362+
var json =
363+
/*lang=json,strict*/
364+
"{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Person\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"wallet\",\"type\":\"address\"}],\"Mail\":[{\"name\":\"from\",\"type\":\"Person\"},{\"name\":\"to\",\"type\":\"Person\"},{\"name\":\"contents\",\"type\":\"string\"}]},\"primaryType\":\"Mail\",\"domain\":{\"name\":\"Ether Mail\",\"version\":\"1\",\"chainId\":84532,\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\"},\"message\":{\"from\":{\"name\":\"Cow\",\"wallet\":\"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826\"},\"to\":{\"name\":\"Bob\",\"wallet\":\"0xbBbBBBBbbBBBbbbBbbBbbBBbBbbBbBbBbBbbBBbB\"},\"contents\":\"Hello, Bob!\"}}";
365+
var serverWalletTypedDataSign = await serverWallet.SignTypedDataV4(json);
366+
Console.WriteLine($"Server Wallet typed data sign: {serverWalletTypedDataSign}");
367+
368+
// ServerWallet forcing ERC-4337 Execution Mode
369+
var smartServerWallet = await ServerWallet.Create(
370+
client: client,
371+
label: "Test",
372+
executionOptions: new ERC4337ExecutionOptions(chainId: 84532, signerAddress: serverWalletAddress),
373+
vaultAccessToken: myAccessToken
374+
);
375+
var smartServerWalletAddress = await smartServerWallet.GetAddress();
376+
Console.WriteLine($"Smart Server Wallet address: {smartServerWalletAddress}");
377+
378+
var smartServerWalletPersonalSig = await smartServerWallet.PersonalSign("Hello, Thirdweb!");
379+
Console.WriteLine($"Smart Server Wallet personal sign: {smartServerWalletPersonalSig}");
380+
381+
var smartServerWalletTypedDataSign = await smartServerWallet.SignTypedDataV4(json);
382+
Console.WriteLine($"Smart Server Wallet typed data sign: {smartServerWalletTypedDataSign}");
383+
384+
// Simple self transfer
385+
var serverWalletReceipt = await serverWallet.Transfer(chainId: 421614, toAddress: await serverWallet.GetAddress(), weiAmount: 0);
386+
Console.WriteLine($"Server Wallet Hash: {serverWalletReceipt.TransactionHash}");
387+
388+
// Simple self transfer
389+
var smartServerWalletReceipt = await smartServerWallet.Transfer(chainId: 421614, toAddress: await smartServerWallet.GetAddress(), weiAmount: 0);
390+
Console.WriteLine($"Server Wallet Hash: {smartServerWalletReceipt.TransactionHash}");
358391

359392
#endregion
360393

Thirdweb/Thirdweb.Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class Constants
1010
internal const string PIN_URI = "https://storage.thirdweb.com/ipfs/upload";
1111
internal const string FALLBACK_IPFS_GATEWAY = "https://ipfs.io/ipfs/";
1212
internal const string NEBULA_API_URL = "https://nebula-api.thirdweb.com";
13+
internal const string ENGINE_API_URL = "https://engine.thirdweb.com";
1314
internal const string NEBULA_DEFAULT_MODEL = "t0-003";
1415
internal const int DEFAULT_FETCH_TIMEOUT = 120000;
1516

Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Thirdweb;
1111
/// <summary>
1212
/// Enclave based secure cross ecosystem wallet.
1313
/// </summary>
14+
[Obsolete("The EngineWallet is deprecated and will be removed in a future version. Please use ServerWallet instead.")]
1415
public partial class EngineWallet : IThirdwebWallet
1516
{
1617
public ThirdwebClient Client { get; }
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System.Numerics;
2+
using Newtonsoft.Json;
3+
4+
namespace Thirdweb;
5+
6+
/// <summary>
7+
/// Base class for execution options
8+
/// </summary>
9+
[JsonObject]
10+
public class ExecutionOptions
11+
{
12+
[JsonProperty("chainId")]
13+
public BigInteger? ChainId { get; set; } = null;
14+
15+
[JsonProperty("idempotencyKey")]
16+
public string IdempotencyKey { get; set; }
17+
}
18+
19+
/// <summary>
20+
/// Auto determine execution options
21+
/// </summary>
22+
[JsonObject]
23+
public class AutoExecutionOptions : ExecutionOptions
24+
{
25+
[JsonProperty("type")]
26+
public string Type { get; set; } = "auto";
27+
28+
[JsonProperty("from")]
29+
public string From { get; set; }
30+
}
31+
32+
/// <summary>
33+
/// ERC-4337 execution options
34+
/// </summary>
35+
[JsonObject]
36+
public class ERC4337ExecutionOptions : ExecutionOptions
37+
{
38+
[JsonProperty("type")]
39+
public string Type { get; set; } = "ERC4337";
40+
41+
[JsonProperty("signerAddress")]
42+
public string SignerAddress { get; set; }
43+
44+
[JsonProperty("accountSalt")]
45+
public string AccountSalt { get; set; }
46+
47+
[JsonProperty("smartAccountAddress")]
48+
public string SmartAccountAddress { get; set; }
49+
50+
[JsonProperty("entrypointAddress")]
51+
public string EntrypointAddress { get; set; }
52+
53+
[JsonProperty("entrypointVersion")]
54+
public string EntrypointVersion { get; set; }
55+
56+
[JsonProperty("factoryAddress")]
57+
public string FactoryAddress { get; set; }
58+
59+
public ERC4337ExecutionOptions(BigInteger chainId, string signerAddress)
60+
{
61+
this.ChainId = chainId;
62+
this.SignerAddress = signerAddress;
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Response wrapper for queued transactions
68+
/// </summary>
69+
[JsonObject]
70+
internal class QueuedTransactionResponse
71+
{
72+
[JsonProperty("result")]
73+
public QueuedTransactionResult Result { get; set; }
74+
}
75+
76+
/// <summary>
77+
/// Result containing the transactions array
78+
/// </summary>
79+
[JsonObject]
80+
internal class QueuedTransactionResult
81+
{
82+
[JsonProperty("transactions")]
83+
public QueuedTransaction[] Transactions { get; set; }
84+
}
85+
86+
/// <summary>
87+
/// Queued transaction response
88+
/// </summary>
89+
[JsonObject]
90+
internal class QueuedTransaction
91+
{
92+
[JsonProperty("id")]
93+
public string Id { get; set; }
94+
95+
[JsonProperty("batchIndex")]
96+
public long BatchIndex { get; set; }
97+
98+
[JsonProperty("executionParams")]
99+
public ExecutionOptions ExecutionParams { get; set; }
100+
101+
[JsonProperty("transactionParams")]
102+
public InnerTransaction[] TransactionParams { get; set; }
103+
}
104+
105+
/// <summary>
106+
/// Inner transaction data
107+
/// </summary>
108+
[JsonObject]
109+
internal class InnerTransaction
110+
{
111+
[JsonProperty("to")]
112+
public string To { get; set; }
113+
114+
[JsonProperty("data")]
115+
public string Data { get; set; }
116+
117+
[JsonProperty("value")]
118+
public string Value { get; set; }
119+
}

0 commit comments

Comments
 (0)