eth_getCode - Somnia
Example code for the eth_getCode JSON-RPC method. Complete guide on how to use eth_getCode JSON-RPC in GetBlock Web3 documentation.
This method returns the bytecode at a given address on the Somnia network. This is useful for verifying contract deployment, checking if an address is a contract, and analyzing contract bytecode. Somnia's compiled EVM executes this bytecode at near-native speeds.
Parameters
address
string
Yes
The address to get code from
blockNumber
string
Yes
Block number in hex, or "latest", "earliest", "pending"
Request Example
curl -X POST https://go.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "eth_getCode",
"params": [
"0xContractAddress",
"latest"
]
}'const axios = require('axios');
const url = 'https://go.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
id: 'getblock.io',
method: 'eth_getCode',
params: ['0xContractAddress', 'latest']
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));Response Example
Response Parameters
result
string
Contract bytecode (0x if not a contract)
Use Cases
Verify contract deployment
Check if address is a contract vs EOA
Analyze contract bytecode
Detect proxy contracts
Security auditing
Error Handling
-32602
Invalid params - malformed address
-32603
Internal error - node processing issues
SDK Integration
Last updated
Was this helpful?