Prerequisites

API Key with correct scope

Refer to the Create an API Key Guide and the API Keys page for more information.

Ensure your API Key has the nfts.create scope enabled.

Complete API Reference Introduction

Follow the API Playground Guide to setup authentication, create a user wallet, and mint an NFT to it using the API Playground.

Mint an NFT

If you followed the API Playground Guide in the prerequisites you already minted an NFT right here in the browser. This next section will show you how to mint an NFT using the API directly with javascript.

1

Copy the javascript code below:

Save to a file on your local machine named: mint-nft.js.

mint-nft.js
const url =
  "https://staging.crossmint.com/api/2022-06-09/collections/default-polygon/nfts";
const options = {
  method: "POST",
  headers: {
    accept: "application/json",
    "content-type": "application/json",
    "x-api-key": "YOUR_API_KEY",
  },
  body: JSON.stringify({
    recipient: "email:YOUR_EMAIL_ADDRESS:polygon",
    metadata: {
      name: "Crossmint Test NFT",
      image:
        "https://bafkreiexjl6kw4khdxkrt6dojgacscnzvrys47t472l2t7d6r2ss65kifq.ipfs.nftstorage.link/",
      description: "Created with the Crossmint minting API",
    },
  }),
};

fetch(url, options)
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch((err) => console.error("error:" + err));
2

Edit file to include your API key:

Change the YOUR_API_KEY value to your API key.

You should also adjust the YOUR_EMAIL_ADDRESS value to your email address so you can login to see the NFT at https://staging.crossmint.com/user/collection when completed.

3

Run the file from your terminal

node mint-nft.js

You should get a response like this:

{
  "id": "7402007c-4e30-4fba-a769-60e7b513086e",
  "onChain": {
    "status": "pending",
    "chain": "polygon",
    "contractAddress": "0x67a602CBb306b3DBaaC7ECf55b72EED0E04Dc785"
  },
  "actionId": "7402007c-4e30-4fba-a769-60e7b513086e"
}

Take note of the id returned as it is used in the next step to retrieve the status of the minting.

4

Get mint status

Create another file in the same directory as above named get-mint-status.js and copy the following code into it:

get-mint-status.js
const options = {
  method: 'GET',
  headers: {
    "x-api-key": "YOUR_API_KEY",
  }
};

fetch('https://staging.crossmint.com/api/2022-06-09/collections/default-polygon/nfts/7402007c-4e30-4fba-a769-60e7b513086e', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Once again, ensure you replace the YOUR_API_KEY value with your API key.

5

Run the file from your terminal

node get-mint-status.js

You should get a response like this:

{
    "id": "7402007c-4e30-4fba-a769-60e7b513086e",
    "metadata":
    {
        "name": "Crossmint Test NFT",
        "image": "ipfs://QmVhAkiT3XCPQUaZKHootfEfixmKVqSiq5Y7uVPZyFGQXw",
        "description": "Created with the Crossmint minting API"
    },
    "onChain":
    {
        "status": "success",
        "tokenId": "5",
        "owner": "0x0359Cd99FD20e853a85489DFC93EaDFeF7461590",
        "txId": "0x730e92a62ae53393ffc9ce743e0e738ccb92b74331570dd5333556222ed47b22",
        "contractAddress": "0x67a602CBb306b3DBaaC7ECf55b72EED0E04Dc785",
        "chain": "polygon"
    },
    "action": "https://staging.crossmint.com/api/2022-06-09/actions/7402007c-4e30-4fba-a769-60e7b513086e"
}
6

View the NFT

Visit https://staging.crossmint.com/user/collection and login with the email address you used in the first step.

You should see your NFT in the collection.

You can also take the txId returned in the response and find your transaction on the block explorer. This example uses Polygon’s Mumbai testnet. Simply enter the transaction id in the search bar and you should see your NFT transaction.

Ready for More?

Explore the API reference to learn more about the NFT minting APIs. Be sure to checkout the API Playground Guide to get comfortable testing the APIs out right in your browser.