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>"
}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>"
}data — the 20-byte address.quantity or tag — integer block number, or the string latest, earliest, or pending.result — the code from the given address. Returns 0x for externally owned accounts (EOAs).eth_getCode code examplesconst { 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();
eth_getCode is verifying whether an address is a smart contract before interacting with it, which helps prevent errors and potential security issues.Was this page helpful?