Index API
AvalancheGo can be configured to run with an indexer. That is, it saves (indexes) every container (a block, vertex or transaction) it accepts on the X-Chain, P-Chain and C-Chain. To run AvalancheGo with indexing enabled, use command line flag --index-enabled. AvalancheGo will only index containers that are accepted when running with --index-enabled. To ensure your node has a complete index, run a node with a fresh database and --index-enabled. The node will accept every block, vertex and transaction in the network history during bootstrapping, ensuring your index is complete. It is OK to turn off your node if it is running with indexing enabled. If it restarts with indexing still enabled, it will accept all containers that were accepted while it was offline. The indexer should never fail to index an accepted block, vertex or transaction.
Indexed containers (that is, accepted blocks, vertices and transactions) are timestamped with the time at which the node accepted that container. Note that if the container was indexed during bootstrapping, other nodes may have accepted the container much earlier. Every container indexed during bootstrapping will be timestamped with the time at which the node bootstrapped, not when it was first accepted by the network.
Note that for DAGs (including the X-Chain), nodes may accept vertices and transactions in a different order from one another.
This document shows how to query data from AvalancheGo's Index API. The Index API is only available when running with --index-enabled.

Format

This API uses the json 2.0 RPC format. For more information on making JSON RPC calls, see here.

Endpoints

Each chain has one or more index. To see if a C-Chain block is accepted, for example, send an API call to the C-Chain block index. To see if an X-Chain vertex is accepted, for example, send an API call to the X-Chain vertex index.

X-Chain Transactions

1
/ext/index/X/tx
Copied!

X-Chain Vertices

1
/ext/index/X/vtx
Copied!

P-Chain Blocks

1
/ext/index/P/block
Copied!

C-Chain Blocks

1
/ext/index/C/block
Copied!

API Methods

index.getLastAccepted

Get the most recently accepted container.

Signature

1
index.getLastAccepted({
2
encoding:string
3
}) -> {
4
id: string,
5
bytes: string,
6
timestamp: string,
7
encoding: string,
8
index: string
9
}
Copied!
where:
    id is the container's ID
    bytes is the byte representation of the container
    timestamp is the time at which this node accepted the container
    index is how many containers were accepted in this index before this one
    encoding is "cb58" or "hex"

Example Call

1
curl --location --request POST 'localhost:9650/ext/index/X/tx' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "index.getLastAccepted",
6
"params": {
7
"encoding":"cb58"
8
},
9
"id": 1
10
}'
Copied!

Example Response

1
{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"result" :{
5
"id":"6fXf5hncR8LXvwtM8iezFQBpK5cubV6y1dWgpJCcNyzGB1EzY",
6
"bytes":"111115HRzXVDSeonLBcv6QdJkQFjPzPEobMWy7PyGuoheggsMCx73MVXZo2hJMEXXvR5gFFasTRJH36aVkLiWHtTTFcghyFTqjaHnBhdXTRiLaYcro3jpseqLAFVn3ngnAB47nebQiBBKmg3nFWKzQUDxMuE6uDGXgnGouDSaEKZxfKreoLHYNUxH56rgi5c8gKFYSDi8AWBgy26siwAWj6V8EgFnPVgm9pmKCfXio6BP7Bua4vrupoX8jRGqdrdkN12dqGAibJ78Rf44SSUXhEvJtPxAzjEGfiTyAm5BWFqPdheKN72HyrBBtwC6y7wG6suHngZ1PMBh93Ubkbt8jjjGoEgs5NjpasJpE8YA9ZMLTPeNZ6ELFxV99zA46wvkjAwYHGzegBXvzGU5pGPbg28iW3iKhLoYAnReysY4x3fBhjPBsags37Z9P3SqioVifVX4wwzxYqbV72u1AWZ4JNmsnhVDP196Gu99QTzmySGTVGP5ABNdZrngTRfmGTFCRbt9CHsgNbhgetkxbsEG7tySi3gFxMzGuJ2Npk2gnSr68LgtYdSHf48Ns",
7
"timestamp":"2021-04-02T15:34:00.262979-07:00",
8
"encoding":"cb58",
9
"index":"0"
10
}
11
}
Copied!

index.getContainerByIndex

Get container by index. The first container accepted is at index 0, the second is at index 1, etc.

Signature

1
index.getContainerByIndex({
2
index: uint64,
3
encoding: string
4
}) -> {
5
id: string,
6
bytes: string,
7
timestamp: string,
8
encoding: string,
9
index: string
10
}
Copied!
    id is the container's ID
    bytes is the byte representation of the container
    timestamp is the time at which this node accepted the container
    index is how many containers were accepted in this index before this one
    encoding is "cb58" or "hex"

Example Call

1
curl --location --request POST 'localhost:9650/ext/index/X/tx' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "index.getContainerByIndex",
6
"params": {
7
"index":0,
8
"encoding":"cb58"
9
},
10
"id": 1
11
}'
Copied!

Example Response

1
{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"result" :{
5
"id":"6fXf5hncR8LXvwtM8iezFQBpK5cubV6y1dWgpJCcNyzGB1EzY",
6
"bytes":"111115HRzXVDSeonLBcv6QdJkQFjPzPEobMWy7PyGuoheggsMCx73MVXZo2hJMEXXvR5gFFasTRJH36aVkLiWHtTTFcghyFTqjaHnBhdXTRiLaYcro3jpseqLAFVn3ngnAB47nebQiBBKmg3nFWKzQUDxMuE6uDGXgnGouDSaEKZxfKreoLHYNUxH56rgi5c8gKFYSDi8AWBgy26siwAWj6V8EgFnPVgm9pmKCfXio6BP7Bua4vrupoX8jRGqdrdkN12dqGAibJ78Rf44SSUXhEvJtPxAzjEGfiTyAm5BWFqPdheKN72HyrBBtwC6y7wG6suHngZ1PMBh93Ubkbt8jjjGoEgs5NjpasJpE8YA9ZMLTPeNZ6ELFxV99zA46wvkjAwYHGzegBXvzGU5pGPbg28iW3iKhLoYAnReysY4x3fBhjPBsags37Z9P3SqioVifVX4wwzxYqbV72u1AWZ4JNmsnhVDP196Gu99QTzmySGTVGP5ABNdZrngTRfmGTFCRbt9CHsgNbhgetkxbsEG7tySi3gFxMzGuJ2Npk2gnSr68LgtYdSHf48Ns",
7
"timestamp":"2021-04-02T15:34:00.262979-07:00",
8
"encoding":"cb58",
9
"index":"0"
10
}
11
}
Copied!

index.getContainerRange

Returns containers with indices in [startIndex, startIndex+1, ... , startIndex + numToFetch - 1]. numToFetch must be in [0,1024].

Signature

1
index.getContainerRange({
2
startIndex: uint64,
3
numToFetch: uint64,
4
encoding: string
5
}) -> []{
6
id: string,
7
bytes: string,
8
timestamp: string,
9
encoding: string,
10
index: string
11
}
Copied!
    id is the container's ID
    bytes is the byte representation of the container
    timestamp is the time at which this node accepted the container
    index is how many containers were accepted in this index before this one
    encoding is "cb58" or "hex"

Example Call

1
curl --location --request POST 'localhost:9650/ext/index/X/tx' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "index.getContainerRange",
6
"params": {
7
"startIndex":0,
8
"numToFetch":100,
9
"encoding":"cb58"
10
},
11
"id": 1
12
}'
Copied!

Example Response

1
{
2
"jsonrpc":"2.0",
3
"id" :1,
4
"result" :[{
5
"id":"6fXf5hncR8LXvwtM8iezFQBpK5cubV6y1dWgpJCcNyzGB1EzY",
6
"bytes":"111115HRzXVDSeonLBcv6QdJkQFjPzPEobMWy7PyGuoheggsMCx73MVXZo2hJMEXXvR5gFFasTRJH36aVkLiWHtTTFcghyFTqjaHnBhdXTRiLaYcro3jpseqLAFVn3ngnAB47nebQiBBKmg3nFWKzQUDxMuE6uDGXgnGouDSaEKZxfKreoLHYNUxH56rgi5c8gKFYSDi8AWBgy26siwAWj6V8EgFnPVgm9pmKCfXio6BP7Bua4vrupoX8jRGqdrdkN12dqGAibJ78Rf44SSUXhEvJtPxAzjEGfiTyAm5BWFqPdheKN72HyrBBtwC6y7wG6suHngZ1PMBh93Ubkbt8jjjGoEgs5NjpasJpE8YA9ZMLTPeNZ6ELFxV99zA46wvkjAwYHGzegBXvzGU5pGPbg28iW3iKhLoYAnReysY4x3fBhjPBsags37Z9P3SqioVifVX4wwzxYqbV72u1AWZ4JNmsnhVDP196Gu99QTzmySGTVGP5ABNdZrngTRfmGTFCRbt9CHsgNbhgetkxbsEG7tySi3gFxMzGuJ2Npk2gnSr68LgtYdSHf48Ns",
7
"timestamp":"2021-04-02T15:34:00.262979-07:00",
8
"encoding":"cb58",
9
"index":"0"
10
}]
11
}
Copied!

index.getIndex

Get a container's index.

Signature

1
index.getIndex({
2
containerID: string,
3
encoding: string
4
}) -> {
5
index: string
6
}
Copied!
where encoding is "cb58" or "hex".

Example Call

1
curl --location --request POST 'localhost:9650/ext/index/X/tx' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "index.getIndex",
6
"params": {
7
"containerID":"6fXf5hncR8LXvwtM8iezFQBpK5cubV6y1dWgpJCcNyzGB1EzY",
8
"encoding":"cb58"
9
},
10
"id": 1
11
}'
Copied!

Example Response

1
{
2
"jsonrpc":"2.0",
3
"result":
4
{
5
"index":"0"
6
},
7
"id":1
8
}
Copied!

index.isAccepted

Returns true if the container is in this index.

Signature

1
index.isAccepted({
2
containerID: string,
3
encoding: string
4
}) -> {
5
isAccepted: bool
6
}
Copied!

Example Call

1
curl --location --request POST 'localhost:9650/ext/index/X/tx' \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"jsonrpc": "2.0",
5
"method": "index.isAccepted",
6
"params": {
7
"containerID":"6fXf5hncR8LXvwtM8iezFQBpK5cubV6y1dWgpJCcNyzGB1EzY",
8
"encoding":"cb58"
9
},
10
"id": 1
11
}'
Copied!

Example Response

1
{
2
"jsonrpc":"2.0",
3
"result":
4
{
5
"isAccepted": true
6
},
7
"id":1
8
}
Copied!
Last modified 21d ago