Get Clearing Price Of Certain Auction
In this tutorial, you will learn how to use the Moxie Offchain REST API to fetch the clearing price of a certain auction in Node.js.
Pre-requisites
Before following the tutorial, make sure that your machine fulfills the following requirements:
- Node.js v.18+
- npm v.10+
In addition, make sure that you have node-fetch
installed in your Node.js project. If you haven't installed it yet, you can do so by running the following command:
- npm
- yarn
- pnpm
- bun
npm install node-fetch
yarn add node-fetch
pnpm add node-fetch
bun install node-fetch
Step 1: Add REST API Call To The Code
You can easily call the Clearing Price API by sending a GET request providing the auctionId
of the auction and specifying which chain you would like to fetch from on the chainId
parameter by the following code snippet with node-fetch
:
- TypeScript
- JavaScript
import fetch from "node-fetch";
const options = {
method: "GET",
headers: {
accept: "application/json",
},
};
// The ID of the auction you want to fetch the clearing price for
const auctionId = 19;
/*
* The Chain ID to fetch the data from:
* - 84532 is for Base Sepolia Testnet
* - 8453 is for Base Mainnet
*/
const chainId = 84532;
fetch(
`https://batch-auction.airstack.xyz/api/clearing-price?auctionId=${auctionId}&chainId=${chainId}`,
options
)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
const fetch = require("node-fetch");
const options = {
method: "GET",
headers: {
accept: "application/json",
},
};
// The ID of the auction you want to fetch the clearing price for
const auctionId = 19;
/*
* The Chain ID to fetch the data from:
* - 84532 is for Base Sepolia Testnet
* - 8453 is for Base Mainnet
*/
const chainId = 84532;
fetch(
`https://batch-auction.airstack.xyz/api/clearing-price?auctionId=${auctionId}&chainId=${chainId}`,
options
)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));
Step 2: Execute Your Code
Once you have your code ready, you can execute it by running the following command:
- TypeScript
- JavaScript
ts-node index.ts
node index.js
If it runs successfully, you should see the data returned in the terminal:
{
"auction": {
"minBuyAmount": "37320999999999999737856",
"initialSupply": "37320999999999999737856",
"id": "0",
"clearingPrice": 1,
"userId": "0"
}
}
Congrats! 🥳🎉 You've just fetched the clearing price of a certain auction!
Developer Support
If you have any questions or need help with other use cases, feel free to join the Moxie Official Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.