nearprotocol

Get block height of transaction create account with account id NEAR Protocol


I already deploy a contract in Near protocol for a long time. Now we need to get the block height, when the first time contract deployed.

Is there any api can get that information with the account id?

In Near protocol, api to get the block height of created account by passing in account id


Solution

  • If you know the transaction hash of the transaction which created the account, you can query it and see the block height. Otherwise, there is no blockchain API for that, and you need to index the history of all the receipts executed on the blockchain and save the information per account whenever you observe CREATE_ACCOUNT action (or TRANSFER action when the receiver is an implicit account [64 hex characters]).

    NEAR Explorer has a dedicated indexing service that listened to the network events since day 0, so Explorer UI then can display that information (see the "Created by transaction" field: https://explorer.near.org/accounts/frol.near). The same approach is used to display when the contract code was updated.

    Learn more about indexing solutions in the docs. I have experience with NEAR Lake Framework, which I totally recommend for production use, but it might be overkill for one-off tasks.