On-Chain GraphQL Query Precompile
A precompile that lets any EVM contract run a GraphQL query against the G-Chain query layer, with a result cache, subscriptions, and index hints, and a gas schedule priced off the query AST
Abstract
An on-chain GraphQL query precompile lets any EVM contract execute a GraphQL query against the G-Chain query layer (LP-1300). Contracts read indexed chain state, cross-chain data, and oracle feeds without any off-chain infrastructure. The precompile carries a result cache, subscription registration, cache management, and index hinting.
Specification
Addresses
| Address | Function |
|---|---|
0x0500000000000000000000000000000000000010 | GraphQL query execution |
0x0500000000000000000000000000000000000011 | Subscription registration |
0x0500000000000000000000000000000000000012 | Cache management |
0x0500000000000000000000000000000000000013 | Index hints |
The authoritative as-built address table for every Lux precompile is LP-1210; the derivation rule is LP-1220.
Interface
Query (0x…0010):
Input: query_len(2) + query(UTF-8) + variables_len(2) + variables(JSON)
Output: result(JSON bytes)
Subscribe (0x…0011):
Input: subscription query + callback address + callback selector
Output: subscription_id(32)
Cache (0x…0012):
Input: op(1) + cache_key(32)
0x01: Get cached result
0x02: Invalidate cache entry
0x03: Set TTL
Gas schedule
Gas scales with query complexity, estimated from the query AST:
| Component | Gas |
|---|---|
| Base query | 5,000 |
| Per field | 100 |
| Per filter / where clause | 500 |
| Per join / relation | 1,000 |
| Cache hit | 500 |
| Subscription registration | 10,000 |
Security Considerations
- Query complexity is bounded — maximum depth, field count, and result size are all enforced, so a query cannot become a denial-of-service vector.
- Cross-chain queries return data at the latest finalized block height. No unconfirmed data reaches a contract.
- Cache entries carry TTLs and can be invalidated. The staleness risk is the calling contract's to manage.
- The G-Chain client connection is local to the node. No external network call happens during EVM execution.
References
- GraphQL Foundation, GraphQL Specification
- Source:
github.com/luxfi/precompile/graph/
Copyright
Copyright and related rights waived via CC0.