JSON API Request
Fetches JSON data from any public API endpoint and extracts specific values using a selector path. This agent is the fundamental building block for creating on-chain oracles.
Methods
fetchString
url, selector
string
Text values, names
fetchUint
url, selector, decimals
uint256
Prices, positive numbers
fetchInt
url, selector, decimals
int256
Temperatures, signed numbers
fetchBool
url, selector
bool
Flags, status checks
fetchStringArray
url, selector
string[]
Lists of names/IDs
fetchUintArray
url, selector, decimals
uint256[]
Price lists, numeric arrays
Parameters
url
string
The URL of the JSON API endpoint to fetch
selector
string
A dot-notation path to extract from the response (e.g., data.price or items[0].name)
decimals
uint8
Number of decimal places to scale the value by (multiplies by 10^decimals)
Decimal Scaling
The decimals parameter is used by fetchUint, fetchInt, and fetchUintArray to convert floating-point values from APIs into blockchain-compatible integers. The value is multiplied by 10^decimals.
For example, with decimals=8:
42000.50becomes42000500000000.00001234becomes1234
This follows the standard pattern for handling decimals in smart contracts (e.g., ERC-20 tokens typically use 18 decimals).
Method Signatures
Example Use Cases
Fetching cryptocurrency prices from CoinGecko or similar APIs
Retrieving weather data for parametric insurance contracts
Pulling sports scores for prediction markets
Accessing any REST API that returns JSON
Usage Examples
Fetch a Price as uint256
Fetch a String Value
Fetch a Boolean Value
Last updated