Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
Supported ChainsLineaJSON-RPC APIAccount Methods

eth_getCode - Linea RPC Method

Get contract bytecode on Linea. Essential for verifying smart contracts for enterprise DeFi (Aave, Renzo), institutional cross-border payments via SWIFT pilots, and zkEVM-native applications.

Linea RPC endpoint: endpoint URLs, plans and pricing.

Returns the bytecode at a given address on Linea.

Why Linea? Build on Consensys-backed zkEVM L2 with $1B+ TVL and 807% growth in 2025 with 15-30x lower fees than Ethereum mainnet, 6,200 TPS throughput, SWIFT integration with 12+ institutions, and $725M Consensys backing.

When to Use This Method

eth_getCode is essential for enterprise developers, DeFi builders, and teams seeking Consensys ecosystem integration:

  • Contract Verification -- Verify that the bytecode deployed at an address matches the expected source code compilation output on Linea
  • EOA vs Contract Detection -- Determine whether an address is an externally owned account (returns 0x) or a deployed smart contract (returns bytecode)
  • Proxy Pattern Detection -- Check if a proxy contract has been initialized by examining whether its implementation slot contains code
  • Security Auditing -- Validate contract deployments before interacting with them on enterprise DeFi (Aave, Renzo), institutional cross-border payments via SWIFT pilots, and zkEVM-native applications

Common Use Cases

1. Detect Contract vs EOA

Determine if an address is a smart contract or a regular wallet on Linea:

JavaScript
import { JsonRpcProvider } from 'ethers';

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

async function isContract(address) {
  const code = await provider.getCode(address);
  return code !== '0x' && code !== '0x0';
}

async function classifyAddress(address) {
  if (await isContract(address)) {
    const balance = await provider.getBalance(address);
    console.log('Contract at', address, '- balance:', balance.toString());
    return 'contract';
  }
  console.log('EOA at', address);
  return 'eoa';
}

2. Verify Proxy Implementation Initialization

Check whether a proxy contract has been initialized with an implementation on Linea:

JavaScript
import { JsonRpcProvider } from 'ethers';

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

async function checkProxyInitialized(proxyAddress) {
  // EIP-1967 implementation slot
  const IMPL_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc';
  
  const slotValue = await provider.getStorage(proxyAddress, IMPL_SLOT);
  const implAddress = '0x' + slotValue.slice(26);
  
  const implCode = await provider.getCode(implAddress);
  const hasCode = implCode !== '0x' && implCode !== '0x0';
  
  console.log(`Proxy: ${proxyAddress}`);
  console.log(`Implementation: ${implAddress} (has code: ${hasCode})`);
  
  return hasCode;
}

3. Batch Contract Detection

Scan multiple addresses to classify them efficiently:

JavaScript
async function scanAddresses(provider, addresses) {
  const results = [];
  
  for (const address of addresses) {
    try {
      const code = await provider.getCode(address);
      const type = (code === '0x' || code === '0x0') ? 'EOA' : 'Contract';
      results.push({ address, type, bytecodeSize: code.length });
    } catch (error) {
      results.push({ address, type: 'Error', error: error.message });
    }
  }
  
  const summary = {
    total: results.length,
    contracts: results.filter(r => r.type === 'Contract').length,
    eoas: results.filter(r => r.type === 'EOA').length,
    errors: results.filter(r => r.type === 'Error').length
  };
  
  console.log('Scan results:', summary);
  return { results, summary };
}

Best Practices

  • Check both 0x and 0x0 return values -- different client implementations return one or the other for EOAs
  • Use historical block numbers with eth_getCode to verify contract state at a specific point in time
  • For proxy pattern detection, combine eth_getCode with eth_getStorageAt to fully verify initialization
  • Cache bytecode by address, as deployed contract code is immutable
  • The return value length is roughly 2x the deployment bytecode size (hex encoding doubles the byte count)
JSON-RPC request
{
  "jsonrpc": "2.0",
  "method": "eth_getCode",
  "params": [
    "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
    "latest"
  ],
  "id": 1
}

Code Examples

Related Methods

  • eth_getBalance - Get account balance
  • eth_getStorageAt - Get contract storage

eth_getBalance

Query account balance on Linea. Essential for wallet applications and enterprise DeFi (Aave, Renzo), institutional cross-border payments via SWIFT pilots, and zkEVM-native applications on Consensys-backed zkEVM L2 with $1B+ TVL and 807% growth in 2025.

eth_getStorageAt

Read the value from a storage slot at a given contract address on Linea. Essential for reading contract state directly, proxy implementation verification, and storage layout analysis.

On this page

When to Use This MethodCommon Use Cases1. Detect Contract vs EOA2. Verify Proxy Implementation Initialization3. Batch Contract DetectionBest PracticesCode ExamplesRelated Methods