Skip to main content

Fetch block transactions

Intermediate
Tutorial

There exist two different entpoints that allow for querying of transaction. This endpoint allows you to fetch a transaction at a certain block height. It is the implementation of the /block/transaction endpoint of the Rosetta API standard. The search_transactions endpoint allows you to query for transactions given a set of parameters. It is the implementation of the /search/transactions endpoint

Note that in the case of the ICP ledger a block always contains exactly one transaction. The hash of the block as well as the index of the block is guaranteed to be unique while the hash of the transaction is not.

Prerequisites

  • Your Rosetta instance is up and running under the address 0.0.0.0:8081.

Make sure to use the correct NetworkIdentifier as described in this section. For this example the following arbitrary BlockIdentifier and TransactionIdentifier are used:

"block_identifier": {
"index": 9890652,
"hash": "e189f729b207dafc2583305cf313671a84bb1437ee44435e12eaf3dcfbcb8fcf"
}
"transaction_identifier": {
"hash": "93a19bfa37db0200cec77281cd8a0602a4375a7367338e7c6973f93a42e6eb5e"
}

BlockTransaction endpoint

An example request for the block/transaction endpoint would resemble the following:

curl --location '0.0.0.0:8081/block/transaction'  --header 'Content-Type: application/json' --data '{
"network_identifier": {
"blockchain":"Internet Computer",
"network":"00000000000000020101"
},
"block_identifier": {
"index": 9840566,
"hash": "e189f729b207dafc2583305cf313671a84bb1437ee44435e12eaf3dcfbcb8fcf"
},
"transaction_identifier": {
"hash": "93a19bfa37db0200cec77281cd8a0602a4375a7367338e7c6973f93a42e6eb5e"
}
}

The response is similar to that of the block endpoint as there is only one transaction withing a block.

{
"transaction": {
"transaction_identifier": {
"hash": "93a19bfa37db0200cec77281cd8a0602a4375a7367338e7c6973f93a42e6eb5e"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "d360ba83413713928ec6a61438f7c611c6c81a09b36a99462f654473f9a1a671"
},
"amount": {
"value": "-830010000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "42727096b88d2ef0527c77e16c4b11b8685e623bfdd0b035b3680f36078cca06"
},
"amount": {
"value": "830010000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "d360ba83413713928ec6a61438f7c611c6c81a09b36a99462f654473f9a1a671"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 9840566,
"memo": 0,
"timestamp": 1705420805314666462
}
}
}

SearchTransactions endpoint

There are several parameters that can be used to query transactions. See the full specification to see what query parameters can be used. For example, if you want to fetch all transactions in a given block range (of maximum 10000 blocks) where a specific account was involved, you can make a request to the search/transactions endpoint:

curl --location '0.0.0.0:8081/search/transactions'  --header 'Content-Type: application/json' --data '{
"network_identifier": {
"blockchain":"Internet Computer",
"network":"00000000000000020101"
},
"account_identifier": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
}
}'

The response lists all transactions where the given account_identifier was involved in:

{
"transactions": [
{
"block_identifier": {
"index": 340,
"hash": "09840e4e9551d7f53b98aca016b871a739a7e7a8b9decd0d83f219695de69e22"
},
"transaction": {
"transaction_identifier": {
"hash": "bc93fad6948b88dd79fdcd97d5bbb43b7e79b113120dab5f0b320d5b43b2947c"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "56a4e64ffdf42e2e39a457c0d7cb10a29f8e956651a9b52569e1eeb84c5fc0c6"
},
"amount": {
"value": "-10000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "10000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "56a4e64ffdf42e2e39a457c0d7cb10a29f8e956651a9b52569e1eeb84c5fc0c6"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 340,
"memo": 1234,
"timestamp": 1711442448519667770
}
}
},
{
"block_identifier": {
"index": 341,
"hash": "d5a4540506fa33e18bd388c00a94ff8eceb103d31df954269057659a06e5db5a"
},
"transaction": {
"transaction_identifier": {
"hash": "f8b16e6a1cc53fa6409c64c557e1f799303c8cbbe83fe8b6b6f9f669667c84c2"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 341,
"memo": 5735670440150344530,
"timestamp": 1711442623333685262
}
}
},
{
"block_identifier": {
"index": 342,
"hash": "8b53373f910f488584a6876fd57bc9ecf398e67558cefcb187147ef6aad7f4d9"
},
"transaction": {
"transaction_identifier": {
"hash": "93b71e1bdb5016e31f28a7762283c896f1d749cdbd8569c1bf8487f804f7923b"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "7f622708b363917e3ba0ef8ac1cb0dfe241ef5ffca54f32c1480473ee3a12cad"
},
"amount": {
"value": "10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 342,
"memo": 7924617631962561266,
"timestamp": 1711442657669389875
}
}
},
{
"block_identifier": {
"index": 343,
"hash": "fc30f125732c9df66136298956c99f6f44cb9e3d7756e6bbe9aff3fdf8d503a7"
},
"transaction": {
"transaction_identifier": {
"hash": "87e1f7315678fa77f204451cb2aa43c43e972783ff24d58880f77833832c9328"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "7f622708b363917e3ba0ef8ac1cb0dfe241ef5ffca54f32c1480473ee3a12cad"
},
"amount": {
"value": "10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 343,
"memo": 16289954222169307417,
"timestamp": 1711442900201631877
}
}
},
{
"block_identifier": {
"index": 367,
"hash": "6f177560d35196fd43af71c46b074e0fe5b408c3ee42386845bfbcbf2d7b4d4a"
},
"transaction": {
"transaction_identifier": {
"hash": "b5ee49f26b5cc49122b425b626cb04b5cfb378e95cdf1e71ea86057ea136f82c"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "26d877d2a04f0a9ae5e5a481102d5a865115263f2ed93a0804e3ed7b8d824921"
},
"amount": {
"value": "1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 367,
"memo": 18006154073614947169,
"timestamp": 1712142206634710570
}
}
},
{
"block_identifier": {
"index": 378,
"hash": "b2668c738ab5b6ad62536c4969f4051ebfb146054cffe97734b647eaff0d2eb9"
},
"transaction": {
"transaction_identifier": {
"hash": "630c2039c08feee05df8d324855d785f05d182f841a769ac88519b0dc958d1ba"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "c7ab2a6b0f7b80138d02a6415f94ed38d9141a5d2c8fbc024b234b56730764f8"
},
"amount": {
"value": "1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 378,
"memo": 14834524988377055565,
"timestamp": 1712656117723675734
}
}
},
{
"block_identifier": {
"index": 379,
"hash": "c6bdc54caa2c1573126ea7febcc5c19f9609ef6dbcd30f72af8f743e358c0cb0"
},
"transaction": {
"transaction_identifier": {
"hash": "13845e340d54007a463ece9a5474b097184a23960d0b55dd1fffc8b2014e5f2e"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"status": "COMPLETED",
"account": {
"address": "47e0ae0de8af04a961c4b3225cd77b9652777286ce142c2a07fab98da5263100"
},
"amount": {
"value": "1000000000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 2
},
"type": "FEE",
"status": "COMPLETED",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10000",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": {
"block_height": 379,
"memo": 8071647994638581255,
"timestamp": 1712668999597129194
}
}
}
],
"total_count": 7
}