preparePurchase

preparePurchase(params)PreparedPurchase

Simulates a purchase to check eligibility and calculate the 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.

A purchase can involve more than one transaction. For example, minting and paying with ERC-20 tokens requires an approval transaction followed by a mint transaction. If you’re building your own front end with the SDK, you may want users to trigger these transactions explicitly (e.g., by clicking separate buttons).

PreparedPurchase returns a list of steps for this purpose. Each step represents an on-chain transaction that can be executed by calling step.execute(). Each execute call performs the necessary on-chain checks to determine whether the transaction is still required; if it isn’t, the step is skipped. Click here to learn more

Example

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

const client = createClient();

const product = await client.getProduct('12311232')
if (product.type !== AppType.Edition) {
	throw new Error(`Unsupported app type`)
}
try {
  const preparedPurchase = await product.preparePurchase<EditionPayload>({
    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}

NOT_ELIGIBLE

wallet not eligible to purchase product

Eligibility

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

Eligibiliy

Field
Type
Description

reason

string

Why not eligible

missingFunds

Missing required funds to purchase (Could be in native ETH or ERC20 tokens)

Last updated