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 exampleSendRequestPOST()
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 exampleSendRequestPOST(
uint256 fulfillGasUsed,
string memory valueInput_1,
string memory valueInput_2
) external payable nonReentrant {
uint256 gasCost = gasCostFulfill(fulfillGasUsed);
require(
msg.value > gasCost,
"ETH sent is less than gas cost for the callback"
);
string memory url = "http://<your host>:<port>/sum/"; //<--- SETUP YOUR HOST HERE
string memory requestBody = string(
abi.encodePacked(
'{"arg_1":"', //<--- We setted in server.js this key body so we pass it now
valueInput_1,
'","arg_2":"', //<--- We setted in server.js this key body so we pass it now
valueInput_2,
'"}'
)
);
OracleRequest.Request memory req;
req.url = url;
req.method = "POST";
req.slot = "0";
req.jsonResponsePath = "data.result";
req.requestBody = requestBody;
req.bodyValuesDataTypes = '["uint256","uint256"]';
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.