// get to address from walletconst from = wallet.getAddress()// get to address from HD walletconst addressInfo = hdWallet.getAddressNextAddress(0, quais.Zone.Cyprus1)const from = addressInfo.address// build simple transfer transactionconst txData: QuaiTransactionRequest{ from, to: "0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329", value: quais.parseQuai("1.0"),}
The above transaction is a simple value transfer. Additional transaction params for more complex transactions can be found in the QuaiTransaction class.
3
Send and Sign Transaction
Finally, sign and broadcast the transaction using your wallet of choice.
// send transaction with walletconst tx = await wallet.sendTransaction(txData)const txReceipt = await tx.wait()// send transaction with HD walletconst tx = await hdWallet.sendTransaction(txData)const txReceipt = await tx.wait()
1
Configure Wallet
To send a Qi transaction, you’ll first need to connect a QiHDWallet to a Provider and sync the UTXO set.
const provider = new quais.JsonRpcProvider('https://rpc.quai.network', undefined, { usePathing: true })// initialize HD walletconst hdWallet = quais.QiHDWallet.fromMnemonic(mnemonic)// connect to provider and sync UTXO setawait hdWallet.connect(provider)await hdWallet.scan(quais.Zone.Cyprus1)
Syncing the UTXO set will retrieve standard and change addresses, as well as scan the specified account for addresses with unspent outputs. You’ll need the wallet outpoints and addresses to build a transaction.
2
Build Transaction
Using the addresses and outpoints from the UTXO set, build the transaction you want to send using the QiTransactionRequest type.
// get from address from HD walletconst addressInfo = hdWallet.getAddressNextAddress(0, quais.Zone.Cyprus1)const from = addressInfo.address// get outpoints for a specified zoneconst outpoints = hdWallet.getOutpoints(quais.Zone.Cyprus1)// build transactionconst txData: QiTransactionRequest = { txInputs: outpoints[0] txOutputs: { address: "0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329", denomination: 7 },}
3
Send and Sign Transaction
Finally, sign and broadcast the transaction.
// send transaction with HD walletconst tx = await hdWallet.sendTransaction(txData)const txReceipt = await tx.wait()