Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions Thirdweb.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,54 @@

#endregion

#region Engine Wallet

// // EngineWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
// var engineWallet = await EngineWallet.Create(
// client: client,
// engineUrl: Environment.GetEnvironmentVariable("ENGINE_URL"),
// authToken: Environment.GetEnvironmentVariable("ENGINE_ACCESS_TOKEN"),
// walletAddress: Environment.GetEnvironmentVariable("ENGINE_BACKEND_WALLET_ADDRESS"),
// timeoutSeconds: null, // no timeout
// additionalHeaders: null // can set things like x-account-address if using basic session keys
// );

// // Simple self transfer
// var receipt = await engineWallet.Transfer(chainId: 11155111, toAddress: await engineWallet.GetAddress(), weiAmount: 0);
// Console.WriteLine($"Receipt: {receipt}");
#region Server Wallet

// You need only pass this if you are using a self-managed vault (check your dashboard Transactions tab)
var myAccessToken = Environment.GetEnvironmentVariable("VAULT_ACCESS_TOKEN");

// ServerWallet is compatible with IThirdwebWallet and can be used with any SDK method/extension
var serverWallet = await ServerWallet.Create(
client: client,
label: "Test",
// Optional, defaults to Auto - we choose between EIP-7702, EIP-4337 or native zkSync AA execution
executionOptions: new AutoExecutionOptions(),
vaultAccessToken: myAccessToken
);
var serverWalletAddress = await serverWallet.GetAddress();
Console.WriteLine($"Server Wallet address: {serverWalletAddress}");

var serverWalletPersonalSig = await serverWallet.PersonalSign("Hello, Thirdweb!");
Console.WriteLine($"Server Wallet personal sign: {serverWalletPersonalSig}");

var json =
/*lang=json,strict*/
"{\"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!\"}}";
var serverWalletTypedDataSign = await serverWallet.SignTypedDataV4(json);
Console.WriteLine($"Server Wallet typed data sign: {serverWalletTypedDataSign}");

// ServerWallet forcing ERC-4337 Execution Mode
var smartServerWallet = await ServerWallet.Create(
client: client,
label: "Test",
executionOptions: new ERC4337ExecutionOptions(chainId: 84532, signerAddress: serverWalletAddress),
vaultAccessToken: myAccessToken
);
var smartServerWalletAddress = await smartServerWallet.GetAddress();
Console.WriteLine($"Smart Server Wallet address: {smartServerWalletAddress}");

var smartServerWalletPersonalSig = await smartServerWallet.PersonalSign("Hello, Thirdweb!");
Console.WriteLine($"Smart Server Wallet personal sign: {smartServerWalletPersonalSig}");

var smartServerWalletTypedDataSign = await smartServerWallet.SignTypedDataV4(json);
Console.WriteLine($"Smart Server Wallet typed data sign: {smartServerWalletTypedDataSign}");

// Simple self transfer
var serverWalletReceipt = await serverWallet.Transfer(chainId: 421614, toAddress: await serverWallet.GetAddress(), weiAmount: 0);
Console.WriteLine($"Server Wallet Hash: {serverWalletReceipt.TransactionHash}");

// Simple self transfer
var smartServerWalletReceipt = await smartServerWallet.Transfer(chainId: 421614, toAddress: await smartServerWallet.GetAddress(), weiAmount: 0);
Console.WriteLine($"Server Wallet Hash: {smartServerWalletReceipt.TransactionHash}");

#endregion

Expand Down
1 change: 1 addition & 0 deletions Thirdweb/Thirdweb.Utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Constants
internal const string PIN_URI = "https://storage.thirdweb.com/ipfs/upload";
internal const string FALLBACK_IPFS_GATEWAY = "https://ipfs.io/ipfs/";
internal const string NEBULA_API_URL = "https://nebula-api.thirdweb.com";
internal const string ENGINE_API_URL = "https://engine.thirdweb.com";
internal const string NEBULA_DEFAULT_MODEL = "t0-003";
internal const int DEFAULT_FETCH_TIMEOUT = 120000;

Expand Down
1 change: 1 addition & 0 deletions Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Thirdweb;
/// <summary>
/// Enclave based secure cross ecosystem wallet.
/// </summary>
[Obsolete("The EngineWallet is deprecated and will be removed in a future version. Please use ServerWallet instead.")]
public partial class EngineWallet : IThirdwebWallet
{
public ThirdwebClient Client { get; }
Expand Down
119 changes: 119 additions & 0 deletions Thirdweb/Thirdweb.Wallets/ServerWallet/ServerWallet.Types.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.Numerics;
using Newtonsoft.Json;

namespace Thirdweb;

/// <summary>
/// Base class for execution options
/// </summary>
[JsonObject]
public class ExecutionOptions
{
[JsonProperty("chainId")]
public BigInteger? ChainId { get; set; } = null;

[JsonProperty("idempotencyKey")]
public string IdempotencyKey { get; set; }
}

/// <summary>
/// Auto determine execution options
/// </summary>
[JsonObject]
public class AutoExecutionOptions : ExecutionOptions
{
[JsonProperty("type")]
public string Type { get; set; } = "auto";

[JsonProperty("from")]
public string From { get; set; }
}

/// <summary>
/// ERC-4337 execution options
/// </summary>
[JsonObject]
public class ERC4337ExecutionOptions : ExecutionOptions
{
[JsonProperty("type")]
public string Type { get; set; } = "ERC4337";

[JsonProperty("signerAddress")]
public string SignerAddress { get; set; }

[JsonProperty("accountSalt")]
public string AccountSalt { get; set; }

[JsonProperty("smartAccountAddress")]
public string SmartAccountAddress { get; set; }

[JsonProperty("entrypointAddress")]
public string EntrypointAddress { get; set; }

[JsonProperty("entrypointVersion")]
public string EntrypointVersion { get; set; }

[JsonProperty("factoryAddress")]
public string FactoryAddress { get; set; }

public ERC4337ExecutionOptions(BigInteger chainId, string signerAddress)
{
this.ChainId = chainId;
this.SignerAddress = signerAddress;
}
}

/// <summary>
/// Response wrapper for queued transactions
/// </summary>
[JsonObject]
internal class QueuedTransactionResponse
{
[JsonProperty("result")]
public QueuedTransactionResult Result { get; set; }
}

/// <summary>
/// Result containing the transactions array
/// </summary>
[JsonObject]
internal class QueuedTransactionResult
{
[JsonProperty("transactions")]
public QueuedTransaction[] Transactions { get; set; }
}

/// <summary>
/// Queued transaction response
/// </summary>
[JsonObject]
internal class QueuedTransaction
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("batchIndex")]
public long BatchIndex { get; set; }

[JsonProperty("executionParams")]
public ExecutionOptions ExecutionParams { get; set; }

[JsonProperty("transactionParams")]
public InnerTransaction[] TransactionParams { get; set; }
}

/// <summary>
/// Inner transaction data
/// </summary>
[JsonObject]
internal class InnerTransaction
{
[JsonProperty("to")]
public string To { get; set; }

[JsonProperty("data")]
public string Data { get; set; }

[JsonProperty("value")]
public string Value { get; set; }
}
Loading