buyToken

This action is used to buy an ERC-1155 or ERC-721 token. You can also use it to buy multiple tokens of the same kind (sweeping).

You can supply an object of parameters listed below:

ParameterDescriptionRequiredExample
itemsAn array of objects representing orders to be purchased. Refer to the the execute buy api for a full list of parameterstrue[{ token: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d:1" }]
signerA valid WalletClient from viem.trueRefer to viem's documentation on Wallet Clients
onProgressCallback to update UI state as execution progresses. Can also be used to get the transaction hash for a given step item.true(steps) => { console.log(steps) }
expectedPriceToken price used to prevent to protect buyer from price moves.false20.5
optionsSupports all of the parameters allowed in the execute buy apifalse{
source: "reservoir.market",
skipBalanceCheck: true
...
}

Example

import { getClient, Execute } from "@reservoir0x/reservoir-sdk";
import { createWalletClient, http } from 'viem'

...

address = "0x8ba1f109551bD432803012645Ac136ddd6000000"
signer = createWalletClient({
  account: address,
  transport: http()
})

getClient()?.actions.buyToken({
  items: [{ token: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d:1", quantity: 1 }],
  signer,
  onProgress: (steps: Execute['steps']) => {
    console.log(steps)
  }
})