- Quai Transactions
- Qi Transactions
1
Configure Wallet
To send a Quai transaction, you’ll first need to connect a Wallet or QuaiHDWallet to a Provider.
Copy
Ask AI
const provider = new quais.JsonRpcProvider('https://rpc.quai.network', undefined, { usePathing: true })
// initialize wallet
const wallet = new quais.Wallet(privateKey, provider)
// initialize HD wallet
const hdWallet = quais.QuaiHDWallet.fromMnemonic(mnemonic)
await hdWallet.connect(provider)
2
Build Transaction
Then, build the transaction you want to send using the QuaiTransactionRequest type.
Copy
Ask AI
// get to address from wallet
const from = wallet.getAddress()
// get to address from HD wallet
const addressInfo = hdWallet.getAddressNextAddress(0, quais.Zone.Cyprus1)
const from = addressInfo.address
// build simple transfer transaction
const 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.
Copy
Ask AI
// send transaction with wallet
const tx = await wallet.sendTransaction(txData)
const txReceipt = await tx.wait()
// send transaction with HD wallet
const 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.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.
Copy
Ask AI
const provider = new quais.JsonRpcProvider('https://rpc.quai.network', undefined, { usePathing: true })
// initialize HD wallet
const hdWallet = quais.QiHDWallet.fromMnemonic(mnemonic)
// connect to provider and sync UTXO set
await hdWallet.connect(provider)
await hdWallet.scan(quais.Zone.Cyprus1)
2
Build Transaction
Using the addresses and outpoints from the UTXO set, build the transaction you want to send using the QiTransactionRequest type.
Copy
Ask AI
// get from address from HD wallet
const addressInfo = hdWallet.getAddressNextAddress(0, quais.Zone.Cyprus1)
const from = addressInfo.address
// get outpoints for a specified zone
const outpoints = hdWallet.getOutpoints(quais.Zone.Cyprus1)
// build transaction
const txData: QiTransactionRequest = {
txInputs: outpoints[0]
txOutputs: { address: "0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329", denomination: 7 },
}
3
Send and Sign Transaction
Finally, sign and broadcast the transaction.
Copy
Ask AI
// send transaction with HD wallet
const tx = await hdWallet.sendTransaction(txData)
const txReceipt = await tx.wait()
