Skip to content

JSON-RPC API Reference

The JSON-RPC API is the primary interface for interacting with the IOST Layer 2 network. It follows the Ethereum JSON-RPC specification, making it compatible with existing Ethereum tools and libraries.

Endpoint

The JSON-RPC API endpoint for IOST Layer 2 is: https://l2-mainnet.iost.io

Request Format

All JSON-RPC requests follow this format:

json
{
  "jsonrpc": "2.0",
  "method": "METHOD_NAME",
  "params": [PARAM1, PARAM2, ...],
  "id": REQUEST_ID
}

API Methods by Category

Chain Information

MethodDescription
eth_chainIdReturns the chain ID
eth_blockNumberReturns the number of the most recent block
eth_syncingReturns sync status or false
eth_gasPriceReturns the current gas price in wei
eth_feeHistoryReturns fee history for blocks in specified range

Account Methods

MethodDescription
eth_getBalanceReturns account balance at specified block
eth_getCodeReturns code at a given address
eth_getStorageAtReturns value from storage position
eth_getTransactionCountReturns number of transactions sent from address
eth_accountsReturns list of addresses owned by client

Block Methods

MethodDescription
eth_getBlockByHashReturns block information by hash
eth_getBlockByNumberReturns block information by number
eth_getBlockTransactionCountByHashReturns number of transactions in block by hash
eth_getBlockTransactionCountByNumberReturns number of transactions in block by number
eth_getBlockReceiptsReturns all transaction receipts for a block

Transaction Methods

MethodDescription
eth_sendRawTransactionSubmits a signed transaction for broadcast
eth_getTransactionByHashReturns transaction information by hash
eth_getTransactionByBlockHashAndIndexReturns transaction by block hash and index
eth_getTransactionByBlockNumberAndIndexReturns transaction by block number and index
eth_getTransactionReceiptReturns transaction receipt by transaction hash
eth_estimateGasEstimates gas needed for transaction execution
eth_maxPriorityFeePerGasReturns suggestion for max priority fee per gas

Contract Methods

MethodDescription
eth_callExecutes a contract call without creating a transaction
eth_createAccessListCreates an access list for a transaction
eth_getLogsReturns logs matching given filter criteria

Filter Methods

MethodDescription
eth_newFilterCreates filter for state changes
eth_newBlockFilterCreates filter for new blocks
eth_newPendingTransactionFilterCreates filter for pending transactions
eth_getFilterChangesReturns filter changes since last poll
eth_getFilterLogsReturns all logs matching filter
eth_uninstallFilterUninstalls a filter

Network Methods

MethodDescription
net_versionReturns network ID
net_listeningReturns true if client is actively listening
net_peerCountReturns number of peers connected

Common Parameters

Block Parameters

Many methods accept a block parameter that can be:

  • Block number in hexadecimal format (e.g. "0x1b4")
  • Block hash
  • Tag string: "earliest", "latest", "pending"

Address Format

Ethereum-compatible 20-byte hex string with 0x prefix, e.g., "0x71c7656ec7ab88b098defb751b7401b5f6d8976f"

Gas Price/Limit

Gas values are in wei and represented as hex strings, e.g., "0x5d21dba00" for 25 Gwei

Response Format

All successful JSON-RPC responses have this format:

json
{
  "jsonrpc": "2.0",
  "id": REQUEST_ID,
  "result": RESPONSE_DATA
}

Error responses:

json
{
  "jsonrpc": "2.0",
  "id": REQUEST_ID,
  "error": {
    "code": ERROR_CODE,
    "message": ERROR_MESSAGE
  }
}

Example Usage

javascript
// Using fetch API
async function getBalance(address) {
  const response = await fetch("https://l2-mainnet.iost.io", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      jsonrpc: "2.0",
      method: "eth_getBalance",
      params: [address, "latest"],
      id: 1
    })
  });
  
  const data = await response.json();
  return data.result;
}

Using with Web3.js

javascript
const Web3 = require('web3');
const web3 = new Web3('https://l2-mainnet.iost.io');

// Get latest block
web3.eth.getBlockNumber()
  .then(blockNumber => console.log(`Latest block: ${blockNumber}`));

Using with ethers.js

javascript
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://l2-mainnet.iost.io');

// Get account balance
provider.getBalance('0xYourAccountAddress')
  .then(balance => console.log(`Balance: ${ethers.utils.formatEther(balance)} ETH`));

Additional Resources

For complete details on all available methods and parameters, refer to the Ethereum JSON-RPC Specification.

Released under the MIT License.