Pull based oracles
Last updated
Last updated
Pull (or also known as Request Based Oracle) enables the creation of requests for asset prices on a source blockchain. These requests are sent through a mailbox on the current chain and ultimately delivered to the DIA chain, which retrieves and delivers the required price data.
A request is made from the source chain for an asset symbol whose price is required (e.g. ETH/USD) which then passes through the chain's mailbox to be then delivered to the destination chain. You check all the contracts in Testnet Addresses.
The request body is formatted as follows in JavaScript:
And this is how it is formatted in Solidity:
Once a request is created, it is transmitted to the Hyperlane mailbox. The message is then relayed to the OracleRequestRecipient
contract , where the price data is fetched from the Oracle Metadata Contract.
Upon receiving the request, the DIA chain initiates a transaction to deliver the message back to the end contract on the source chain. The recipient contract on the source chain must implement the IMessageRecipient interface, which includes a handle function that will receive the price quotation.
In this example, we’ll be sending an ETH/USD price request from Base Sepolia to DIA Lasernet. Start by cloning the Spectra Interoperability
repository to your local machine and switching to the deploy
branch:
Then install the node packages and compile the contracts using hardhat:
Next, cd contracts
folder, and export your wallet's private key in your terminal as follows:
Now, the sendMessage.mjs
script will trigger a request
transaction to fetch the latest price of ETH/USD from DIA lasernet. To run the script:
You can also run the script on other networks by changing the value passed to the --network
flag (e.g. --network sepolia
).
Optionally, you can take the txn hash from your terminal and paste it into the Hyperlane explorer, it will show you the status of the message sent from the source chain (e.g. Base Sepolia):
⚠️ You might get an error message saying "No chain config found for domain 10640" similar to the one shown below:
Here’s how to fix it:
Click on `add metadata` button on the Destination Transaction box
Copy the content in the `hyperlane.explorer.yml` file from the Spectra repo that you’ve cloned earlier
Paste it inside the popup window and click on “+ Add chain”
Copy the txn hash from the Destination Transaction window which represents the response hash and paste it into the hyperlane explorer search bar to check the delivery status from DIA lasernet to Base Sepolia. Once delivered, you can check the txn logs for the pull oracle contract by clicking on “View Explorer”.
The price returned is around 2,718$!