docs
Complete GET Example
4. Call send GET request

Make a Request GET

Finally, we will make a simple GET request in which we pass name and age in url.
Our backend will return:

Hello, john! You are 33 years old.

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 exampleSendRequestGET function.

Select type data response and 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 sendRequestGet.js script to make a request.

sendRequestGet.js
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 = 110499; // <== input the gas usage here
 
  const ethToSendInTx = fulfillGasUsed * gasPrice * 1.5;
 
  const name = "john";
  const age = "33";
 
  const sendRequestPostTx = await exampleContract.exampleSendRequestGET(
    fulfillGasUsed,
    name,
    age,
    {
      value: BigInt(ethToSendInTx),
    }
  );
  console.log("Tx:", sendRequestPostTx.hash);
 
  console.log(
    "-------------------- SEND REQUEST GET COMPLETED -----------------------"
  );
}
 
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
 

Now you can run the script:

yarn hardhat run scripts/sendRequestGet.js --network base_sepolia

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