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
First, we need to create a new directory for our project.Implementing the Contract
Before writing our contract, we first need to rename the template contract toNewInitiaERC20.sol
IConnectOracle interface from the @initia/initia-evm-contracts package.
src/Oracle.sol
connect: The interface of the ConnectOracle contractcurrencyPair: The variable that stores the currency pair response from ConnectOraclepriceThe variable that stores the single pair price response from ConnectOraclepricesThe variable that stores the multiple pair prices response from ConnectOracle
src/Oracle.sol
src/Oracle.sol
oracle_get_all_currency_pairs: This function will return all of the asset pairs currently supported by Connectoracle_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, we will get an error.
This is because the default Oracle.t.sol expects the original Oracle.sol contract to be available. To fix this, we will rename Oracle.t.sol to OracleTest.t.sol.
test/OracleTest.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 create command
oracle_get_all_currency_pairs function using Foundry’s cast send command.
currencyPairs variable using Foundry’s cast call command, you should see the response from Connect.