Select UTXOs
How to provide UTXOs when building transactions with the Anvil API.
Unspent Transaction Outputs (UTXOs) are Cardano's way of tracking value. Unlike account-based blockchains, Cardano tracks individual outputs from previous transactions that haven't been spent yet. When building a transaction, you need to specify which UTXOs to use as inputs.
Test vs Production
In test environments (preprod, preview), the utxos parameter is optional—Anvil will automatically fetch and select UTXOs from the changeAddress:
// Test environment: No UTXOs needed
const response = await fetch('https://preprod.api.ada-anvil.app/v2/services/transactions/build', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({
changeAddress: 'addr_test...',
outputs: [{ address: 'addr_test...', lovelace: 5_000_000 }]
})
});Production requires explicit UTXOs. You must provide the utxos parameter when building transactions on mainnet. Multi-account wallets (e.g., Eternl) also require explicit UTXOs in all environments.
The transaction builder accepts two UTXO-related parameters:
utxos— Available UTXOs (hex-CBOR encoded) for the builder to select fromrequiredInputs— Specific UTXOs that must be consumed (useful for smart contracts where a particular UTXO unlocks state or rewards)
Fetching UTXOs
Choose your approach based on where your code runs:
Frontend: Weld
Weld provides a unified interface for CIP-30 browser wallets (Eternl, Lace, Nami, etc.). UTXOs come directly from the user's connected wallet and are always current.
Backend: Anvil API
For server-side applications, use Anvil's /wallets/utxos endpoint. UTXOs are returned in the exact hex-CBOR format needed for transaction building.
Additional options: query by stakeAddress to get UTXOs across all derived addresses, or enable includeMempool for chained transactions. See Wallet Endpoints for full parameter documentation.
Related: Transaction Building · Wallet Endpoints
Last updated
Was this helpful?

