TriportRPC

eth_getCode

POSThttps://api.triport.io/

Returns the deployed bytecode stored at an address at a given block.

Ethereumeth_read_rpcfree — 10 RPS (basic 20, pro 100, business 250)

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

Positional params array: [address, block].

addressstring (0x-prefixed, 20 bytes / 40 hex chars)required
The address whose code you want to read.
blockstringoptional
Block tag — latest, earliest, pending, or a 0x-prefixed hex block number. Defaults to latest if omitted.

Response

For an EOA or an address with no deployed code, the result is empty:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x"
}
resultstring
The deployed runtime bytecode at address, as a 0x-prefixed hex string. 0x (empty) for EOAs, never-deployed addresses, and contracts not yet deployed at the queried block.

Errors

Errors are returned in the standard JSON-RPC envelope (error.code + error.message). See errors.md for the full envelope and shared codes.

CodeMeaningWhen it happens
-32001trial_expiredThe API key's trial period has ended; upgrade to a paid tier to continue.
-32003rate_limitedYou exceeded the requests-per-second limit for your tier. Back off and retry.

Examples

JavaScript (fetch)

const res = await fetch("https://api.triport.io/", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "eth_getCode",
    params: ["0x6B175474E89094C44Da98b954EedeAC495271d0F", "latest"],
  }),
});


const { result } = await res.json();
const isContract = result !== "0x";
console.log(isContract ? "contract" : "EOA / no code");

TypeScript SDK (@triport/sdk)

import { Triport } from "@triport/sdk";


const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });


const code = await client.eth.getCode(
  "0x6B175474E89094C44Da98b954EedeAC495271d0F",
  "latest",
);


console.log(code === "0x" ? "no code" : `${(code.length - 2) / 2} bytes`);

Python (triport-sdk)

import os
from triport import Triport


client = Triport(api_key=os.environ["TRIPORT_API_KEY"])


code = client.eth.get_code(
    "0x6B175474E89094C44Da98b954EedeAC495271d0F",
    "latest",
)


print("EOA / no code" if code == "0x" else f"{(len(code) - 2) // 2} bytes")

Notes

  • 0x is the empty answer. EOAs, never-deployed addresses, and contracts that don't exist yet at the queried block all return 0x. Treat result !== "0x" as the canonical "this is a contract" test.
  • Runtime code, not init code. You get the bytecode persisted on chain, not the constructor/deployment bytecode and not the Solidity source. There is no ABI here — pair it with eth_call to actually invoke functions.
  • Block matters for proxies and self-destructs. Code at an address can appear or disappear over time (counterfactual/CREATE2 deployments, historical SELFDESTRUCT). Pin a block hex height for reproducible historical reads instead of relying on latest.
  • Rate limits are enforced per second per tier (no daily cap). On -32003, honor exponential backoff rather than retrying immediately.