Node.js
In this tutorial, you will learn how to use the Moxie Auction Subgraph API to fetch data from the Moxie protocol auction contract in Node.js.
Here, you will be shown an example to fetch Moxie protocol auction summary data, but you can use other APIs to fetch other data available on the Moxie Auction Subgraph API.
For more details on the Moxie Auction Subgraph API, check out the Subgraph Studio here.
Pre-requisites
Before following the tutorial, make sure that your machine fulfills the following requirements:
Step 1: Setup Node.js project
First, create a new Node.js project by running the following command:
npm init -y
Then, install the graphql
and graphql-request
packages into your project:
- npm
- yarn
- pnpm
- bun
npm install graphql graphql-request undefined
yarn add graphql graphql-request undefined
pnpm add graphql graphql-request undefined
bun install graphql graphql graphql-request undefined
Step 2: Add Query Call To The Code
You can then create a new file and import graphql-request
to make a query call to the Moxie Auction Subgraph API:
- TypeScript
- JavaScript
import { gql, GraphQLClient } from "graphql-request";
const graphQLClient = new GraphQLClient(
"https://api.studio.thegraph.com/query/23537/moxie_auction_stats_mainnet/version/latest"
);
const query = gql`
query MyQuery {
summaries {
totalAuctions
totalBiddingValue
totalOrders
}
}
`;
try {
const data = await graphQLClient.request(query);
console.log(data);
} catch (e) {
throw new Error(e);
}
const { gql, GraphQLClient } = require("graphql-request");
const graphQLClient = new GraphQLClient(
"https://api.studio.thegraph.com/query/23537/moxie_auction_stats_mainnet/version/latest"
);
const query = gql`
query MyQuery {
summaries {
totalAuctions
totalBiddingValue
totalOrders
}
}
`;
try {
const data = await graphQLClient.request(query);
console.log(data);
} catch (e) {
throw new Error(e);
}
Step 3: Execute The 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:
{
"data": {
"summaries": [
{
"totalAuctions": "41",
"totalBiddingValue": "543157600000000000000000",
"totalOrders": "65"
}
]
}
}
Developer Support
If you have any questions or need help with other use cases, feel free to join the /airstack Warpcast channel and ask your questions there.
Our team is always ready to help you with any questions you may have.