{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xa0b86a33e6776e1e627e5c82df4c0cf77b8bb0c9",
    "latest"
  ]
}
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c..."
}

Defined in the Ethereum JSON-RPC Specification

Returns the bytecode at a given address. This is useful for verifying if an address is a contract or an externally owned account.

Parameters

address
string
required

The address to get bytecode from (20 bytes).

blockParameter
string
required

Integer block number, or the string “latest”, “earliest” or “pending”.

Returns

result
string

The bytecode at the given address as a hexadecimal string. Returns “0x” for externally owned accounts.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xa0b86a33e6776e1e627e5c82df4c0cf77b8bb0c9",
    "latest"
  ]
}
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c..."
}

Error Handling

CodeMessageDescription
-32602Invalid address or block parameterThe provided address or block parameter is invalid
4100Requested method not supportedThe method is not supported by the wallet

If the result is “0x”, the address is an externally owned account (EOA). If it contains bytecode, it’s a smart contract.