Apollo: request feeds from EVM
Step-by-step integration real-world data to your EVM SC
Last updated
Step-by-step integration real-world data to your EVM SC
Last updated
Apollo is an intricate module developed to bridge the gap between EVM (Ethereum Virtual Machine) contracts and the data-rich environment of the Orally platform, particularly its Sybil component. Beyond mere data provisioning, Apollo is also configured to provide a level of randomness through a cryptographic measure, utilizing the unpredictable BLS signatures inherent to the Internet Computer (ICP) execution layer.
Integration Steps:
To start using the Apollo module, your smart contract needs to inherit from ApolloReceiver
. This setup allows your contract to receive data from the Apollo network:
// 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) {}
}
To request data, such as a price feed, use the requestDataFeed
(or requestRandomFeed
for randomness) function from the ApolloCoordinator
(interface). This function emits an event that the Apollo network listens for to provide the requested data.
// 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);
}
Override the fulfillData
function to define how your contract should handle the incoming data. This function is called when the Apollo network delivers the data to your contract.
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);
}
}
That's it! You successfully requested data and received it in the callback.
Here are contract addresses for IApolloCoordinator and IOrallyExecutorRegistry.
Here are Apollo consumer examples:
RaffleExample (randomness)
ApolloConsumerExample (price feed)