What is the best way to tell if the node I am is using a full archive node?

One way I know if is to call a contract from the context of an old block, but this requires an RPC call and is not explicit (the call may fail for other reasons). Additionally, different clients (geth, party, etc.) return error messages, so this is not reliable. Is there a way to do this explicitly?

  • I believe that you are explaining why you don't want to use contract.methods.func(arg1, arg2).call(null, blockNumber), but I did not quite understand your explanation. – goodvibration Apr 21 '20 at 14:56
  • You can just catch the error, and if (!error.message.startsWith("Invalid JSON RPC response")), then you know that you are not using a full archive node. – goodvibration Apr 21 '20 at 14:57
  • Of course, make sure to call a function which cannot revert (preferably a pure function). – goodvibration Apr 21 '20 at 14:58
  • i.e., a function with no assert, require, revert, array access operations, division, modulo, external calls (to another contract), and probably a few more of those. For example a getter function of any one of your (non-array) public variables. – goodvibration Apr 21 '20 at 15:00
  • Is it possible to do this without using .call()? That error message you mentioned can be different depending on the underlying client (geth, parity, etc.), so that is not reliable. – Shane Fontaine Apr 21 '20 at 15:22

A full archive node has access to the historical state of the blockchain. For example, if the node returns balance of an account (which has some eth) at block 1 then that node will be an archive node.

  1. Case of an archive node:
$ curl --data '{"method":"eth_getBalance","params":["0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3", "0x1"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localh

In the above code snippet, we are querying balance of 0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3 an address which received 1k ETH during the genesis block.

Asserting the result of the above JSON-RPC call to be equal to 1K ETH will explicitly indicate if the node is an archive node.

  1. Case of a non archive node:
$ curl --data '{"method":"eth_getBalance","params":["0xe5Fb31A5CaEE6a96de393bdBF89FBe65fe125Bb3", "0x1"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST https://cloudflare-eth.com/
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"missing trie node d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3 (path )"}}

A non archive node will not be able to return the balance at block 1 for the above address.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.