This guide covers integration patterns for Price Feeds, Randomness, and custom Radon-based requests.
You can enumerate supported feeds both from Solidity and from CLI.
Solidity path:
- Call
IWitPriceFeeds.lookupPriceFeeds(). - Return value is
PriceFeedInfo[], where each item includes: id,exponent,symbol,mapper,oracle,updateConditions,lastUpdate.
CLI path:
- Run
npx witeth priceFeeds. - CLI table highlights:
ID4: 4-byte feed id.CAPTION: feed caption.FRESHNESS: relative age of latest update.DATA PROVIDERS: source providers or mapped dependencies.
Use WitPriceFeeds to consume subsidized feeds through four compatible read paths.
Methods:
getPrice(ID4 id4)getPriceNotOlderThan(ID4 id4, uint24 age)getPriceUnsafe(ID4 id4)
Arguments:
id4: 4-byte feed identifier.age: max allowed staleness in seconds.
Reverts:
PriceFeedNotFound().StalePrice()for stale values in sanity-checked methods.InvalidGovernanceTarget()for invalid EMA/governance setup.
Returns:
Pricestruct:exponent,price,deltaPrice,timestamp,trail.
Method:
valueFor(bytes32 id)
Arguments:
id: 32-byte feed id.
Reverts:
- Usually status-driven rather than revert-driven for stale/missing values.
Returns:
(int256 value, uint256 timestamp, uint256 status)where current implementation uses:200fresh,400stale,404not found.
Methods:
getPrice(bytes32 id)getPriceNotOlderThan(bytes32 id, uint64 age)getPriceUnsafe(bytes32 id)getEmaPrice(bytes32 id)getEmaPriceNotOlderThan(bytes32 id, uint64 age)getEmaPriceUnsafe(bytes32 id)
Arguments:
id:bytes32price id.age: max accepted staleness in seconds.
Reverts:
PriceFeedNotFound().StalePrice()in sanity-checked methods.InvalidGovernanceTarget()for EMA/governance incompatibilities.
Returns:
PythPrice:price,conf,expo,publishTime.
Flow:
- Create adapter with
IWitPriceFeeds.createChainlinkAggregator(string caption). - Read through Chainlink-compatible methods on returned adapter.
Methods:
latestRoundData()getRoundData(uint80 roundId)decimals(),description(),version()id4(),priceId(),symbol(),witOracle()
Arguments:
caption: feed caption when creating adapter.roundId: round id for historical reads.
Reverts:
- Adapter creation reverts if caption is unsupported.
- Read calls may bubble up underlying feed lookup failures.
Returns:
- Chainlink tuple
(roundId, answer, startedAt, updatedAt, answeredInRound).
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import { IWitPriceFeeds, IWitPriceFeedsTypes } from "@witnet/solidity/contracts/interfaces/IWitPriceFeeds.sol";
import { IWitPyth } from "@witnet/solidity/contracts/interfaces/legacy/IWitPyth.sol";
import { IWitPythChainlinkAggregator } from "@witnet/solidity/contracts/interfaces/legacy/IWitPythChainlinkAggregator.sol";
interface IERC2362 {
function valueFor(bytes32 id) external view returns (int256 value, uint256 timestamp, uint256 status);
}
contract FeedReadExamples {
IWitPriceFeeds public immutable feeds;
constructor(address feedsAddress) {
feeds = IWitPriceFeeds(feedsAddress);
}
// 1) Witnet-native
function readNative(bytes4 id4)
external
view
returns (IWitPriceFeedsTypes.Price memory checked, IWitPriceFeedsTypes.Price memory unsafe_)
{
checked = feeds.getPrice(IWitPriceFeedsTypes.ID4.wrap(id4));
unsafe_ = feeds.getPriceUnsafe(IWitPriceFeedsTypes.ID4.wrap(id4));
}
// 2) ERC-2362 compatibility
function readErc2362(bytes32 id32) external view returns (int256 value, uint256 timestamp, uint256 status) {
return IERC2362(address(feeds)).valueFor(id32);
}
// 3) Pyth-adapted compatibility
function readPyth(bytes32 id32)
external
view
returns (IWitPyth.PythPrice memory spot, IWitPyth.PythPrice memory ema)
{
IWitPyth.ID id = IWitPyth.ID.wrap(id32);
spot = feeds.getPriceNotOlderThan(id, 300);
ema = feeds.getEmaPriceUnsafe(id);
}
// 4) Chainlink-adapted compatibility
function createAndReadChainlink(string calldata caption)
external
returns (address aggregator, int256 answer, uint256 updatedAt)
{
aggregator = feeds.createChainlinkAggregator(caption);
(, answer, , updatedAt, ) = IWitPythChainlinkAggregator(aggregator).latestRoundData();
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import { IWitPythChainlinkAggregator } from "@witnet/solidity/contracts/interfaces/legacy/IWitPythChainlinkAggregator.sol";
contract FeedReadChainlinkOnly {
IWitPythChainlinkAggregator public immutable adapter;
constructor(address adapterAddress) {
adapter = IWitPythChainlinkAggregator(adapterAddress);
}
function readLatest()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
return adapter.latestRoundData();
}
function metadata()
external
view
returns (bytes4 id4, bytes32 priceId, string memory symbol, address witOracle, uint8 decimals)
{
return (adapter.id4(), adapter.priceId(), adapter.symbol(), adapter.witOracle(), adapter.decimals());
}
}See the @witnet/price-feeds README:
See the @witnet/price-feeds README:
See the @witnet/price-feeds README:
Use WitRandomness randomize flow from your contract and consume finalized randomness once available.
npx witeth randomness --target <wit_randomness_address> --randomize --signer <evm_address>
npx randomizer --target <wit_randomness_address>- Clone WitRandomness.
- Trigger randomize from bot or transactions.
- Implement IWitRandomnessConsumer callback entrypoint.
npx witeth randomness --target <wit_randomness_address> --clone --signer <evm_address>A Radon Request defines data retrieval, transformation, aggregation, and commit/reveal parameters.
- Solidity: framework artifacts and contracts.
- JavaScript: @witnet/sdk asset composition.
npx witeth assets --all --decode
npx witeth assets <request_or_template> --dry-run
npx witeth assets <request_or_template> --deploynpx witeth queries --filter-radHash <rad_hash_fragment>
npx witeth reports --filter-radHash <rad_hash_fragment> --parse