TriportRPC

eth_getCode

Last updated:

eth_getCode returns the compiled EVM bytecode deployed at an address, as a 0x-prefixed hex string, as of a specific block. This is the code that actually runs when the contract is called — not the source, the ABI, or the constructor ("init") code, but the runtime bytecode persisted on chain.

Use it to tell a contract apart from an externally-owned account (EOA), to fetch the on-chain bytecode for verification or disassembly, or to confirm that a deployment landed at the expected address before you start calling it.

The key behaviour to plan for: an empty result is 0x. A plain wallet (EOA), an address that has never been deployed to, and a contract that hasn't been deployed yet at the queried block all return 0x. Code presence is therefore the reliable "is this a contract?" check — result !== "0x" means bytecode exists at that address at that block.

Parameters

This method takes no parameters.

Returns

eth_getCode return value
FieldType
resultobject

Examples

curl https://triport.io/eth \
  -X POST -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <api-key>' \
  -d '{"id":1,"method":"eth_getCode","params":[],"jsonrpc":"2.0"}'
const res = await fetch("https://triport.io/eth", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: "Bearer <api-key>" },
  body: JSON.stringify({
  "id": 1,
  "method": "eth_getCode",
  "params": [],
  "jsonrpc": "2.0"
}),
});
const data = await res.json();
import requests
resp = requests.post(
    "https://triport.io/eth",
    headers={"Authorization": "Bearer <api-key>"},
    json={"id":1,"method":"eth_getCode","params":[],"jsonrpc":"2.0"},
)
print(resp.json())

Usage

  1. Transport: HTTP (JSON-RPC).
  2. Networks: mainnet.
  3. Credit cost: 1 per call.

FAQ

What does eth_getCode do?
Returns the deployed bytecode stored at an address at a given block.
How many credits does eth_getCode cost?
eth_getCode costs 1 credit(s) per call on Triport by default.
Is eth_getCode available over WebSocket?
eth_getCode is an HTTP JSON-RPC method.