Skip to main content

Mint Moxie Pass

In this tutorial, you will learn how to mint Moxie Pass to a user wallet by calling the Moxie Partner API.

Pre-requisites

  1. Install dependencies graphqlandgraphql-request to your project :
npm install graphql graphql-request
  1. Your will need a special API key to access to the Moxie Partner 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:

mutation Mutation($input: FarcasterMintMoxiePassInput!) {
FarcasterMintMoxiePass(input: $input) {
fid
lastSuccessState
status
tokenId
tokenImageUrl
tokenUrl
transactionHash
transactionId
walletAddress
}
}
With this GraphQL query, you can add it to your source code and call the API with the graphql-request library:
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);
}

Step 2: Execute Your Code

Once you have your code ready, you can execute it by running the following command:

ts-node index.ts

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.