0

I was wondering if there are ways to distinguish Ethereum full vs archive nodes without using RPC calls to ask for old state information.

This is helpful because lots of nodes have RPC disabled so you cannot simply send a RPC request and get a response.

Thank you

1
  • What do you mean by 'lots of nodes have RPC disabled'? I added an answer that I hope will help you, but might have misunderstood your question too Commented Nov 23, 2023 at 15:22

1 Answer 1

0

dev advocate at Chainstack here.

Doing it without RPC calls is difficult, can't talk for other providers, but on Chainstack, you'll have the node mode in the console, which will display if it's full or archive.

You can also test an endpoint trying to get the state of a block older than the past 128, using eth_getBalance, for example.

Here is an example using ethers.

const { ethers } = require("ethers");

async function checkNodeType(rpcEndpoint) {
  const provider = new ethers.JsonRpcProvider(rpcEndpoint);

  try {
    // Get the current block number
    const currentBlockNumber = await provider.getBlockNumber();
    // Define an old block number (e.g., 100,000 blocks ago)
    const oldBlockNumber = currentBlockNumber - 100000;

    // Define a known address to check the balance of
    const knownAddress = "0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13";

    // Attempt to get the balance at the historical block
    await provider.getBalance(knownAddress, oldBlockNumber);
    console.log("Connected to an Archive Node.");
  } catch (error) {
    console.log("Connected to a Full Node.");
  }
}

// Replace with your RPC endpoint
const rpcEndpoint =
  "NODE_URL";
checkNodeType(rpcEndpoint);

In this case, we try to get the balance from 100000 blocks before the latest one. A full node only stores the states of the past 128 blocks.

Usually, you'll get a missing trie node error if querying an old state on a full node.

This is the logic of the code, if you get an error, it's most likely because you are querying a full node; you can add better error handling to make it more reliable.

Running the code will give you these results:

Connected to a Full Node.


or 


Connected to an Archive Node.

Feel free to reach out if you have any question!

1
  • 1
    thanks Dave for your answer. Yeah I perfectly get the RPC path in order to trying to guess if a node is full or archive. I was wondering if there are other ways to get that information without RPC calls and I was struggling ahah. I also think it's almost impossible...
    – alemaz98
    Commented Nov 23, 2023 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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