Introduction

In this quickstart you’ll learn how to accept multiple different cryptocurrencies as payment using Crossmint’s headless APIs, to purchase an NFT on the polygon-amoy testnet.

Prerequisites

From Crossmint

  1. Create a developer account in the Staging Console.
  2. Create a new collection or import yours into the console, and have your collectionId ready.
    • Make sure you follow the maximum prices for collections set in staging outlined here
  3. Create a server-side API key with the orders.create, orders.update, and orders.read scopes enabled. More info on creating API keys here.

This Quickstart assumes that you'll be using the API Playground or cURL requests to make the API calls. This approach requires the use of a server-side API key.

If you would rather follow the quickstart while building a client-side app that makes requests to Crossmint directly from the browser, you must use a client-side API key. See the Server or Client Guide for more information.

To integrate in production/mainnet, you'll also need to complete account and collection verification. More information in the production launch guide.

If you are choosing to do this quickstart in your own console or IDE, consider you will need to have a way to prompt and sign crypto payments, like using Metamask.

External Prerequisites

  • Your crypto wallet of choice - Metamask, Coinbase Wallet, etc.
  • A small balance of testnet currency in whichever cryptocurrency you would like to pay with

Integration Steps

This quickstart will primarily focus on the API calls necessary to implement headless checkout in your project. You will also need to build out the frontend experience for your users.

1. Create an Order

The first step in the headless checkout process is to create an order. An order is an object datastructure, that represents an intent to purchase in Crossmint's systems. This guide will create a basic order, and then update it with required info step-by-step.

You can also create the entire order in one API call if the necessary information is available at the time of order creation. This can be used for custom "one-click-checkout" experiences, should you wish to make them.

POST https://staging.crossmint.com/api/2022-06-09/orders

Refer to the complete create order API reference here.

{
    "payment": {
        "method": "base-sepolia",
        "currency": "eth",
        "payerAddress": "0xabcd1234..."
    },
    "lineItems": {
        "collectionLocator": "crossmint:<collectionId>",
        "callData": {
            "totalPrice": "0.0001"
        }
    }
}

In the requests above the payerAddress has been included, however if your user has not yet connected their wallet you may omit this field, allow them to connect their wallet after creating the order, and submit the payerAddress at a later time.

For the comprehensive list of supported currencies and chains, view the Supported Currencies page.

At this point you have successfully created an Order in the Crossmint system! The order is currently in the quote phase and is awaiting a recipient to be set. Setting a recipient does not mean that we are sending the NFT to them; it is merely used to verify that the intended recipient is a valid address, before beginning gathering payment info.

Optional - View the Order in the Console

Congratulations! You've made your first contact with Crossmint's systems. You can see your request show up in the developer console. Navigate to the Orders tab for your collection in the Staging Console and enter the orderId returned from your API response to find your incomplete order object and status.

Crossmint Headless NFT Checkout - view order

2. Update the Order with Recipient

Next, you will set who's the intended recipient of the order by specifying a wallet address or email. When a recipient is passed as an email, Crossmint will automatically create a custodial wallet associated with this email, that can be accessed by logging in to the (staging) Crossmint Wallet or from your website if you're using whitelabel wallets.

PATCH https://staging.crossmint.com/api/2022-06-09/orders/<orderId>

Remember to ensure you're using the right type of API key! See the Server or Client Guide for more info.

Refer to the complete edit order API reference here.

{
    "recipient": {
        "email": "test@example.com"
    }
}

Notice you only need to pass the object that your are updating, in this case, recipient. You can also update multiple properties in the same call. Available properties for update include recipient, locale, and the payment object.

If specifying a recipient by wallet address, ensure the address is valid for the chain your collection is on, which may differ from the chain the payment is being performed on.

3. Show Purchase Preview to User

Now, after you’ve told Crossmint systems what you want, and you have passed a valid place to send the NFT, Crossmint will return a quote with prices for the desired items Within the returned response, you’ll find the lineItems array which contains the metadata and a quote for each line item. Within a quote, a detailed breakdown of its charges can be found.

preview purchase screenshot

4. Request Payment from User

You now need to request crypto payment from the user.

You will use the serializedTransaction returned in the purchase preview from the previous step. The serializedTransaction needs to be structured into a transaction object, which can then be passed to a crypto payment prompter, like viem’s sendTransaction or wagmi’s sendTransactionAsync.

Whichever method you use, it should open the user’s default wallet extension in the browser and allow the user to complete the cross-chain payment.

If you’ve followed along this far you can simply paste the serializedTransaction property returned in your previous API call into the app below. This will allow you to sign and send the transaction.

5. Poll for Status Updates

After making the payment via whichever payment method, you'll need to poll the Get Order API to check on the delivery status and present this info to your user.

Refer to the complete get order API reference here.

GET https://staging.crossmint.com/api/2022-06-09/orders/<orderId>

Next Steps

You can now receive payments for anything on the blockchain, and display it in whatever UI you choose to build.

Headless checkout is gated in production. To get started, contact us.