Address:Documentation Index
Fetch the complete documentation index at: https://seilabs.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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 address0x0000000000000000000000000000000000001003 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 fees
Install Dependencies
Install the required packages for interacting with Sei precompiles:Import Precompile Components
Precompile Address: The JSON precompile is deployed at
0x0000000000000000000000000000000000001003Contract 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
| Function | Supports | Limitations |
|---|---|---|
| extractAsBytes | Strings, Objects, Arrays | Returns raw bytes - needs conversion |
| extractAsUint256 | Integers only | No decimals, booleans, or negative numbers |
| extractAsBytesList | Arrays of strings/objects | Each 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
Complete Integration Example
Create a comprehensive JSON parsing application for mainnet:json-precompile-mainnet.js
Running the Mainnet Example
- Create a new directory and initialize npm:
- Install dependencies:
- Create a
.envfile:
-
Create the demo file:
Copy the complete integration example above into
json-precompile-mainnet.js -
Ensure you have SEI tokens:
- SEI for gas fees (small amounts needed for view functions)
- Run the script:
Expected Output
Advanced Usage Examples
Oracle Price Feed Integration
Troubleshooting
Common Issues and Solutions
Key Not Found
Error Code Reference
| Error | Cause | Solution |
|---|---|---|
key not found | Specified key doesn’t exist in JSON | Verify key path and JSON structure |
invalid JSON format | Malformed JSON input | Use JSON.stringify() to ensure valid format |
execution reverted | Gas limit too low | Increase gas limit based on data complexity |
invalid integer | Non-numeric value for extractAsUint256 | Ensure the value is a valid integer |
out of gas | Insufficient gas for large JSON | Use calculateGasLimit() for dynamic estimation |
Key Considerations and Tricks
- Integers Only:
extractAsUint256only 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.