Table of Contents

Class PrivateKeyWallet

Namespace
Thirdweb
Assembly
Thirdweb.dll

Represents a wallet that uses a private key for signing transactions and messages.

public class PrivateKeyWallet : IThirdwebWallet
Inheritance
PrivateKeyWallet
Implements
Inherited Members
Extension Methods

Constructors

PrivateKeyWallet(ThirdwebClient, EthECKey)

protected PrivateKeyWallet(ThirdwebClient client, EthECKey key)

Parameters

client ThirdwebClient
key EthECKey

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

EcKey

protected EthECKey EcKey { get; set; }

Property Value

EthECKey

Methods

Create(ThirdwebClient, string)

Creates a new instance of PrivateKeyWallet using the provided private key.

public static Task<PrivateKeyWallet> Create(ThirdwebClient client, string privateKeyHex)

Parameters

client ThirdwebClient

The Thirdweb client instance.

privateKeyHex string

The private key in hexadecimal format.

Returns

Task<PrivateKeyWallet>

A new instance of PrivateKeyWallet.

Exceptions

ArgumentNullException

Thrown when the private key is null or empty.

Delete()

Deletes the saved private key from the local storage if it exists.

public static void Delete()

Disconnect()

Disconnects the wallet (if using InAppWallet, clears session)

public virtual Task Disconnect()

Returns

Task

EthSign(byte[])

Signs a raw message using Ethereum's signing method.

public virtual 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 virtual 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 virtual Task<ThirdwebTransactionReceipt> ExecuteTransaction(ThirdwebTransactionInput transactionInput)

Parameters

transactionInput ThirdwebTransactionInput

Returns

Task<ThirdwebTransactionReceipt>

The transaction receipt.

Export()

Exports the private key as a hexadecimal string.

public Task<string> Export()

Returns

Task<string>

The private key as a hexadecimal string.

Exceptions

InvalidOperationException

Thrown when the wallet does not have a private key.

Generate(ThirdwebClient)

Generates a new instance of PrivateKeyWallet with a new private key.

public static Task<PrivateKeyWallet> Generate(ThirdwebClient client)

Parameters

client ThirdwebClient

The Thirdweb client instance.

Returns

Task<PrivateKeyWallet>

A new instance of PrivateKeyWallet.

Exceptions

ArgumentNullException

Thrown when the client is null.

GetAddress()

Gets the address of the wallet.

public virtual Task<string> GetAddress()

Returns

Task<string>

The wallet address.

GetLinkedAccounts()

Returns a list of linked accounts to the current wallet.

public virtual Task<List<LinkedAccount>> GetLinkedAccounts()

Returns

Task<List<LinkedAccount>>

A list of LinkedAccount objects.

GetSavePath()

Gets the path to the file where a PrivateKeyWallet would be saved if PrivateKeyWallet.Save() is called.

public static string GetSavePath()

Returns

string

The path to the file.

IsConnected()

Checks if the wallet is connected.

public virtual Task<bool> IsConnected()

Returns

Task<bool>

True if connected, 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 virtual 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.

LoadOrGenerate(ThirdwebClient)

Loads a saved instance of PrivateKeyWallet from the local storage or generates an ephemeral one if not found.

public static Task<PrivateKeyWallet> LoadOrGenerate(ThirdwebClient client)

Parameters

client ThirdwebClient

The Thirdweb client instance.

Returns

Task<PrivateKeyWallet>

A new instance of PrivateKeyWallet.

Exceptions

ArgumentNullException

Thrown when the client is null.

PersonalSign(byte[])

Signs a raw message using personal signing.

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

Parameters

rawMessage byte[]

The raw message to sign.

Returns

Task<string>

The signed message.

PersonalSign(string)

Signs a message using personal signing.

public virtual Task<string> PersonalSign(string message)

Parameters

message string

The message to sign.

Returns

Task<string>

The signed message.

RecoverAddressFromEthSign(string, string)

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

public virtual 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 virtual 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 virtual 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

Save()

Saves the private key to the local storage.

public Task Save()

Returns

Task

A task that represents the asynchronous save operation.

Exceptions

InvalidOperationException

Thrown when the wallet does not have a private key.

SendTransaction(ThirdwebTransactionInput)

Sends a transaction.

public virtual Task<string> SendTransaction(ThirdwebTransactionInput transaction)

Parameters

transaction ThirdwebTransactionInput

The transaction to send.

Returns

Task<string>

The transaction hash.

SignTransaction(ThirdwebTransactionInput)

Signs a transaction.

public virtual 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 virtual 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 virtual 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.