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 }]
  })
});
circle-exclamation

The transaction builder accepts two UTXO-related parameters:

  • utxos — Available UTXOs (hex-CBOR encoded) for the builder to select from

  • requiredInputs — 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:

Scenario
Approach
Why

Browser dApp with connected wallet

UTXOs from user's wallet, seamless signing

Backend service or automation

No browser needed, query any address

Hardware wallet signing

Fetch UTXOs server-side, sign offline

Frontend: Weld

Weldarrow-up-right 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.

circle-info

Other UTXO sources (BlockFrost, Ogmios, Dolos, etc.) work with Anvil's transaction builder as long as UTXOs are hex-CBOR encoded.


Related: Transaction Building · Wallet Endpoints

Last updated

Was this helpful?