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
tokensAn array of objects representing tokens to be purchased.If no orderIds or rawOrders then required[{ tokenId: 0, contract: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d" }]
orderIdsAn array of order ids to be purchasedIf no tokens or rawOrders then required["0x5c27af06f65deac22abb4307fb68ead818152fee9bc781558be12f8a6a590f97"]
rawOrdersAn array of raw orders to be purchasedIf no tokens or orderIds then required[{ kind: "opensea", data: ... }]
signerA valid signer from ethers.trueRefer to ethers documentation on signers
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-kit-client";
import { ethers } from "ethers";

...

address = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"
signer = new ethers.VoidSigner(address, provider)

getClient()?.actions.buyToken({
  tokens: [{ tokenId: 0, contract: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d" }],
  signer,
  onProgress: (steps: Execute['steps']) => {
    console.log(steps)
  }
})