get_code

Eos RPC

Archive Method

Only on the full archive nodes. Complex queries might take longer and incur additional cost

Overview

The get_code method returns an object containing the smart contract WASM code for a specified account on the EOS blockchain. This method is paramount for developers who are looking to analyze or understand the WASM code of deployed smart contracts, enabling an in-depth interaction and integration with the smart contracts.

// yarn add @tatumio/tatum

import { TatumSDK, Eos, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Eos>({ network: Network.EOS })

const response = await tatum.rpc.getCode({
  accountName: 'eosio.token',
  codeAsWasm: 1,
})

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Example use cases:

  1. Smart Contract Analysis:
    Developers use this method to retrieve and analyze the WASM code of smart contracts, allowing for comprehensive understanding and debugging of the contract logic.

  2. WASM Code Inspection:
    This method is vital for users and developers wishing to inspect the WASM code, ensuring the contract's integrity, functionality, and security.

  3. Enhanced Integration and Interaction:
    Retrieving the WASM code facilitates seamless integration and interaction with smart contracts, ensuring proper deployment, execution, and management of contracts on the EOS blockchain.

Request Parameters

The getCode method requires the following parameters in the request body:

  • accountName (string, required): The name of the account whose smart contract WASM code needs to be retrieved. Acceptable types are NamePrivileged, NameBasic, NameBid, and NameCatchAll.
  • codeAsWasm (integer, required): This must be 1 (true).

Return Object

The get_code method returns an object containing:

  • name (string): The name of the account from which the WASM code was retrieved. Acceptable types are NamePrivileged, NameBasic, NameBid, and NameCatchAll.
  • code_hash (string): A Sha256 hash representing the WASM code of the retrieved smart contract.
  • wast (string): The WebAssembly text format representation of the smart contract.
  • wasm (string): The WebAssembly binary representation of the smart contract.
  • abi (object): The ABI (Application Binary Interface) of the smart contract, representing the binary representation of the contract's interface.

JSON-RPC Request Example

{
  "accountName": "eosio.token",
  "codeAsWasm": 1
}

JSON-RPC Response Example

{
  "name": "eosio.token",
  "code_hash": "a1b2c3d4e5f67890abcdef1234567890abcdef1234567890abcdef1234567890ab",
  "wast": "... (WAST string) ...",
  "wasm": "... (WASM binary string) ...",
  "abi": { ... (ABI object) ... }
}