A Wallet manages a single private key which is used to sign transactions, messages and other common payloads.

This class is generally the main entry point for developers that wish to use a private key directly, as it can create instances from a large variety of common sources, including raw private key, BIP-39 mnemonics and encrypted JSON wallets.

Extends

  • BaseWallet

Constructors

new Wallet()

new Wallet(key, provider?): Wallet

Create a new wallet for the private key, optionally connected to provider.

Parameters

ParameterTypeDescription
keystring | SigningKeyThe private key.
provider?null | ProviderThe provider to connect to.

Returns

Wallet

Overrides

BaseWallet.constructor

Source

wallet/wallet.ts:34

Properties

PropertyModifierTypeDescriptionInherited from
#addressprivatestringThe wallet address.BaseWallet.#address
#signingKeyprivateSigningKeyThe signing key used for signing payloads.BaseWallet.#signingKey
providerreadonlynull | ProviderThe provider this signer is connected to.BaseWallet.provider

Accessors

address

get address(): string

The address of this wallet.

Returns

string

Source

wallet/base-wallet.ts:69


privateKey

get privateKey(): string

The private key for this wallet.

Returns

string

Source

wallet/base-wallet.ts:87


signingKey

get signingKey(): SigningKey

The SigningKey used for signing payloads.

Returns

SigningKey

Source

wallet/base-wallet.ts:78

Methods

connect()

connect(provider): Wallet

Connects the wallet to a provider.

Parameters

ParameterTypeDescription
providernull | ProviderThe provider to connect to.

Returns

Wallet

The connected wallet.

Overrides

BaseWallet.connect

Source

wallet/wallet.ts:50


encrypt()

encrypt(password, progressCallback?): Promise<string>

Resolves to a JSON Keystore Wallet encrypted with password.

If progressCallback is specified, it will receive periodic updates as the encryption process progresses.

Parameters

ParameterTypeDescription
passwordstring | Uint8ArrayThe password to encrypt the wallet with.
progressCallback?ProgressCallbackAn optional callback to keep the user informed.

Returns

Promise<string>

The encrypted JSON wallet.

Source

wallet/wallet.ts:64


encryptSync()

encryptSync(password): string

Returns a JSON Keystore Wallet encrypted with password.

It is preferred to use the async version instead, which allows a ProgressCallback to keep the user informed.

This method will block the event loop (freezing all UI) until it is complete, which may be a non-trivial duration.

Parameters

ParameterTypeDescription
passwordstring | Uint8ArrayThe password to encrypt the wallet with.

Returns

string

The encrypted JSON wallet.

Source

wallet/wallet.ts:82


getAddress()

getAddress(_zone?): Promise<string>

Returns the address of this wallet.

Parameters

ParameterTypeDescription
_zone?stringThe zone (optional).

Returns

Promise<string>

The wallet address.

Inherited from

BaseWallet.getAddress

Source

wallet/base-wallet.ts:99


signMessage()

signMessage(message): Promise<string>

Signs a message.

Parameters

ParameterTypeDescription
messagestring | Uint8ArrayThe message to sign.

Returns

Promise<string>

The signed message.

Inherited from

BaseWallet.signMessage

Async

Source

wallet/base-wallet.ts:157


signMessageSync()

signMessageSync(message): string

Returns the signature for message signed with this wallet.

Parameters

ParameterTypeDescription
messagestring | Uint8ArrayThe message to sign.

Returns

string

The serialized signature.

Inherited from

BaseWallet.signMessageSync

Source

wallet/base-wallet.ts:169


signTransaction()

signTransaction(tx): Promise<string>

Signs a transaction.

Parameters

ParameterTypeDescription
txQuaiTransactionRequestThe transaction request.

Returns

Promise<string>

The signed transaction.

Inherited from

BaseWallet.signTransaction

Source

wallet/base-wallet.ts:119


signTypedData()

signTypedData(
   domain, 
   types, 
value): Promise<string>

Signs typed data.

Parameters

ParameterTypeDescription
domainTypedDataDomainThe domain of the typed data.
typesRecord<string, TypedDataField[]>The types of the typed data.
valueRecord<string, any>The value of the typed data.

Returns

Promise<string>

The signed typed data.

Inherited from

BaseWallet.signTypedData

Async

Source

wallet/base-wallet.ts:182


fromEncryptedJson()

static fromEncryptedJson(
   json, 
   password, 
progress?): Promise<Wallet>

Creates (asynchronously) a Wallet by decrypting the json with password.

If progress is provided, it is called periodically during decryption so that any UI can be updated.

Parameters

ParameterTypeDescription
jsonstringThe JSON data to decrypt.
passwordstring | Uint8ArrayThe password to decrypt the JSON data.
progress?ProgressCallbackAn optional callback to keep the user informed.

Returns

Promise<Wallet>

The decrypted wallet.

Source

wallet/wallet.ts:116


fromEncryptedJsonSync()

static fromEncryptedJsonSync(json, password): QuaiHDWallet | Wallet

Creates a Wallet by decrypting the json with password.

The fromEncryptedJson method is preferred, as this method will lock up and freeze the UI during decryption, which may take some time.

Parameters

ParameterTypeDescription
jsonstringThe JSON data to decrypt.
passwordstring | Uint8ArrayThe password to decrypt the JSON data.

Returns

QuaiHDWallet | Wallet

The decrypted wallet.

Source

wallet/wallet.ts:140