Skip to content
Cive

getCode

Get the code of the specified contract. If contract not exist will return undefined.

Usage

import { publicClient } from "./client";
const bytecode = await publicClient.getCode({
  address: "cfx:...",
});

Returns

Return Hex if the address has code; otherwise, return undefined.

Parameters

address

  • Type: Address

The address to check for collateral storage

const contractAddress = await publicClient.getCode({
  address: "cfx:...", 
});

epochTag (optional)

  • Type: latest_state| latest_confirmed| latest_checkpoint | earliest
  • Defaut: latest_state
const contractAddress = await publicClient.getCode({
  address: "cfx:...",
  epochTag: "latest_state", 
});

epochNumber (optional)

  • Type: bigint
const contractAddress = await publicClient.getCode({
  address: "cfx:...",
  epochNumber: 1n, 
});

JSON-RPC Method

cfx_getCode