⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_getCode

Returns the bytecode at a given address.

When to Use This Method

Use eth_getCode to:

  • Verify Contract Deployment - Check if contract exists
  • Get Contract Bytecode - Retrieve deployed contract code
  • Distinguish EOAs from Contracts - EOAs return 0x
  • Contract Verification - Compare deployed vs expected bytecode
  • Security Audits - Analyze deployed contract code

Parameters

  1. Address - DATA, 20 Bytes

    • Address to get code from
  2. Block Parameter - QUANTITY|TAG

    • latest, earliest, pending, or block number
{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x239e96c8f17C85c30100AC26F635Ea15f23E9c67",
"latest"
],
"id": 1
}

Returns

DATA - The bytecode from the given address.

Implementation Examples

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY');

// Check if address is a contract
async function isContract(address) {
const code = await provider.getCode(address);
return code !== '0x';
}

// Get contract bytecode
const contractAddress = '0x239e96c8f17C85c30100AC26F635Ea15f23E9c67';
const bytecode = await provider.getCode(contractAddress);

if (bytecode !== '0x') {
console.log('Contract found, bytecode length:', bytecode.length);
} else {
console.log('No contract at this address (EOA)');
}