For the complete documentation index, see llms.txt. This page is also available as Markdown.

queryLedgerState_utxo - Cardano

Example code for the queryLedgerState_utxo JSON-RPC method. Complete guide on how to use queryLedgerState_utxo JSON-RPC in GetBlock Web3 documentation.

This method returns unspent transaction outputs, filtered by address or by output reference. It is the primary method for finding spendable inputs for a transaction.

Parameters

Parameter
Type
Required
Description

addresses

array

No

Filter outputs to these addresses

outputReferences

array

No

Filter outputs to these transaction id and index pairs

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "queryLedgerState/utxo",
    "params": {
        "addresses": [
            "addr1qxy2lpan99fcnhhyzr8w8qk4dqz4mp7g6b8h3r2v5c9d0e1f2g3h4j5k6l7m8n9p0q"
        ]
    },
    "id": "getblock.io"
}'
example.js
const response = await fetch(
    'https://go.getblock.io/<ACCESS-TOKEN>/',
    {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({"jsonrpc": "2.0", "method": "queryLedgerState/utxo", "params": {"addresses": ["addr1qxy2lpan99fcnhhyzr8w8qk4dqz4mp7g6b8h3r2v5c9d0e1f2g3h4j5k6l7m8n9p0q"]}, "id": "getblock.io"})
    }
);
console.log(await response.json());

Response

Response Parameters

Field
Type
Description

transaction

object

The transaction that created the output

index

integer

Output index within that transaction

address

string

Address that owns the output

value

object

Output value, including ada and any native assets

Use Cases

  • Coin Selection: Read spendable UTXOs when building a transaction

  • Balance Construction: Sum output values to compute an address balance

  • Asset Discovery: Find native assets held at an address

  • Wallet Backends: Source inputs for transaction construction

Error Handling

Error Code
Message
Description

-32602

Invalid params

A required field is missing or has the wrong type

-32000

Query unavailable

The query is not available in the current ledger era

-32603

Internal error

The node failed to answer the query

Was this helpful?