Foundry
For this tutorial, you will be using the Foundry toolkit to develop, compile, and deploy your 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 the contract, first 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 you 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, 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 the contract is compiled and ready, you can deploy it to the MiniEVM. To accomplish this, use Foundry’sforge script command. First, 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 |