Skip to main content

Import

import { useCreditCardCheckoutModal } from '@0xsequence/checkout'

Usage

import { useCreditCardCheckoutModal } from '@0xsequence/checkout'
import { polygon } from 'viem/chains'
import { useAccount } from 'wagmi'

function Home() {
  const { address } = useAccount()
  const { initiateCreditCardCheckout, closeCreditCardCheckout, settings } = useCheckoutModal()

  const handleCheckout = () => {
    // NFT purchase settings
    const chainId = polygon.id
    const orderbookAddress = '0xfdb42A198a932C8D3B506Ffa5e855bC4b348a712'
    const nftQuantity = '1'
    const tokenContractAddress = '0xabcdef...' // NFT contract address
    const tokenId = '123' // NFT token ID

    initiateCreditCardCheckout({
      chainId,
      contractAddress: orderbookAddress,
      recipientAddress: address || '',
      currencyQuantity: '100000',
      currencySymbol: 'USDC',
      currencyAddress: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
      currencyDecimals: '6',
      nftId: tokenId,
      nftAddress: tokenContractAddress,
      nftQuantity,
      approvedSpenderAddress: orderbookAddress,
      calldata: "0x...",
      onSuccess: (txHash) => console.log('Success!', txHash)
    })
  }

  return (
    <button onClick={handleCheckout}>
      Checkout
    </button>
  )
}

export default Home

Properties

initiateCreditCardCheckout

(settings: CreditCardCheckoutSettings) => void Opens the Credit Card Checkout modal with the specified parameters. Parameters: The settings object can include the following properties:
ParameterTypeDescription
chainIdnumberThe blockchain network ID
contractAddressstringThe address of the contract to interact with
recipientAddressstringThe address to receive the purchased item
currencyQuantitystringThe quantity of currency to use for payment
currencySymbolstringThe symbol of the currency (e.g., ‘USDC’)
currencyAddressstringThe address of the currency token contract
currencyDecimalsstringThe number of decimals for the currency
nftIdstringThe ID of the NFT being purchased
nftAddressstringThe address of the NFT contract
nftQuantitystringThe quantity of NFTs to purchase
approvedSpenderAddressstringThe address allowed to spend tokens
calldatastringThe encoded function call data for the transaction
onSuccess(txHash: string) => voidCallback when transaction succeeds

closeCreditCardCheckout

() => void Closes the Credit Card Checkout modal.

settings

CreditCardCheckoutSettings | undefined The current settings configuration for the Credit Card Checkout modal.

Notes

This hook provides methods to control the Credit Card Checkout modal that allows users to complete purchases using a credit card.