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.
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. For client-side usage, you don't need the orders.read scope - use the clientSecret from order creation for subsequent operations.
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.
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.
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.
POSThttps://staging.crossmint.com/api/2022-06-09/ordersRefer to the complete create order API reference here.
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.
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.
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.PATCHhttps://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.
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.
Notice at the bottom, the new serializedTransaction property. This is a unique identifier let’s Crossmint know exactly which order you are updating.
Anytime you update an order you must use the returned serializedTransaction property.
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 Screenshot
Code Example
lineItems Example
If you are developing in an IDE or in terminal, the returned lineitems may be stuck in an [Object], or be in a
hard-to-understand object format. You can make this human-readable for yourself by adding JSON.stringify(response)
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.
Send EVM Payment
Send Solana Payment
Code Example
Full Repository Example
Ensure your wallet is connected to the devnet network, otherwise your funds may be lost!
Copy
Ask AI
"use client";import { ConnectButton } from "@rainbow-me/rainbowkit";import { useState } from "react";import { parseTransaction } from "viem"; // Refer to their documentation details to make viem work for your needsimport { useSendTransaction } from "wagmi"; // Refer to their documentation details to make wagmi work for your needsexport default function Home() { const { data: hash, isPending, sendTransactionAsync } = useSendTransaction(); const signAndSendTransaction = async () => { const serializedTxn = "0x_your_serialized_transaction_response"; const txn = parseTransaction(serializedTxn || "0x"); await sendTransactionAsync({ to: txn.to as `0x${string}`, value: BigInt(txn.value ? txn.value.toString() : "0"), data: txn.data as `0x${string}`, chainId: txn.chainId, }); }; return <button onClick={() => signAndSendTransaction()}>Send Transaction</button>;}
For a deeper example, refer to the repository linked below, which is the exact code running in the App tab.
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.GEThttps://staging.crossmint.com/api/2022-06-09/orders/<orderId>
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.