Skip to main content
Address: 0x0000000000000000000000000000000000001003 The Sei JSON precompile allows EVM applications to efficiently parse and query JSON data directly within smart contracts. This enables complex data handling capabilities that are not natively available in Solidity, making it easier to work with structured data from external sources or APIs.
What is a precompile? A precompile is a special smart contract deployed at a fixed address by the Sei protocol itself, that exposes custom native chain logic to EVM-based applications. It acts like a regular contract from the EVM’s perspective, but executes privileged, low-level logic efficiently.

How Does the JSON Precompile Work?

The JSON precompile at address 0x0000000000000000000000000000000000001003 exposes functions like extractAsBytes(), extractAsBytesList(), and extractAsUint256().
  • Direct Integration: EVM contracts and dApps can parse JSON data like any other smart contract method.
  • Native Execution: JSON parsing is executed at the native level for maximum efficiency.
  • Seamless Bridge: No need for complex workarounds or external libraries for JSON handling.

Use Cases

  • Oracle Integration: Parse complex oracle responses containing multiple data points.
  • DeFi Applications: Process structured price feeds and market data.
  • Gaming: Handle complex game state and player data stored in JSON format.
  • Cross-Chain Communication: Parse messages and data from other chains.
  • NFT Metadata: Extract and manipulate NFT metadata stored in JSON format.

Functions

The JSON precompile exposes the following functions:

Query Functions

Using the Precompile

Setup

Prerequisites

Before getting started, ensure you have:
  • Node.js (v18 or higher)
  • npm or yarn package manager
  • MetaMask or compatible EVM wallet configured for Sei Mainnet
  • SEI tokens for gas

Install Dependencies

Install the required packages for interacting with Sei precompiles:

Import Precompile Components

Precompile Address: The JSON precompile is deployed at 0x0000000000000000000000000000000000001003

Contract Initialization

Set up your provider, signer, and contract instance:

Data Type Handling

The JSON precompile has specific limitations for different data types:

Supported Data Types

FunctionSupportsLimitations
extractAsBytesStrings, Objects, ArraysReturns raw bytes - needs conversion
extractAsUint256Integers onlyNo decimals, booleans, or negative numbers
extractAsBytesListArrays of strings/objectsEach element returned as bytes

Data Type Conversion Strategies

Error Handling Utilities

Create comprehensive error handling for all extraction functions:

Step-by-Step Guide: Using the JSON Precompile

Extract String Data

Extract Numeric Data

Extract Array Data

Extract Nested Data

Important: The JSON precompile does not support dot notation for nested objects. Instead, extract the parent object and parse it manually.

Complete Integration Example

Create a comprehensive JSON parsing application for mainnet:
json-precompile-mainnet.js

Running the Mainnet Example

  1. Create a new directory and initialize npm:
  1. Install dependencies:
  1. Create a .env file:
Security Note: Never commit private keys to version control! The .env file should be added to your .gitignore.
  1. Create the demo file: Copy the complete integration example above into json-precompile-mainnet.js
  2. Ensure you have SEI tokens:
    • SEI for gas (small amounts needed for view functions)
  3. Run the script:

Expected Output

Advanced Usage Examples

Oracle Price Feed Integration

Troubleshooting

Common Issues and Solutions

Key Not Found

Error Code Reference

ErrorCauseSolution
key not foundSpecified key doesn’t exist in JSONVerify key path and JSON structure
invalid JSON formatMalformed JSON inputUse JSON.stringify() to ensure valid format
execution revertedGas limit too lowIncrease gas limit based on data complexity
invalid integerNon-numeric value for extractAsUint256Ensure the value is a valid integer
out of gasInsufficient gas for large JSONUse calculateGasLimit() for dynamic estimation

Key Considerations and Tricks

  • Integers Only: extractAsUint256 only handles integers - no decimals, booleans, or negative numbers
  • Decimal Handling: Store decimal numbers as integers with known precision (e.g., 275 for 2.75 with 2 decimal places)
  • Boolean Values: Use 0/1 integers to represent false/true
  • Key Paths: Extract parent objects first, then parse manually - dot notation may not be supported
  • Arrays: Must use extractAsBytesList() for array data
  • Gas Costs: Large JSON objects require higher gas limits
  • Encoding: Always use UTF-8 encoding with ethers.toUtf8Bytes()
  • Error Handling: Always implement fallback values for production applications
Need Help? If you encounter issues not covered here, check the Sei Discord or GitHub repository for community support.