Skip to content

REST API Reference

The REST API provides a simple HTTP interface for querying blockchain data on IOST Layer 2. This API is primarily used by block explorers and applications that need to retrieve on-chain data without implementing complex JSON-RPC calls.

Endpoint

The base REST API endpoint for IOST Layer 2 is: https://l2-scan.iost.io/api

Authentication

The REST API is publicly accessible without authentication for read-only operations. Rate limits may apply to prevent abuse.

API Categories

Block Data

EndpointMethodDescription
/blocksGETReturns a list of recently mined blocks
/blocks/{blockNumber}GETReturns details for a specific block by number
/blocks/{blockHash}GETReturns details for a specific block by hash
/blocks/transactions/{blockNumber}GETReturns all transactions in a block

Transaction Data

EndpointMethodDescription
/transactionsGETReturns a list of recent transactions
/transactions/{txHash}GETReturns details for a specific transaction
/transactions/pendingGETReturns list of pending transactions
/transactions/execution-status/{txHash}GETReturns execution status of a transaction

Account Data

EndpointMethodDescription
/addresses/{address}GETReturns account details and balance
/addresses/{address}/transactionsGETReturns transactions for an account
/addresses/{address}/token-balancesGETReturns all token balances for an address
/addresses/{address}/logsGETReturns logs emitted by contract interactions at this address

Token Data

EndpointMethodDescription
/tokensGETReturns a list of tokens on the network
/tokens/{contractAddress}GETReturns details for a specific token
/tokens/{contractAddress}/holdersGETReturns top token holders
/tokens/{contractAddress}/transfersGETReturns recent token transfers

Contract Data

EndpointMethodDescription
/contracts/{address}GETReturns details about a smart contract
/contracts/{address}/methodsGETReturns contract method signatures
/contracts/{address}/eventsGETReturns events emitted by the contract
/contracts/verificationPOSTSubmit contract for verification

Statistics

EndpointMethodDescription
/statsGETReturns network statistics (TPS, gas price, etc.)
/stats/charts/transactionsGETReturns transaction count over time
/stats/charts/marketGETReturns token price information
/stats/validatorsGETReturns information about validators

Common Query Parameters

Most GET endpoints support the following query parameters:

ParameterDescriptionExample
pagePage number for paginated results?page=2
limitNumber of results per page (max: 100)?limit=50
sortField to sort by (with optional direction)?sort=timestamp:desc
startDateFilter by start date (UNIX timestamp)?startDate=1633046400
endDateFilter by end date (UNIX timestamp)?endDate=1633132800

Response Format

All REST API responses are returned in JSON format with a consistent structure:

json
{
  "status": "success",
  "data": {
    // Response data here
  },
  "pagination": {
    "page": 1,
    "limit": 25,
    "total": 1000,
    "pages": 40
  }
}

Error Handling

When an error occurs, the API returns appropriate HTTP status codes along with an error response:

json
{
  "status": "error",
  "error": {
    "code": "RESOURCE_NOT_FOUND",
    "message": "The requested resource could not be found"
  }
}

Common HTTP Status Codes

Status CodeDescription
200Success
400Bad Request - Invalid parameters
404Not Found - Resource doesn't exist
429Too Many Requests - Rate limit exceeded
500Internal Server Error

Example Usage

Below is a sample code snippet in Python that demonstrates how to query recent blocks using the REST API:

python
import requests

def get_recent_blocks(page=1, limit=10):
    url = "https://l2-scan.iost.io/api/blocks"
    params = {"page": page, "limit": limit}
    response = requests.get(url, params=params)
    if response.status_code == 200:
        data = response.json()
        return data.get("data")
    else:
        print("Error:", response.status_code, response.text)
        return None

# Example: Get recent blocks
if __name__ == "__main__":
    blocks = get_recent_blocks()
    print("Recent Blocks:")
    print(blocks)

Pagination

Results from list endpoints are paginated by default. The pagination information is included in the response:

  • Default page size: 25 items
  • Maximum page size: 100 items
  • Page numbering starts at 1

To navigate through pages, use the page and limit parameters:

http
GET /api/transactions?page=2&limit=50

Additional Notes

  • All timestamps are returned in UNIX format (seconds since epoch).
  • Addresses should be provided in standard Ethereum format (0x-prefixed hexadecimal).
  • Block numbers can be provided as integers or hexadecimal strings.
  • Transaction hashes should include the 0x prefix.

Resources

For more information, visit the BlockScout Documentation, which provides the underlying technology for the IOST Layer 2 explorer.

Released under the MIT License.