Make a Request POST
Finally, we will make a simple POST request in which we pass arg_1
and arg_2
in the body. Our backend will sum them and return a response.
Calulate Gas Use for Oracle Callbacks
First, we need to calculate the gas that the oracle will use in the callback. To do this, we can use the calculator from the dashboard to see the amount of gas used and then pass it to the exampleSendRequestPOST
function.
Select type data response and input any arbitrary response you expect to return, no matter if you just guess it.
This will return the amount of gas units that the oracle will use in the callback. We are almost ready to make our first request to the oracle congratulations! 🎉
Now that we have the amount of gas the oracle will use, we can use it as a parameter in the sendRequestPost.js
script to make a request.
const { ethers, deployments, network } = require("hardhat");
const { getAccount } = require("../utils/getAccount");
const { getGasPrice } = require("../utils/getGasPrice");
async function main() {
let rpcUrl = network.config.url;
let provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const account = getAccount("main", provider);
const exampleDeployment = await deployments.get("ExampleContract");
const exampleAddress = exampleDeployment.address;
const exampleAbi = exampleDeployment.abi;
const exampleContract = new ethers.Contract(
exampleAddress,
exampleAbi,
account
);
const gasPrice = await getGasPrice();
const fulfillGasUsed = 136970; // <== input the gas usage here
const ethToSendInTx = fulfillGasUsed * gasPrice * 1.5; //<== apply 50% more gas just for small fluctuactions. Exceed gas wil refund to caller by the oracle
const inputValue_1 = '3'
const inputValue_2 = '7'
const sendRequestPostTx = await exampleContract.exampleSendRequestPOST(
fulfillGasUsed,
inputValue_1,
inputValue_2,
{
value: BigInt(ethToSendInTx),
}
);
console.log("Tx:", sendRequestPostTx.hash);
console.log(
"-------------------- SEND REQUEST POST COMPLETED -----------------------"
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Now you can run the script:
yarn hardhat run scripts/sendRequestPost.js --network base_sepolia
Done!!! You've just made your first POST request!! 🎉🎊 Wait a few minutes for the oracle to provide a response.