Crypto Payments
Add cross-chain crypto payments to the embedded checkout
In this guide, you will add crypto payments to the embedded checkout, enabling users to pay for NFTs with cryptocurrency. These payments work cross-chain: for example, users can pay for NFTs on any supported chain with ETH on mainnet or many popular L2s (Base, OP, Arbitrum One, and Arbitrum Nova) or even SOL.
Experience the Flow
You can try out the flow in the app below. You must have some ETH available on the supported test networks to complete the purchase.
You can also preview the live demo in a new tab.
Enabling Cross-Chain Payments
If you already have the embedded NFT checkout configured in your application, adding cross-chain functionality simply requires adding a new signer
property to the CrossmintPayElement
. The guides and documentation here leverages the rainbowkit SDK, but you can find examples for other signers at the end.
The Signer Object
You will pass a signer
object to the CrossmintPayElement
to enable cross-chain payments. Here is an outline of what that object will look like:
Signer Properties
This is the public address of the connected wallet.
This is a custom function that will present the transaction to the user for signing.
Here is an example using the wagmi library:
sendTransactionAsync
function return an object with hash
as a property. In this case you must return result.hash
.This is the string chain name of the currently selected chain. This is important and must be set to match the chain of the connected wallet. This value is used to re-calculate the payment transaction for the newly selected network.
The option set here must match one of the values passed to the supportedChains
property below.
This is an array of string chain names listing the networks you want to be available for selection to the user.
Available chains include:
mainnet: ethereum
, base
, optimism
, arbitrum
testnet: ethereum-sepolia
, base-sepolia
, optimism-sepolia
, arbitrum-sepolia
This is a function you must implement when you’re also using the
supportedChains
property and passing more than a single chain. Add logic
here that will trigger the connected wallet to switch networks to match the
selection the user makes in the Network dropdown.
Examples for Other Signers
The code examples above are using rainbowkit v2.x. If you’re using an older version of rainbowkit and its dependencies (wagmi and viem) you will need to tweak your signAndSendTransaction
function to ensure it returns the txId hash as a string.
embedded-crosschain rainbowkit
Refer to the full repo for complete code examples
The code examples above are using rainbowkit v2.x. If you’re using an older version of rainbowkit and its dependencies (wagmi and viem) you will need to tweak your signAndSendTransaction
function to ensure it returns the txId hash as a string.
embedded-crosschain rainbowkit
Refer to the full repo for complete code examples
embedded-crosschain ethers V5
Refer to the full repo for complete code examples
See below for a step by step walkthrough.
1. Create a new Next.js application
Check out the steps to setup a nextjs application here.
2. Add ethers
to the project
This example is using nextjs with app router. Specify ethers version 5 when installing it.
3. Edit the /app/page.tsx
file
Replace the file contents with the code snippet below.
4. Add a custom hook to initialize ethers
Create a new folder named hooks
in the /app
directory and add a file named useEthersSigner.ts
. Then add the code in the block below.
5. Setup the CrossmintPayElement
in a new file named Crossmint.tsx
The key details here are adding paymentMethod="ETH"
and the signer
property.
emailInputOptions
attribute should be removed when setting up embedded checkout to use cross-chain payments.That’s it! 🎉
Users can now start paying with other cryptocurrencies. You will receive the proceeds in the native currency of the contract, regardless of how the user paid.
Check out the repo: https://github.com/Crossmint/embedded-crosschain-ethers-v5
The example above is based on the simple
branch in this linked repo. The main
branch includes a more complete example with logic to detect minting events and update the UI.
Using an API Signer
Implementing signAndSendTransaction
using a fetch method suggests that you are
interacting with some backend service that will handle the transaction signing
and broadcasting. Here’s a conceptual example of how the implementation might look:
In the above example, you’re making a POST request to the hypothetical /api/sign-and-send-transaction
endpoint on your server.
You need to stringify the transaction object since you are sending it as JSON in the request body.
Your server would handle the signing and sending of the transaction to the blockchain, then respond with the transaction hash.
Was this page helpful?