Sending Transactions
This guide shows you how to send transactions to smart contracts on Aztec.
Overview
Transactions on Aztec execute contract functions that modify state. Unlike simple reads, transactions go through private execution on your device, proving, and then submission to the network for inclusion in a block. You can send single transactions, batch multiple calls atomically, and query transaction status after submission.
Prerequisites
- Connected to a network with a
TestWalletinstance and funded accounts - Deployed contract with its address and ABI (see How to Deploy)
- Understanding of contract interactions
Send a transaction
After connecting to a contract:
import { Contract } from "@aztec/aztec.js";
// wallet is from the connection guide; contractAddress and artifact are from your deployed contract
const contract = await Contract.at(contractAddress, artifact, wallet);
Call a function and wait for it to be mined:
// contract is from the step above; alice is from the connection guide
const receipt = await contract.methods
.transfer(bobAddress, amount)
.send({ from: aliceAddress });
console.log(`Transaction mined in block ${receipt.blockNumber}`);
console.log(`Transaction fee: ${receipt.transactionFee}`);
The from field specifies which account sends the transaction. If that account has Fee Juice, it pays for the transaction automatically. For other fee payment options, see paying fees.
Send without waiting
Use the NO_WAIT option to get the transaction hash immediately without waiting for inclusion:
// Use NO_WAIT for regular transactions too
const transferTxHash = await token.methods
.transfer(bobAddress, 100n)
.send({ from: aliceAddress, wait: NO_WAIT });
console.log(`Transaction sent: ${transferTxHash.toString()}`);
// Wait for inclusion later using the node
const transferReceipt = await waitForTx(node, transferTxHash);
console.log(`Transaction mined in block ${transferReceipt.blockNumber}`);
Source code: docs/examples/ts/aztecjs_advanced/index.ts#L146-L157
Send batch transactions
Execute multiple calls atomically using BatchCall:
// Execute multiple calls atomically using BatchCall
const batch = new BatchCall(wallet, [
token.methods.mint_to_public(aliceAddress, 500n),
token.methods.transfer(bobAddress, 200n),
]);
const batchReceipt = await batch.send({ from: aliceAddress });
console.log(`Batch executed in block ${batchReceipt.blockNumber}`);
Source code: docs/examples/ts/aztecjs_advanced/index.ts#L159-L168
All calls in a batch must succeed or the entire batch reverts. Use batch transactions when you need atomic execution of multiple operations.