Compiling contracts that use ConnectOracle.sol requires the viaIR feature. For Foundry/Forge, this can be done by using the
--via-ir
flag. The relevant methods for other tools may vary.Foundry
For this tutorial, we will be using Foundry toolkit to develop, compile, and deploy our contracts. If you do not have Foundry installed, follow the Foundry installation instructions.Setup
Create a new project directory and initialize it withforge init
:
Implementing the Contract
Before writing our contract, we first need to rename the template contract toOracle.sol
IConnectOracle
interface, which will be used to interact with the ConnectOracle contract.
src/Oracle.sol
The ConnectOracle contract is on MiniEVM precompiles. You can get its address by querying The output will look like this:
${REST_URL}/minievm/evm/v1/connect_oracle
where ${REST_URL}
refers to the REST endpoint URL of the rollup.src/Oracle.sol
oracle_get_price
: This function will return the price of a single asset pairoracle_get_prices
: This function will return the price of multiple asset pairs
src/Oracle.sol
src/Oracle.sol
forge compile
will fail unless we provide a test file that matches the Oracle.sol
contract. Foundry expects a test file like Oracle.t.sol
to exist and import the contract under test. To resolve this, we will rename the existing test file Counter.t.sol
to Oracle.t.sol
.
test/Oracle.t.sol
forge compile
should work without any errors.
Deploying the Contract
Now that our contract is compiled and ready, we can deploy it to the MiniEVM. To accomplish this, we will use Foundry’sforge script
command. First, we need to create a script file to handle the deployment. Create a new file named Oracle.s.sol
in the script
directory.
script/Oracle.s.sol
PRIVATE_KEY
with the deployer’s private key, and JSON_RPC_URL
with your rollup’s JSON-RPC endpoint.
oracle_get_price()
function, use Foundry’s cast call command.
Field | ABI-Encoded Value | Decoded Value |
---|---|---|
Price | 0x2c3cd0d43 | 11874929987 |
Timestamp | 0x1856610b4b695788 | 1753695806045116296 |