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
personalAccountIThirdwebWalletgaslessboolchainIdBigIntegerbundlerUrlstringpaymasterUrlstringentryPointContractThirdwebContractfactoryContractThirdwebContractaccountContractThirdwebContracterc20PaymasterAddressstringerc20PaymasterTokenstringerc20PaymasterStorageSlotBigInteger
Properties
AccountType
Gets the account type of the wallet.
public ThirdwebAccountType AccountType { get; }
Property Value
ActiveChainId
public BigInteger ActiveChainId { get; }
Property Value
Client
Gets the Thirdweb client associated with the wallet.
public ThirdwebClient Client { get; }
Property Value
IsDeploying
public bool IsDeploying { get; }
Property Value
WalletId
String identifier for the wallet to be used in analytics.
public string WalletId { get; }
Property Value
Methods
AddAdmin(string)
Adds a new admin to the smart account.
public Task<ThirdwebTransactionReceipt> AddAdmin(string admin)
Parameters
adminstringThe 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 = null, string factoryAddress = null, string accountAddressOverride = null, string entryPoint = null, string bundlerUrl = null, string paymasterUrl = null, TokenPaymaster tokenPaymaster = TokenPaymaster.NONE)
Parameters
personalWalletIThirdwebWalletThe smart wallet's signer to use.
chainIdBigIntegerThe chain ID.
gaslessbool?Whether to sponsor gas for transactions.
factoryAddressstringOverride the default factory address.
accountAddressOverridestringOverride the canonical account address that would be found deterministically based on the signer.
entryPointstringOverride the default entry point address. We provide Constants for different versions.
bundlerUrlstringOverride the default thirdweb bundler URL.
paymasterUrlstringOverride the default thirdweb paymaster URL.
tokenPaymasterTokenPaymasterUse 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 = null, string nativeTokenLimitPerTransactionInWei = null, string permissionStartTimestamp = null, string permissionEndTimestamp = null, string reqValidityStartTimestamp = null, string reqValidityEndTimestamp = null)
Parameters
signerAddressstringThe address of the signer to create a session key for.
approvedTargetsList<string>The list of approved targets for the signer. Use a list of a single Constants.ADDRESS_ZERO to enable all contracts.
nativeTokenLimitPerTransactionInWeistringThe maximum amount of native tokens the signer can send in a single transaction.
permissionStartTimestampstringThe timestamp when the permission starts. Can be set to zero.
permissionEndTimestampstringThe timestamp when the permission ends. Make use of our Utils to get UNIX timestamps.
reqValidityStartTimestampstringThe timestamp when the request validity starts. Can be set to zero.
reqValidityEndTimestampstringThe timestamp when the request validity ends. Make use of our Utils to get UNIX timestamps.
Returns
Disconnect()
Disconnects the wallet (if using InAppWallet, clears session)
public Task Disconnect()
Returns
EstimateUserOperationGas(ThirdwebTransactionInput)
Estimates the gas cost for a user operation. More accurate than ThirdwebTransaction estimation, but slower.
public Task<BigInteger> EstimateUserOperationGas(ThirdwebTransactionInput transaction)
Parameters
transactionThirdwebTransactionInputThe transaction to estimate.
Returns
- Task<BigInteger>
The estimated gas cost.
ExecuteTransaction(ThirdwebTransactionInput)
Sends a transaction and waits for its receipt.
public Task<ThirdwebTransactionReceipt> ExecuteTransaction(ThirdwebTransactionInput transactionInput)
Parameters
transactionInputThirdwebTransactionInput
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
GetAddress()
Gets the address of the wallet.
public Task<string> GetAddress()
Returns
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
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
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
IsValidSignature(string, string)
Verifies if a signature is valid for a message using EIP-1271 or ERC-6492.
public Task<bool> IsValidSignature(string message, string signature)
Parameters
Returns
LinkAccount(IThirdwebWallet, string, bool?, Action<string>, string, IThirdwebBrowser, BigInteger?, string, 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, string defaultSessionIdOverride = null)
Parameters
walletToLinkIThirdwebWalletThe wallet to link.
otpstringThe OTP code if the wallet to link is an email or phone wallet.
isMobilebool?Set to true if linking OAuth on mobile.
browserOpenActionAction<string>The action to open the browser if linking OAuth.
mobileRedirectSchemestringThe redirect scheme if linking OAuth on mobile.
browserIThirdwebBrowserThe browser to use if linking OAuth.
chainIdBigInteger?The chain ID if linking an external wallet (SIWE).
jwtstringThe JWT token if linking custom JWT auth.
payloadstringThe login payload if linking custom AuthEndpoint auth.
defaultSessionIdOverridestringThe default session ID override if linking Guest 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
rawMessagebyte[]The raw message to sign.
Returns
PersonalSign(string)
Signs a message with the personal account. The message will be verified using EIPs 1271 and 6492 if applicable.
public Task<string> PersonalSign(string message)
Parameters
messagestringThe message to sign.
Returns
RemoveAdmin(string)
Removes an existing admin from the smart account.
public Task<ThirdwebTransactionReceipt> RemoveAdmin(string admin)
Parameters
adminstringThe 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
signerAddressstringThe address of the signer to revoke.
Returns
- Task<ThirdwebTransactionReceipt>
The transaction receipt.
SendTransaction(ThirdwebTransactionInput)
Sends a transaction.
public Task<string> SendTransaction(ThirdwebTransactionInput transactionInput)
Parameters
transactionInputThirdwebTransactionInput
Returns
SignAuthorization(BigInteger, string, bool)
Signs an EIP-7702 authorization to invoke contract functions to an externally owned account.
public Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string contractAddress, bool willSelfExecute)
Parameters
chainIdBigIntegerThe chain ID of the contract.
contractAddressstringThe address of the contract.
willSelfExecuteboolSet to true if the wallet will also be the executor of the transaction, otherwise false.
Returns
- Task<EIP7702Authorization>
The signed authorization as an EIP7702Authorization that can be used with AuthorizationList.
SignTransaction(ThirdwebTransactionInput)
Signs a transaction.
public Task<string> SignTransaction(ThirdwebTransactionInput transaction)
Parameters
transactionThirdwebTransactionInputThe transaction to sign.
Returns
SignTypedDataV4(string)
Signs typed data (version 4).
public Task<string> SignTypedDataV4(string json)
Parameters
jsonstringThe JSON representation of the typed data.
Returns
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
dataTThe data to sign.
typedDataTypedData<TDomain>The typed data.
Returns
Type Parameters
TThe type of the data.
TDomainThe type of the domain.
SwitchNetwork(BigInteger)
Attempts to set the active network to the specified chain ID.
public Task SwitchNetwork(BigInteger chainId)
Parameters
chainIdBigIntegerThe chain ID to switch to.
Returns
UnlinkAccount(LinkedAccount)
Unlinks an account (auth method) from the current wallet.
public Task<List<LinkedAccount>> UnlinkAccount(LinkedAccount accountToUnlink)
Parameters
accountToUnlinkLinkedAccountThe linked account to unlink. Same type returned by GetLinkedAccounts().