Skip to main content
POST
/
eth_getCode
curl --request POST \
  --url https://monad-testnet.core.chainstack.com/9c5b265f20b3ea5df4f54f70eb74b800/ \
  --header 'Content-Type: application/json' \
  --data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xAc586b65F3cd0627D2D05AdB8EF551C9d2D76E12",
    "latest"
  ]
}'
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": "<string>"
}
Monad API method that returns the code at a given address. This is used to check if an address is a smart contract and retrieve its bytecode.
Get you own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • data — the 20-byte address.
  • quantity or tag — integer block number, or the string latest, earliest, or pending.

Response

  • result — the code from the given address. Returns 0x for externally owned accounts (EOAs).

eth_getCode code examples

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

const provider = new ethers.JsonRpcProvider("CHAINSTACK_NODE_URL");

async function getCode() {
  const address = "0xAc586b65F3cd0627D2D05AdB8EF551C9d2D76E12";
  const code = await provider.getCode(address);

  if (code === "0x") {
    console.log("Address is an EOA (not a contract)");
  } else {
    console.log(`Contract bytecode: ${code}`);
  }
}

getCode();

Use case

A practical use case for eth_getCode is verifying whether an address is a smart contract before interacting with it, which helps prevent errors and potential security issues.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_getCode
params
string[]

Response

200 - application/json

The bytecode at the given address.

jsonrpc
string
id
integer
result
string