How do I get the Cosmos account number and sequence?

Felix
2 min readMar 11, 2023

--

Photo by Towfiqu barbhuiya on Unsplash

If you are developing applications based on Cosmos SDK, you may be wondering where to find the sequence and account number. This article will explain what these two values are and where you can get them?

What is the account number?

The account number is a number that uniquely identifies an account. It’s an incremented value that is assigned to an account the first time it receives funds. Once assigned, the account number doesn’t change.

What is the sequence?

The sequence is a value that represents the number of transactions sent from an account. It is therefore initially set to zero. The sequence must be included in each transaction and incremented accordingly. The first transaction has a sequence of 0, the second 1 and so on. The sequence enforces a defined transaction order and prevents replay attacks.

How can I query them?

You can get both values by querying the Cosmos API account endpoint:
Url: https://api.cosmos.interbloc.org/cosmos/auth/v1beta1/accounts/{address}

Documentation of the Account query

Example url: https://api.cosmos.interbloc.org/cosmos/auth/v1beta1/accounts/cosmos1wyayc6un8xad3k36rw3y0yts3gt77cj72mur3h

Example answer:

{ 
"account": {
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"address": "cosmos1wyayc6un8xad3k36rw3y0yts3gt77cj72mur3h",
"pub_key": null,
"account_number": "1567492",
"sequence": "0"
}
}

Note: For a list of active API nodes, I suggest you go to https://cosmos.directory/cosmoshub/nodes. To use this query, you must use the REST endpoint, not the RPC endpoint.

--

--

Responses (1)