preparePurchase

preparePurchase(params)PreparedPurchase

Simulates purchase to check eligibility and get total cost.

Parameters

Parameter
Type
Required
Description

userAddress

string

The address making the purchase

recipientAddress

string

If different than address

networkId

number

If specify, forced transaction on the network (handle funds bridging automatically), assume product network otherwise

payload

{quantity: number}

Specific to Edition Products. Specify quantity of purchase

gasBuffer

object

How much additional gas to spend on the purchase

gasBuffer.fixed

BigInt

Fixed gas buffer amount

gasBuffer.multipller

number

Gas buffer by multiplier.

The multiplier represents a percentage (as a number out of 100). For example:

  • multiplier: 120 means 120% of the original estimate (20% increase)

  • multiplier: 150 means 150% of the original estimate (50% increase)

account

If provided, it will perform balance checks on the specified account; otherwise, it will skip balance checks.

Example

import { createClient, type AppType, isBlindMintProduct } from '@manifoldxyz/client-sdk'

const client = createClient();

const product = await client.getProduct('12311232')
if (!isBlindMintProduct(product)) {
  throw new Error(`Unsupported app type`)
}
try {
  const preparedPurchase = await product.preparePurchase({
    userAddress: '0x....', // the connected wallet
    payload: {
      quantity: 1
    },
    gasBuffer: {
     multiplier: 0.25 // 25% gas buffer
    }
  });
} catch (error: ClientSDKError) {
  console.log(`Error: ${error.message}`)
  return
}

console.log('Total cost:', simulation.totalCost.formatted);

Errors

Code
Message
data

INVALID_INPUT

invalid input

UNSUPPORTED_NETWORK

unsupported networkId ${networkId}

SOLD_OUT

product sold out

LIMIT_REACHED

you've reached your purchase limit

ENDED

ended

NOT_STARTED

not started, come back later

ESTIMATION_FAILED

transaction estimation failed

Last updated