Mint Moxie Pass
In this tutorial, you will learn how to mint Moxie Pass to a user wallet by calling the Moxie Pass Mint API.
Pre-requisites
- Install dependencies
graphql
andgraphql-request
to your project :
- npm
- yarn
- pnpm
- bun
npm install graphql graphql-request
yarn add graphql graphql-request
pnpm add graphql graphql-request
bun install graphql graphql graphql-request
- Your will need a special API key to access to the Moxie Pass Mint API. To request access, please fill in this form here.
Step 1: Add The API Query To Your Code
To mint Moxie Pass to user wallet, you can use the following query:
- Query
- Variable
- Response
mutation Mutation($input: FarcasterMintMoxiePassInput!) {
FarcasterMintMoxiePass(input: $input) {
fid
lastSuccessState
status
tokenId
tokenImageUrl
tokenUrl
transactionHash
transactionId
walletAddress
}
}
{
"input": {
// Provide User FID here (optional)
"fid": "0",
// Provide Farcaster verified wallet here
// If wallet is not associated to the given FID, the API will return an error
"preferredConnectedWallet": "0x0000000000000000b600000000000000000000000"
}
}
{
"data": {
"FarcasterMoxieMintStatus": {
"fid": "0",
"lastSuccessState": "minted",
"status": "COMPLETED",
"tokenId": "0",
"tokenImageUrl": "https://d1dmtrbs0t4wod.cloudfront.net/image/0xc7486219881c780b676499868716b27095317416-15971.jpg",
"tokenUrl": "https://d1dmtrbs0t4wod.cloudfront.net/metadata/0xc7486219881c780b676499868716b2709531741615971.json",
"transactionHash": "0x6ce371b5755fcb4f62ab4b629bbe46fba364abd26d695845aa2219f115ad0f77",
"transactionId": "042add97-cca1-443d-b3ae-eeec78712760",
"walletAddress": "0x0000000000000000b600000000000000000000000"
}
}
}
graphql-request
library:- TypeScript
- JavaScript
index.ts
import { gql, GraphQLClient } from "graphql-request";
import { config } from "dotenv";
config();
const graphQLClient = new GraphQLClient(
"https://api.moxie.xyz/protocol/graphql"
);
const query = gql`
mutation Mutation($input: FarcasterMintMoxiePassInput!) {
FarcasterMintMoxiePass(input: $input) {
fid
lastSuccessState
status
tokenId
tokenImageUrl
tokenUrl
transactionHash
transactionId
walletAddress
}
}
`;
const variable = {
"input": {
// Provide User FID here (optional)
"fid": "0",
// Provide Farcaster verified wallet here
// If wallet is not associated to the given FID, the API will return an error
"preferredConnectedWallet": "0x0000000000000000b600000000000000000000000"
}
}
const headers = {
// Add Airstack API key here
"x-airstack-protocol": process.env.AIRSTACK_API_KEY as string,
}
try {
const data = await graphQLClient.request(query, variable, headers);
console.log(data);
} catch (e) {
throw new Error(e);
}
index.js
const { gql, GraphQLClient } = require("graphql-request");
const { config } = require("dotenv");
config();
const graphQLClient = new GraphQLClient(
"https://api.moxie.xyz/protocol/graphql"
);
const query = gql`
mutation Mutation($input: FarcasterMintMoxiePassInput!) {
FarcasterMintMoxiePass(input: $input) {
fid
lastSuccessState
status
tokenId
tokenImageUrl
tokenUrl
transactionHash
transactionId
walletAddress
}
}
`;
const variable = {
"input": {
// Provide User FID here (optional)
"fid": "0",
// Provide Farcaster verified wallet here
// If wallet is not associated to the given FID, the API will return an error
"preferredConnectedWallet": "0x0000000000000000b600000000000000000000000"
}
}
const headers = {
// Add Airstack API key here
"x-airstack-protocol": process.env.AIRSTACK_API_KEY as string,
}
try {
const data = await graphQLClient.request(query, variable, headers);
console.log(data);
} catch (e) {
throw new Error(e);
}
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:
{
"data": {
"FarcasterMoxieMintStatus": {
"fid": "0",
"lastSuccessState": "minted",
"status": "COMPLETED",
"tokenId": "0",
"tokenImageUrl": "https://d1dmtrbs0t4wod.cloudfront.net/image/0xc7486219881c780b676499868716b27095317416-15971.jpg",
"tokenUrl": "https://d1dmtrbs0t4wod.cloudfront.net/metadata/0xc7486219881c780b676499868716b2709531741615971.json",
"transactionHash": "0x6ce371b5755fcb4f62ab4b629bbe46fba364abd26d695845aa2219f115ad0f77",
"transactionId": "042add97-cca1-443d-b3ae-eeec78712760",
"walletAddress": "0x0000000000000000b600000000000000000000000"
}
}
}
Congrats! 🥳🎉 You've just successfully minted a Moxie Pass for your user!
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.