Table of Contents

Class SmartWallet

Namespace
Thirdweb
Assembly
Thirdweb.dll
public class SmartWallet : IThirdwebWallet
Inheritance
SmartWallet
Implements
Inherited Members
Extension Methods

Constructors

SmartWallet(IThirdwebWallet, bool, BigInteger, string, string, ThirdwebContract, ThirdwebContract, ThirdwebContract, string, string, BigInteger)

protected SmartWallet(IThirdwebWallet personalAccount, bool gasless, BigInteger chainId, string bundlerUrl, string paymasterUrl, ThirdwebContract entryPointContract, ThirdwebContract factoryContract, ThirdwebContract accountContract, string erc20PaymasterAddress, string erc20PaymasterToken, BigInteger erc20PaymasterStorageSlot)

Parameters

personalAccount IThirdwebWallet
gasless bool
chainId BigInteger
bundlerUrl string
paymasterUrl string
entryPointContract ThirdwebContract
factoryContract ThirdwebContract
accountContract ThirdwebContract
erc20PaymasterAddress string
erc20PaymasterToken string
erc20PaymasterStorageSlot BigInteger

Properties

AccountType

Gets the account type of the wallet.

public ThirdwebAccountType AccountType { get; }

Property Value

ThirdwebAccountType

Client

Gets the Thirdweb client associated with the wallet.

public ThirdwebClient Client { get; }

Property Value

ThirdwebClient

IsDeploying

public bool IsDeploying { get; }

Property Value

bool

Methods

AddAdmin(string)

Adds a new admin to the smart account.

public Task<ThirdwebTransactionReceipt> AddAdmin(string admin)

Parameters

admin string

The address of the admin to add.

Returns

Task<ThirdwebTransactionReceipt>

The transaction receipt.

Create(IThirdwebWallet, BigInteger, bool, string, string, string, string, string, TokenPaymaster)

Creates a new instance of SmartWallet.

public static Task<SmartWallet> Create(IThirdwebWallet personalWallet, BigInteger chainId, bool gasless = true, string factoryAddress = null, string accountAddressOverride = null, string entryPoint = null, string bundlerUrl = null, string paymasterUrl = null, TokenPaymaster tokenPaymaster = TokenPaymaster.NONE)

Parameters

personalWallet IThirdwebWallet

The smart wallet's signer to use.

chainId BigInteger

The chain ID.

gasless bool

Whether to sponsor gas for transactions.

factoryAddress string

Override the default factory address.

accountAddressOverride string

Override the canonical account address that would be found deterministically based on the signer.

entryPoint string

Override the default entry point address. We provide Constants for different versions.

bundlerUrl string

Override the default thirdweb bundler URL.

paymasterUrl string

Override the default thirdweb paymaster URL.

tokenPaymaster TokenPaymaster

Use an ERC20 paymaster and sponsor gas with ERC20s. If set, factoryAddress and accountAddressOverride are ignored.

Returns

Task<SmartWallet>

A new instance of SmartWallet.

Exceptions

InvalidOperationException

Thrown if the personal account is not connected.

CreateSessionKey(string, List<string>, string, string, string, string, string)

Creates a new session key for a signer to use with the smart account.

public Task<ThirdwebTransactionReceipt> CreateSessionKey(string signerAddress, List<string> approvedTargets, string nativeTokenLimitPerTransactionInWei, string permissionStartTimestamp, string permissionEndTimestamp, string reqValidityStartTimestamp, string reqValidityEndTimestamp)

Parameters

signerAddress string

The address of the signer to create a session key for.

approvedTargets List<string>

The list of approved targets for the signer. Use a list of a single Constants.ADDRESS_ZERO to enable all contracts.

nativeTokenLimitPerTransactionInWei string

The maximum amount of native tokens the signer can send in a single transaction.

permissionStartTimestamp string

The timestamp when the permission starts. Can be set to zero.

permissionEndTimestamp string

The timestamp when the permission ends. Make use of our Utils to get UNIX timestamps.

reqValidityStartTimestamp string

The timestamp when the request validity starts. Can be set to zero.

reqValidityEndTimestamp string

The timestamp when the request validity ends. Make use of our Utils to get UNIX timestamps.

Returns

Task<ThirdwebTransactionReceipt>

Disconnect()

Disconnects the wallet (if using InAppWallet, clears session)

public Task Disconnect()

Returns

Task

EstimateUserOperationGas(ThirdwebTransactionInput)

Estimates the gas cost for a user operation. More accurate than ThirdwebTransaction estimation, but slower.

public Task<BigInteger> EstimateUserOperationGas(ThirdwebTransactionInput transaction)

Parameters

transaction ThirdwebTransactionInput

The transaction to estimate.

Returns

Task<BigInteger>

The estimated gas cost.

EthSign(byte[])

Signs a raw message using Ethereum's signing method.

public Task<string> EthSign(byte[] rawMessage)

Parameters

rawMessage byte[]

The raw message to sign.

Returns

Task<string>

The signed message.

EthSign(string)

Signs a message using Ethereum's signing method.

public Task<string> EthSign(string message)

Parameters

message string

The message to sign.

Returns

Task<string>

The signed message.

ExecuteTransaction(ThirdwebTransactionInput)

Sends a transaction and waits for its receipt.

public Task<ThirdwebTransactionReceipt> ExecuteTransaction(ThirdwebTransactionInput transactionInput)

Parameters

transactionInput ThirdwebTransactionInput

Returns

Task<ThirdwebTransactionReceipt>

The transaction receipt.

ForceDeploy()

Forces the smart account to deploy on the current chain. This is typically not necessary as the account will deploy automatically when needed.

public Task ForceDeploy()

Returns

Task

GetAddress()

Gets the address of the wallet.

public Task<string> GetAddress()

Returns

Task<string>

The wallet address.

GetAllActiveSigners()

Gets all active signers for the smart account.

public Task<List<SignerPermissions>> GetAllActiveSigners()

Returns

Task<List<SignerPermissions>>

A list of SignerPermissions.

GetAllAdmins()

Gets all admins for the smart account.

public Task<List<string>> GetAllAdmins()

Returns

Task<List<string>>

A list of admin addresses.

GetLinkedAccounts()

Returns a list of linked accounts to the current wallet.

public Task<List<LinkedAccount>> GetLinkedAccounts()

Returns

Task<List<LinkedAccount>>

A list of LinkedAccount objects.

GetPersonalWallet()

Returns the signer that was used to connect to this SmartWallet.

public Task<IThirdwebWallet> GetPersonalWallet()

Returns

Task<IThirdwebWallet>

The signer.

IsConnected()

Checks if the wallet is connected.

public Task<bool> IsConnected()

Returns

Task<bool>

True if connected, otherwise false.

IsDeployed()

Checks if the smart account is deployed on the current chain. A smart account is typically deployed when a personal message is signed or a transaction is sent.

public Task<bool> IsDeployed()

Returns

Task<bool>

True if deployed, otherwise false.

IsValidSignature(string, string)

Verifies if a signature is valid for a message using EIP-1271.

public Task<bool> IsValidSignature(string message, string signature)

Parameters

message string

The message to verify.

signature string

The signature to verify.

Returns

Task<bool>

True if the signature is valid, otherwise false.

LinkAccount(IThirdwebWallet, string, bool?, Action<string>, string, IThirdwebBrowser, BigInteger?, string, string)

Links a new account (auth method) to the current wallet. The current wallet must be connected and the wallet being linked must not be fully connected ie created.

public Task<List<LinkedAccount>> LinkAccount(IThirdwebWallet walletToLink, string otp = null, bool? isMobile = null, Action<string> browserOpenAction = null, string mobileRedirectScheme = "thirdweb://", IThirdwebBrowser browser = null, BigInteger? chainId = null, string jwt = null, string payload = null)

Parameters

walletToLink IThirdwebWallet

The wallet to link.

otp string

The OTP code if the wallet to link is an email or phone wallet.

isMobile bool?

Set to true if linking OAuth on mobile.

browserOpenAction Action<string>

The action to open the browser if linking OAuth.

mobileRedirectScheme string

The redirect scheme if linking OAuth on mobile.

browser IThirdwebBrowser

The browser to use if linking OAuth.

chainId BigInteger?

The chain ID if linking an external wallet (SIWE).

jwt string

The JWT token if linking custom JWT auth.

payload string

The login payload if linking custom AuthEndpoint auth.

Returns

Task<List<LinkedAccount>>

A list of LinkedAccount objects.

PersonalSign(byte[])

Signs a raw message using personal signing.

public Task<string> PersonalSign(byte[] rawMessage)

Parameters

rawMessage byte[]

The raw message to sign.

Returns

Task<string>

The signed message.

PersonalSign(string)

Signs a message with the personal account. If the smart account is deployed, the message will be wrapped 712 and signed by the smart account and verified with 1271. If the smart account is not deployed, it will deploy it first.

public Task<string> PersonalSign(string message)

Parameters

message string

The message to sign.

Returns

Task<string>

The signature.

RecoverAddressFromEthSign(string, string)

Recovers the address from a signed message using Ethereum's signing method.

public Task<string> RecoverAddressFromEthSign(string message, string signature)

Parameters

message string

The UTF-8 encoded message.

signature string

The signature.

Returns

Task<string>

The recovered address.

RecoverAddressFromPersonalSign(string, string)

Recovers the address from a signed message using personal signing.

public Task<string> RecoverAddressFromPersonalSign(string message, string signature)

Parameters

message string

The UTF-8 encoded and prefixed message.

signature string

The signature.

Returns

Task<string>

The recovered address.

RecoverAddressFromTypedDataV4<T, TDomain>(T, TypedData<TDomain>, string)

Recovers the address from a signed message using typed data (version 4).

public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<TDomain> typedData, string signature) where TDomain : IDomain

Parameters

data T

The data to sign.

typedData TypedData<TDomain>

The typed data.

signature string

The signature.

Returns

Task<string>

The recovered address.

Type Parameters

T
TDomain

RemoveAdmin(string)

Removes an existing admin from the smart account.

public Task<ThirdwebTransactionReceipt> RemoveAdmin(string admin)

Parameters

admin string

The address of the admin to remove.

Returns

Task<ThirdwebTransactionReceipt>

The transaction receipt.

RevokeSessionKey(string)

Revokes a session key from a signer.

public Task<ThirdwebTransactionReceipt> RevokeSessionKey(string signerAddress)

Parameters

signerAddress string

The address of the signer to revoke.

Returns

Task<ThirdwebTransactionReceipt>

The transaction receipt.

SendTransaction(ThirdwebTransactionInput)

Sends a transaction.

public Task<string> SendTransaction(ThirdwebTransactionInput transactionInput)

Parameters

transactionInput ThirdwebTransactionInput

Returns

Task<string>

The transaction hash.

SignTransaction(ThirdwebTransactionInput)

Signs a transaction.

public Task<string> SignTransaction(ThirdwebTransactionInput transaction)

Parameters

transaction ThirdwebTransactionInput

The transaction to sign.

Returns

Task<string>

The signed transaction.

SignTypedDataV4(string)

Signs typed data (version 4).

public Task<string> SignTypedDataV4(string json)

Parameters

json string

The JSON representation of the typed data.

Returns

Task<string>

The signed data.

SignTypedDataV4<T, TDomain>(T, TypedData<TDomain>)

Signs typed data (version 4).

public Task<string> SignTypedDataV4<T, TDomain>(T data, TypedData<TDomain> typedData) where TDomain : IDomain

Parameters

data T

The data to sign.

typedData TypedData<TDomain>

The typed data.

Returns

Task<string>

The signed data.

Type Parameters

T

The type of the data.

TDomain

The type of the domain.

SwitchNetwork(BigInteger)

Attempts to set the active network to the specified chain ID. Requires related contracts to be deterministically deployed on the chain.

public Task SwitchNetwork(BigInteger chainId)

Parameters

chainId BigInteger

The chain ID to switch to.

Returns

Task