🔵 Base
eth_getCode

eth_getCode - Base Chain JSON-RPC Method

Overview

The eth_getCode method retrieves the deployed bytecode of a smart contract on the Base chain. This method allows developers to examine compiled smart contract code at a specific address and block.

Returns

code - The bytecode from a given address returned as a string (Shows the compiled smart contract code).

Parameters

1. address [required] - String - Address of the smart contract you want to get code from (20 Bytes)

2. blockNumber/Hash or Tag [required] - The hexadecimal block number OR block hash OR the string Tag ("latest", "earliest", or "pending").

Note: Unlike Ethereum and Arbitrum One chains, the "safe" and "finalized" tags are not available on Base chain. Read block parameter description (opens in a new tab).

Request

POST https://base-mainnet.chainnodes.org/YOUR-API-KEY

Need RPC API keys?

Get 12.5M archival requests for free today.

Example

  • HTTPS POST Request with a JSON RPC call in the body
  • Replace YOUR-API-KEY with the API key from your Chainnodes.org Dashboard
  • You can use a different supported network by replacing base-mainnet
curl https://base-mainnet.chainnodes.org/YOUR-API-KEY \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xD54f502e184B6B739d7D27a6410a67dc462D69c8", "latest"],"id":1}'

Body

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x6080604052600436106100c85760003560e01c80635e3a97e71161007a5780635e3a97e7146103265780636684b1d6146103b35780637147855d146103c857806372a44f07146104485780638757653f1461045d578063b449ea5d14610490578063e907fa3c146104d7578063f9bcdde4146104ec576100c8565b806312f16e6d1461014c57806314778a831461018157806320cea94d146101a857806322175a32146101bd578063439fab91146101f057806356f36dbf1461026b5780635c60da1b146102f5575b6000610...................."
}

Common Use Cases

  1. Contract Verification: Verify that a deployed contract's bytecode matches the expected compiled code.

  2. Empty Address Check: Determine if an address is a contract by checking if it returns bytecode (non-contract addresses return 0x).

// If result is "0x", the address is not a contract
{"jsonrpc":"2.0","method":"eth_getCode","params":["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"],"id":1}
  1. Contract State Analysis: Examine contract code at different blocks to analyze how it has changed over time.

  2. Contract Proxy Detection: Identify proxy contracts by analyzing their bytecode patterns.

  3. Historical Contract State: Retrieve a contract's code at a specific block to understand its functionality at that point.

// Get contract code at a specific historical block
{"jsonrpc":"2.0","method":"eth_getCode","params":["0xD54f502e184B6B739d7D27a6410a67dc462D69c8", "0x100000"],"id":1}

💡 Confusing?

Ask our experienced blockchain developers in Telegram