eth_getCode - Arbitrum
Example code for the eth_getCode json-rpc method. Сomplete guide on how to use eth_getCode json-rpc in GetBlock.io Web3 documentation.
This method returns the bytecode stored at a specific address. If the address has no smart contract deployed, the result will be 0x.
Parameters
address
string
yes
The target address to inspect. Must be a valid 20 byte Ethereum-style address.
block_number
string
yes
The block number or state override reference such as latest, earliest, or pending.
Request
curl --location 'https://go.getblock.us/<ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x9b956e3d318625be2686ae7268d81777c462d41f",
"latest"
],
"id": "getblock.io"
}'import axios from 'axios'
let data = JSON.stringify({
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x9b956e3d318625be2686ae7268d81777c462d41f",
"latest"
],
"id": "getblock.io"
};
let config = {
method: "post",
maxBodyLength: Infinity,
url: "https://go.getblock.us/<ACCESS_TOKEN>",
headers: {
"Content-Type": "application/json",
},
data: data,
};
axios
.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x"
}Reponse Parameter Definition
result
string (hex)
Contract bytecode at the given address. Returns 0x if the address is not a contract.
Use case
The eth_getCode is used to:
Checking if an address is a contract or an externally owned account
Verifying onchain deployments for security audits
Allowing frontends to detect contract upgrades by comparing bytecode
Supporting explorers that display contract metadata
Identifying proxy contracts by checking for minimal bytecode patterns
Error handling
403
Forbidden
Missing or invalid ACCESS_TOKEN.
-32602
Invalid argument
The Address not 20 bytes or missing prefix
block hash isn't accurate or incomplete
keyword missing
Integration with Web3
The eth_getCode method helps developers to:
Detect whether a user is interacting with a contract or a wallet
Validate deployed bytecode for audit and debugging purposes
Build tools that identify proxies, multicall contracts, routers, and libraries
Support trustless dapps that rely on on-chain introspection
Ensure safe interactions by verifying contract code before sending transactions
Last updated
Was this helpful?