Skip to main content

🧰 SDKs & Libraries

XDC Gateway speaks standard Ethereum JSON-RPC, so any EVM-compatible library works out of the box — just point it at your endpoint.

ethers.js

npm install ethers

import { FetchRequest, JsonRpcProvider } from "ethers";

const request = new FetchRequest("https://rpc.xdcrpc.com/main/evm/50");
request.setHeader("X-API-Key", "YOUR_API_KEY");
const provider = new JsonRpcProvider(request);
const block = await provider.getBlockNumber();

viem

npm install viem

import { createPublicClient, http } from "viem";
import { xdc } from "viem/chains";

const client = createPublicClient({
  chain: xdc,
  transport: http("https://rpc.xdcrpc.com/main/evm/50", {
    fetchOptions: {
      headers: { "X-API-Key": "YOUR_API_KEY" },
    },
  }),
});
const block = await client.getBlockNumber();

web3.js

npm install web3

import { Web3 } from "web3";

const web3 = new Web3(
  new Web3.providers.HttpProvider("https://rpc.xdcrpc.com/main/evm/50", {
    headers: [{ name: "X-API-Key", value: "YOUR_API_KEY" }],
  })
);
const block = await web3.eth.getBlockNumber();