Skip to content

Commit de9b0a2

Browse files
authored
Add ServerWallet implementation and deprecate EngineWallet (#153)
1 parent f22a57b commit de9b0a2

File tree

5 files changed

+638
-11
lines changed

5 files changed

+638
-11
lines changed

Thirdweb.Console/Program.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var privateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
2828

2929
// Fetch timeout options are optional, default is 120000ms
30-
var client = ThirdwebClient.Create(secretKey: secretKey);
30+
var client = ThirdwebClient.Create(secretKey: "4qXoZMCqQo9SD8YkrdvO5Ci9gYKrgRADHSY84Q0wwKHZS53_R1QNcIs2XbFBWR0xE7HTQPER45T1sN1JvdFKlA");
3131

3232
// Create a private key wallet
3333
var privateKeyWallet = await PrivateKeyWallet.Generate(client);
@@ -340,21 +340,46 @@
340340

341341
#endregion
342342

343-
#region Engine Wallet
343+
#region Server Wallet
344344

345-
// // EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
346-
// var engineWallet = await EngineWallet.Create(
345+
// // ServerWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
346+
// var serverWallet = await ServerWallet.Create(
347347
// 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
348+
// label: "Test",
349+
// // Optional, defaults to Auto - we choose between EIP-7702, EIP-4337 or native zkSync AA execution / EOA is also available
350+
// executionOptions: new AutoExecutionOptions()
353351
// );
354352

353+
// var serverWalletAddress = await serverWallet.GetAddress();
354+
// Console.WriteLine($"Server Wallet address: {serverWalletAddress}");
355+
356+
// var serverWalletPersonalSig = await serverWallet.PersonalSign("Hello, Thirdweb!");
357+
// Console.WriteLine($"Server Wallet personal sign: {serverWalletPersonalSig}");
358+
359+
// var json =
360+
// /*lang=json,strict*/
361+
// "{\"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!\"}}";
362+
// var serverWalletTypedDataSign = await serverWallet.SignTypedDataV4(json);
363+
// Console.WriteLine($"Server Wallet typed data sign: {serverWalletTypedDataSign}");
364+
355365
// // Simple self transfer
356-
// var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0);
357-
// Console.WriteLine($"Receipt: {receipt}");
366+
// var serverWalletReceipt = await serverWallet.Transfer(chainId: 84532, toAddress: await serverWallet.GetAddress(), weiAmount: 0);
367+
// Console.WriteLine($"Server Wallet Hash: {serverWalletReceipt.TransactionHash}");
368+
369+
// // ServerWallet forcing ERC-4337 Execution Mode
370+
// var smartServerWallet = await ServerWallet.Create(client: client, label: "Test", executionOptions: new ERC4337ExecutionOptions(chainId: 84532, signerAddress: serverWalletAddress));
371+
// var smartServerWalletAddress = await smartServerWallet.GetAddress();
372+
// Console.WriteLine($"Smart Server Wallet address: {smartServerWalletAddress}");
373+
374+
// var smartServerWalletPersonalSig = await smartServerWallet.PersonalSign("Hello, Thirdweb!");
375+
// Console.WriteLine($"Smart Server Wallet personal sign: {smartServerWalletPersonalSig}");
376+
377+
// var smartServerWalletTypedDataSign = await smartServerWallet.SignTypedDataV4(json);
378+
// Console.WriteLine($"Smart Server Wallet typed data sign: {smartServerWalletTypedDataSign}");
379+
380+
// // Simple self transfer
381+
// var smartServerWalletReceipt = await smartServerWallet.Transfer(chainId: 84532, toAddress: await smartServerWallet.GetAddress(), weiAmount: 0);
382+
// Console.WriteLine($"Server Wallet Hash: {smartServerWalletReceipt.TransactionHash}");
358383

359384
#endregion
360385

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: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
/// Externally Owned Account (EOA) execution options
34+
/// </summary>
35+
[JsonObject]
36+
public class EIP7702ExecutionOptions : ExecutionOptions
37+
{
38+
[JsonProperty("type")]
39+
public string Type { get; set; } = "EIP7702";
40+
41+
[JsonProperty("from")]
42+
public string From { get; set; }
43+
}
44+
45+
/// <summary>
46+
/// Externally Owned Account (EOA) execution options
47+
/// </summary>
48+
[JsonObject]
49+
public class EOAExecutionOptions : ExecutionOptions
50+
{
51+
[JsonProperty("type")]
52+
public string Type { get; set; } = "EOA";
53+
54+
[JsonProperty("from")]
55+
public string From { get; set; }
56+
}
57+
58+
/// <summary>
59+
/// ERC-4337 execution options
60+
/// </summary>
61+
[JsonObject]
62+
public class ERC4337ExecutionOptions : ExecutionOptions
63+
{
64+
[JsonProperty("type")]
65+
public string Type { get; set; } = "ERC4337";
66+
67+
[JsonProperty("signerAddress")]
68+
public string SignerAddress { get; set; }
69+
70+
[JsonProperty("accountSalt")]
71+
public string AccountSalt { get; set; }
72+
73+
[JsonProperty("smartAccountAddress")]
74+
public string SmartAccountAddress { get; set; }
75+
76+
[JsonProperty("entrypointAddress")]
77+
public string EntrypointAddress { get; set; }
78+
79+
[JsonProperty("entrypointVersion")]
80+
public string EntrypointVersion { get; set; }
81+
82+
[JsonProperty("factoryAddress")]
83+
public string FactoryAddress { get; set; }
84+
85+
public ERC4337ExecutionOptions(BigInteger chainId, string signerAddress)
86+
{
87+
this.ChainId = chainId;
88+
this.SignerAddress = signerAddress;
89+
}
90+
}
91+
92+
/// <summary>
93+
/// Response wrapper for queued transactions
94+
/// </summary>
95+
[JsonObject]
96+
internal class QueuedTransactionResponse
97+
{
98+
[JsonProperty("result")]
99+
public QueuedTransactionResult Result { get; set; }
100+
}
101+
102+
/// <summary>
103+
/// Result containing the transactions array
104+
/// </summary>
105+
[JsonObject]
106+
internal class QueuedTransactionResult
107+
{
108+
[JsonProperty("transactions")]
109+
public QueuedTransaction[] Transactions { get; set; }
110+
}
111+
112+
/// <summary>
113+
/// Queued transaction response
114+
/// </summary>
115+
[JsonObject]
116+
internal class QueuedTransaction
117+
{
118+
[JsonProperty("id")]
119+
public string Id { get; set; }
120+
121+
[JsonProperty("batchIndex")]
122+
public long BatchIndex { get; set; }
123+
124+
[JsonProperty("executionParams")]
125+
public ExecutionOptions ExecutionParams { get; set; }
126+
127+
[JsonProperty("transactionParams")]
128+
public InnerTransaction[] TransactionParams { get; set; }
129+
}
130+
131+
/// <summary>
132+
/// Inner transaction data
133+
/// </summary>
134+
[JsonObject]
135+
internal class InnerTransaction
136+
{
137+
[JsonProperty("to")]
138+
public string To { get; set; }
139+
140+
[JsonProperty("data")]
141+
public string Data { get; set; }
142+
143+
[JsonProperty("value")]
144+
public string Value { get; set; }
145+
}

0 commit comments

Comments
 (0)