docs
Complete Real Example
4. Call send request

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.

Input any arbitrary response you expect to return, no matter if you just guess it.

Gas Calculation

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.sol 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 = 44019; // <== 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 sendRequestPostTx = await exampleContract.exampleSendRequestPOST(
    fulfillGasUsed,
    {
      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 sepolia

Done!!! You've just made your first POST request!! 🎉🎊 Wait a few minutes for the oracle to provide a response.