Quickstart

This guide will get you set up and ready to use the Daimo Pay API within minutes. We'll generate a hosted payment link using the API to accept a payment.

Accept $1 USDC on Optimism

To get started, we'll generate a payment link that will allow us to accept $1 USDC on Optimism. This will be a single-use payment link, allowing a customer to pay in any token on any chain of their choice.

POST
/generate
curl --request POST 'https://pay.daimo.com/api/generate' \
--header 'Idempotency-Key: <A unique idempotency key>' \
--header 'Api-Key: <Your API key>' \
--data-raw '{
  "intent": "Pay Daimoo",
  "items": [
    {
      "name": "Milk",
      "description": "Get milk?",
      "image": "https://picsum.photos/200"
    }
  ],
  "recipient": {
    "address": "<Your address>",
    "amount": "1000000",
    "token": "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
    "chain": 10
  }
}'

The endpoint will return a url that you can redirect the customer to.

{
  "id": "x1vcAo8UducRDN9228Tdr9vECfnAgxmdSNB2v8meSrH",
  "url": "https://pay.daimo.com/checkout?id=x1vcAo8UducRDN9228Tdr9vECfnAgxmdSNB2v8meSrH"
}

Try opening the URL in your browser and fulfilling the payment. Confirm that the recipient address receives the payment in USDC on Optimism within seconds.

Mint an NFT with a Base USDC payment

Next, we'll generate a payment link that will mint a test NFT using a contract that charges $0.10 USDC on Base. The customer will be able to pay in any token on any chain of their choice.

For this example, we've set up a simple NFT mint contract on Base with Zora here that will be the recipient of the payment. The contract has a mint function, so we'll use the callData field in the Daimo Pay API to specify the mint function call that mints the NFT to the customer's address.

First, let's use viem to compute the calldata:

import { encodeFunctionData, parseAbi } from 'viem'

const minterAbi = parseAbi([
  'function mint(address mintTo, uint256 quantity, address tokenAddress, uint256 tokenId, uint256 totalValue, address currency, address mintReferral, string calldata comment)',
])

const callData = encodeFunctionData({
  abi: minterAbi,
  functionName: 'mint',
  args: [
    '<Your address>', // mintTo
    1n, // quantity
    '0x7778488f089ac701c943c3eefef5cb4d7f78deae', // tokenAddress of NFT contract
    1n, // tokenId of our NFT
    100000n, // totalValue (0.1 USDC)
    '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // currency (USDC)
    '0x0000000000000000000000000000000000000000', // mintReferral
    '', // comment
  ],
})

console.log(callData)

Now, we'll use the contract and calldata as the recipient in our request to the /generate endpoint:

const response = await fetch('https://pay.daimo.com/api/generate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Idempotency-Key': '<A unique idempotency key>',
    'Api-Key': '<Your API key>',
  },
  body: JSON.stringify({
    intent: 'Buy NFT',
    items: [
      {
        name: 'Daimo Pay Test NFT',
        description: 'Pay for an NFT with Daimo Pay',
        image: 'https://pay.daimo.com/daimo-pay-logo.svg',
      },
    ],
    recipient: {
      address: '0x777777e8850d8d6d98de2b5f64fae401f96eff31', // NFT contract address
      amount: '100000', // 0.1 USDC
      token: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // Base USDC
      chain: 8453, // Base
      callData,
    },
  }),
})

const data = await response.json()
console.log(data)

We'll get a payment link:

{
  "id": "42vcAo8UducRDN9228Tdr9vECfnAgxmdSNB2v8meSrH",
  "url": "https://pay.daimo.com/checkout?id=42vcAo8UducRDN9228Tdr9vECfnAgxmdSNB2v8meSrH"
}

Try opening the URL in your browser and finishing the checkout. Then, confirm that the NFT is minted to the address specified in the mintTo field in the calldata here.

If all went well, you've now successfully made an arbitrary contract call with a cross-chain cross-token payment using the Daimo Pay API. We're looking forward to seeing what you build next!

Was this page helpful?