Deploy your Consumer
In this section, we will guide you through the process of deploying your consumer contract to interact with the OracleRouter. Let's get started!.
Open ExampleContract.sol
to edit exampleSendRequestGET()
function.
Set up your own host, with your PUBLIC IP, and port as we did in the previous section testServer.js
file.
ExampleContract.sol
function exampleSendRequestGET(
uint256 fulfillGasUsed,
string memory name,
string memory age
) external payable nonReentrant {
uint256 gasCost = gasCostFulfill(fulfillGasUsed);
require(
msg.value > gasCost,
"ETH sent is less than gas cost for the callback"
);
// Base URL
string memory baseUrl = "http://<your host>:<port>/greet/";
// Concatenate the URL with the name and age
string memory url = string(abi.encodePacked(baseUrl, name, "/", age));
OracleRequest.Request memory req;
req.url = url;
req.method = "GET";
req.slot = "0";
req.jsonResponsePath = "message"; // Adjust this according to the actual response structure
bytes memory requestData = req.encodeCBOR();
//this will emit a event on OracleRouter that nodes will caputure
//msg.value is sent here
uint256 requestId = _sendRequest(requestData, fulfillGasUsed);
}
Compile contracts:
yarn hardhat compile
Now you can deploy your contract.
Leave your testServer.js
running, open another terminal and run:
yarn hardhat deploy --tags example --network base_sepolia
Note: This deployment script also includes a script to add the consumer to the oracle, so in the next step, you won't need to add it again.