The Quai HD wallet is a BIP44-compliant hierarchical deterministic wallet used for managing a set of addresses in the Quai ledger. This is the easiest way to manage the interaction of managing accounts and addresses on the Quai network, however, if your use case requires a single address Quai address, you can use the Wallet class.

The Quai HD wallet supports:

  • Adding accounts to the wallet heierchy
  • Generating addresses for a specific account in any Zone
  • Signing and sending transactions for any address in the wallet
  • Signing and verifying EIP1193 typed data for any address in the wallet.
  • Serializing the wallet to JSON and deserializing it back to a wallet instance.

Example

import { QuaiHDWallet, Zone } from 'quais';

const wallet = new QuaiHDWallet();
const cyrpus1Address = await wallet.getNextAddress(0, Zone.Cyrpus1); // get the first address in the Cyrpus1 zone
await wallet.sendTransaction({ from: address, to: '0x...', value: 100 }); // send a transaction
const serializedWallet = wallet.serialize(); // serialize current (account/address) state of the wallet
.
.
.
const deserializedWallet = QuaiHDWallet.deserialize(serializedWallet); // create a new wallet instance from the serialized data

Extends

  • AbstractHDWallet

Constructors

new QuaiHDWallet()

new QuaiHDWallet(
   guard, 
   root, 
   provider?): QuaiHDWallet

Create a QuaiHDWallet instance.

Parameters

ParameterTypeDescription
guardany-
rootHDNodeWalletThe root HD node wallet.
provider?ProviderThe provider.

Returns

QuaiHDWallet

Overrides

AbstractHDWallet.constructor

Source

wallet/quai-hdwallet.ts:62

Accessors

xPub

get xPub(): string

Returns the extended public key of the root node of the HD wallet.

Returns

string

The extended public key.

Source

wallet/hdwallet.ts:93

Methods

addAddress()

addAddress(
   account, 
   addressIndex, 
   isChange?): NeuteredAddressInfo

Adds an address to the wallet.

Parameters

ParameterTypeDefault valueDescription
accountnumberundefinedThe account number.
addressIndexnumberundefinedThe address index.
isChange?booleanfalseWhether the address is a change address. Default is false

Returns

NeuteredAddressInfo

The added address info.

Inherited from

AbstractHDWallet.addAddress

Source

wallet/hdwallet.ts:150


connect()

connect(provider): void

Connects the wallet to a provider.

Parameters

ParameterTypeDescription
providerProviderThe provider.

Returns

void

Inherited from

AbstractHDWallet.connect

Source

wallet/hdwallet.ts:380


getAddressInfo()

getAddressInfo(address): null | NeuteredAddressInfo

Gets the address info for a given address.

Parameters

ParameterTypeDescription
addressstringThe address.

Returns

null | NeuteredAddressInfo

The address info or null if not found.

Inherited from

AbstractHDWallet.getAddressInfo

Source

wallet/hdwallet.ts:238


getAddressesForAccount()

getAddressesForAccount(account): NeuteredAddressInfo[]

Gets the addresses for a given account.

Parameters

ParameterTypeDescription
accountnumberThe account number.

Returns

NeuteredAddressInfo[]

The addresses for the account.

Inherited from

AbstractHDWallet.getAddressesForAccount

Source

wallet/hdwallet.ts:264


getAddressesForZone()

getAddressesForZone(zone): NeuteredAddressInfo[]

Gets the addresses for a given zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

NeuteredAddressInfo[]

The addresses for the zone.

Inherited from

AbstractHDWallet.getAddressesForZone

Source

wallet/hdwallet.ts:275


getNextAddress()

getNextAddress(account, zone): Promise<NeuteredAddressInfo>

Promise that resolves to the next address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next address.
zoneZoneThe zone in which to retrieve the next address.

Returns

Promise<NeuteredAddressInfo>

The next neutered address information.

Inherited from

AbstractHDWallet.getNextAddress

Source

wallet/hdwallet.ts:195


getNextAddressSync()

getNextAddressSync(account, zone): NeuteredAddressInfo

Synchronously retrieves the next address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next address.
zoneZoneThe zone in which to retrieve the next address.

Returns

NeuteredAddressInfo

The next neutered address information.

Inherited from

AbstractHDWallet.getNextAddressSync

Source

wallet/hdwallet.ts:206


getPrivateKey()

getPrivateKey(address): string

Returns the private key for a given address. This method should be used with caution as it exposes the private key to the user.

Parameters

ParameterTypeDescription
addressstringThe address associated with the desired private key.

Returns

string

The private key.

Inherited from

AbstractHDWallet.getPrivateKey

Source

wallet/hdwallet.ts:253


sendTransaction()

sendTransaction(tx): Promise<TransactionResponse>

Send a transaction.

Parameters

ParameterTypeDescription
txQuaiTransactionRequestThe transaction request.

Returns

Promise<TransactionResponse>

A promise that resolves to the transaction response.

Overrides

AbstractHDWallet.sendTransaction

Throws

If the provider is not set.

Source

wallet/quai-hdwallet.ts:86


serialize()

serialize(): SerializedHDWallet

Serializes the HD wallet state into a format suitable for storage or transmission.

Returns

SerializedHDWallet

An object representing the serialized state of the HD wallet, including version, mnemonic phrase, coin type, and addresses.

Inherited from

AbstractHDWallet.serialize

Source

wallet/hdwallet.ts:434


signMessage()

signMessage(address, message): Promise<string>

Sign a message.

Parameters

ParameterTypeDescription
addressstringThe address.
messagestring | Uint8ArrayThe message to sign.

Returns

Promise<string>

A promise that resolves to the signed message.

Overrides

AbstractHDWallet.signMessage

Source

wallet/quai-hdwallet.ts:103


signTransaction()

signTransaction(tx): Promise<string>

Sign a transaction.

Parameters

ParameterTypeDescription
txQuaiTransactionRequestThe transaction request.

Returns

Promise<string>

A promise that resolves to the signed transaction.

Overrides

AbstractHDWallet.signTransaction

Source

wallet/quai-hdwallet.ts:72


signTypedData()

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

Signs typed data using the private key associated with the given address.

Parameters

ParameterTypeDescription
addressstringThe address for which the typed data is to be signed.
domainTypedDataDomainThe domain information of the typed data, defining the scope of the signature.
typesRecord<string, TypedDataField[]>The types of the data to be signed, mapping each data type name
to its fields.
valueRecord<string, unknown>The actual data to be signed.

Returns

Promise<string>

A promise that resolves to the signed data in string format.

Throws

If the address does not correspond to a valid HD node or if signing fails.

Source

wallet/quai-hdwallet.ts:143


createRandom()

static createRandom<T>(
   this, 
   password?, 
   wordlist?): T

Creates a random HD wallet.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
password?stringThe password.
wordlist?WordlistThe wordlist.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.createRandom

Source

wallet/hdwallet.ts:319


deserialize()

static deserialize(serialized): Promise<QuaiHDWallet>

Deserializes the given serialized HD wallet data into an instance of QuaiHDWallet.

Parameters

ParameterTypeDescription
serializedSerializedHDWalletThe serialized wallet data to be deserialized.

Returns

Promise<QuaiHDWallet>

A promise that resolves to an instance of QuaiHDWallet.

Overrides

AbstractHDWallet.deserialize

Async

Throws

If validation of the serialized wallet data fails or if deserialization fails.

Static

Source

wallet/quai-hdwallet.ts:118


fromMnemonic()

static fromMnemonic<T>(this, mnemonic): T

Creates an HD wallet from a mnemonic.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
mnemonicMnemonicThe mnemonic.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.fromMnemonic

Source

wallet/hdwallet.ts:304


fromPhrase()

static fromPhrase<T>(
   this, 
   phrase, 
   password?, 
   wordlist?): T

Creates an HD wallet from a phrase.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
phrasestringThe phrase.
password?stringThe password.
wordlist?WordlistThe wordlist.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.fromPhrase

Source

wallet/hdwallet.ts:343