Code samples

Questions? Contact us at www.crossmint.io/support

📘

Want to run code in a live playground environment?

Visit our API Reference, paste your Project ID and API Secret, and run live API calls directly from the browser!

Mint an NFT

curl --location --request POST 
'https://www.crossmint.io/api/2022-06-09/collections/{collectionName}/nfts' \
    --header 'x-client-secret: <API SECRET>' \
    --header 'x-project-id: <PROJECT ID>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "metadata": {
            "name": "Crossmint Mint API Test",
            "image": "https://www.crossmint.io/assets/crossmint/logo.png",
            "description": "Test NFT created by the Crossmint Minting API"
        },
        "recipient": "polygon:0x12618f45ff6e841470bf71f428aae41ee5bc3c39"
    }'
const reqHeader = new Headers();
reqHeader.append("x-client-secret", "<API SECRET>");
reqHeader.append("x-project-id", "<PROJECT ID>");
reqHeader.append("Content-Type", "application/json");

const collectionName = "default" // change if you've created a collection
const recipient = "poly:0x12618f45ff6e841470bf71f428aae41ee5bc3c39"
// Or with just an email:
// const recipient = "email:[email protected]:polygon"

const reqBody = JSON.stringify({
  "metadata": {
    "name": "Crossmint Mint API Test",
    "image": "https://www.crossmint.io/assets/crossmint/logo.png",
    "description": "Test NFT created by the Crossmint Minting API"
  },
  "recipient": recipient
});

var requestOptions = {
  method: 'POST',
  headers: reqHeader,
  body: reqBody,
  redirect: 'follow'
};

fetch(`https://www.crossmint.io/api/2022-06-09/collections/${collectionName}/nfts`, requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Check the minting status

Minting an NFT may take a few seconds. You can check its status based on a request ID obtained during minting.

curl --location --request GET 'https://www.crossmint.io/api/2022-06-09/collections/{collectionName}/nfts/{id}\
    --header 'x-client-secret: <API SECRET>' \
    --header 'x-project-id: <PROJECT ID>'
const reqHeader = new Headers();
reqHeader.append("x-client-secret", "<API SECRET>");
reqHeader.append("x-project-id", "<PROJECT ID>");

const collectionName = "default" // change if you've created a collection
const id = "" // id returned in response from previous mint step

const requestOptions = {
  method: 'GET',
  headers: reqHeader,
  redirect: 'follow'
};

fetch(`https://www.crossmint.io/api/2022-06-09/collections/${collectionName}/nfts/${id}`, requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));