π¬Apollo: request feeds from EVM
Step-by-step integration real-world data to your EVM SC

Contract
Contract
Contract
Last updated
// Import the ApolloReceiver contract
import {ApolloReceiver} from "../apollo/ApolloReceiver.sol";
// Your contract inherits from ApolloReceiver
contract YourContract is ApolloReceiver {
// Constructor initializes the ApolloReceiver with registry and coordinator addresses
constructor(address _executorsRegistry, address _apolloCoordinator)
ApolloReceiver(_executorsRegistry, _apolloCoordinator) {}
}// Example function to request a price feed
// `apolloCoordinator` is passing as public var from ApolloReceiver contract
function requestRandomFeed() public {
// Requesting the randomness with a specified callback gas limit and number of random words
apolloCoordinator.requestRandomFeed(300000, 1);
}// Example function to request a price feed
// `apolloCoordinator` is passing as public var from ApolloReceiver contract
function requestPriceFeed() public {
// Requesting the ICP/USD price feed with a specified callback gas limit
apolloCoordinator.requestDataFeed("ICP/USD", 300000);
}contract YourContract is ApolloReceiver {
// ...
// Overriding the fulfillData function to handle incoming data
function fulfillData(bytes memory data) internal override {
(, uint256[] memory randomWords) = abi.decode(data, (uint256, uint256[]));
// transform the result to a number between 1 and 20 inclusively
uint256 randomNumber = (randomWords[0] % entries.length) + 1;
pickWinner(randomNumber);
}
}contract YourContract is ApolloReceiver {
// Data storage variables
uint256 public requestId;
string public dataFeedId;
uint256 public rate;
uint256 public decimals;
uint256 public timestamp;
// Overriding the fulfillData function to handle incoming data
function fulfillData(bytes memory data) internal override {
(
uint256 _requestId,
string memory _dataFeedId,
uint256 _rate,
uint256 _decimals,
uint256 _timestamp
) = abi.decode(data, (
uint256,
string,
uint256,
uint256,
uint256
));
requestId = _requestId;
dataFeedId = _dataFeedId;
rate = _rate;
decimals = _decimals;
timestamp = _timestamp;
}
}