eth_getCode | Aurora

Aurora API method that retrieves the compiled bytecode of a smart contract, providing its address as a parameter. This method returns a hexadecimal string representing the smart contract's bytecode.

Developers can use this bytecode to verify whether a smart contract is legitimate and ensure that it performs its intended functions.

๐Ÿ‘

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • address โ€” the address of the smart contract to query.

  • quantity or tag โ€” the integer of a block encoded as hexadecimal or the string with:

    • latest โ€” the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.

    • safe โ€” the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.

    • finalized โ€” the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked amount to be burned.

    • earliest โ€” the earliest available or genesis block.

    • pending โ€” the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

      ๐Ÿ“˜

      See the default block parameter and How The Merge Impacts Ethereumโ€™s Application Layer.

Response

data โ€” the compiled bytecode of a smart contract. Returns 0x if the address is not associated with a smart contract.

eth_getCode code examples

The following example retrieves the compiled bytecode from the WETH token smart contract.

const { Web3 } = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);

async function getCode(address, block) {
  const code = await web3.eth.getCode(address, block)
  console.log(code)
 }
 
 getCode("0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB", "latest" )
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const getCode = async (address, block) => {
    const code = await provider.send("eth_getCode", [address, block]);
    console.log(code);
  };

  getCode("0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB", "latest")
from web3 import Web3  
node_url = "CHAINSTACK_NODE_URL" 

code = web3.eth.get_code("0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB", "latest") 
print(web3.to_hex(code))   # Convert the Bytes result into HEX.

Use case

A practical use case for the eth_getcode method is verifying whether an address is associated with a smart contract. This can be particularly useful for blockchain explorers, auditors, and DApp developers, who must ensure that the account they interact with is legitimate.

Try the eth_getCode RPC method yourself

Language
Click Try It! to start a request and see the response here!