Marketplace has launched, further enabling blockchain developers! Learn more

Contents

index.getContainerByIndex RPC method

Like all of the Index API methods, the index.getContainerByIndex method is available across the Avalanche C-Chain, X-Chain, and P-Chain. Refer to the following list of endpoints for each chain that this method can be used on.


Endpoints:
  • X-Chain Transactions​: /ext/index/X/tx
  • X-Chain Vertices​: /ext/index/X/vtx
  • P-Chain Blocks​: /ext/index/P/block
  • C-Chain Blocks​: /ext/index/C/block

For more information, see the Index API homepage.

The API credit value for this method is 1 . To learn more about API credits and each method's value, visit the API Credits page.

Parameters:

  1. index - uint64
  2. encoding - String - (optional) Encoding format - "cb58" or "hex". Defaults to "cb58".

Returns:

  1. id - string - The container's ID.
  2. bytes - string - The byte representation of the container.
  3. timestamp - string - The time at which the node accepted the container.
  4. index - string - How many containers were accepted in this index before this one.
  5. encoding - string - "cb58" or "hex".

Code Examples:

The following examples are calling the index.getContainerByIndex method on the X-Chain Transactions endpoint: /ext/index/X/tx. To call this method on Avalanche’s other endpoints, replace the /ext/index/X/tx with any of the above listed endpoints in your code.

const ethers = require("ethers");

(async () => {
  const provider = new ethers.providers.JsonRpcProvider(
    "http://sample-endpoint-name.network.quiknode.pro/token-goes-here/ext/index/X/tx"
  );
  const params = {
    "index": 0,
    "encoding": "hex",
  };
  const result = await provider.send("index.getContainerByIndex", params);
  console.log(result);
})();
Ready to get started? Create a free account