When interacting with either Qi or Quai, it is necessary to use a private key authenticate actions by signing a payload.Wallets are the simplest way to expose the concept of an Externally Owner Account (EOA) or UTXO account as it wraps a private key and supports high-level methods to sign common types of interaction and send transactions.The class most developers will want to use is Wallet, which can load a private key directly or from any common wallet format.The SDK also supports Hierarchical Deterministic (HD) wallets for both Quai and Qi ledgers. Developers who need access to low-level wallet details can opt to use the QuaiHDWallet and QiHDWallet classes.
Quai wallets can be initialized using either the Wallet class or the QuaiHDWallet class.The simplest wallet configuration is using the Wallet class. All that is needed to initiate a wallet is a private key and a provider. Once configured, the wallet acts similar to a Signer.
Copy
Ask AI
import { Wallet } from 'quais'// initialize wallet from private keyconst wallet = new Wallet(privateKey, provider)
The QuaiHDWallet class provides additional low-level functionality on top of the base Wallet class, allowing for more granular control.
Copy
Ask AI
import { QuaiHDWallet, Zone } from 'quais'// initialize HD walletconst QuaiWallet = new QuaiHDWallet()// get the first address in Paxos2 zoneconst paxos2Address = QuaiWallet.getNextAddress(0, Zone.Paxos2)// serialize current (account/address) state of the walletconst serializedWallet = QuaiWallet.serialize()
Qi wallets can only be initialized using the QiHDWallet class.
Copy
Ask AI
import { QiHDWallet, Zone } from 'quais'// initialize HD walletconst QiWallet = new QiHDWallet()// get the first address in Cyrpus1 zoneconst cyrpus1Address = QiWallet.getNextAddress(0, Zone.Cyrpus1)// serialize current (account/address) state of the walletconst serializedWallet = QiWallet.serialize()