The Reservoir client SDK contains helper functions to execute common actions for an NFT marketplace.
Read the @reservoir0x/client-sdk
source code.
To install @reservoir0x/client-sdk, run the following commands in your terminal:
npm install @reservoir0x/client-sdk
or
yarn add @reservoir0x/client-sdk
The actions follow this dataflow:
- An SDK action is called and an Ethereum Signer and a query object are passed as arguments
- The query object is used to construct an HTTP request to the Reservoir API
- The API responds with an array of steps to be completed using the Signer object
- The user is prompted to sign transactions as needed
To buy a token, call buyToken()
. The SDK will make a GET request to /execute/buy/v2
. See an example using buyToken()
on /components/Buy.tsx
To list a token for sale, call listToken()
. The SDK will make a GET request to /execute/list/v2
. See an example using listToken()
on /components/List.tsx
To cancel an order, call cancelOrder()
. The SDK will make a GET request to /execute/cancel/v1
. See an example using cancelOrder()
on /components/Cancel.tsx
To accept an offer, call acceptOffer()
. The SDK will make a GET request to /execute/sell/v2
. See an example using acceptOffer()
on /components/Accept.tsx
To make a single token offer, call placeBid()
. The SDK will make a GET request to /execute/bid/v2
. See an example using placeBid()
on /components/TokenOffer.tsx
To make a collection wide offer, call placeBid()
. The SDK will make a GET request to /execute/bid/v2
. See an example using placeBid()
on /components/CollectionOffer.tsx
To an attribute wide offer, call placeBid()
. The SDK will make a GET request to /execute/bid/v2
. See an example using placeBid()
on /components/AttributeOffer.tsx
To buy multiple tokens, call buyToken()
and make sure to pass the quantity
query param. The SDK will make a GET request to /execute/buy/v2
. See an example using buyToken()
on /components/MultiBuy.tsx
To use the router methods from the Reservoir API without using the SDK you have to handle the steps
array returned by the API. This array contains all the Ethereum transactions that must be signed to execute the action. The executeBuy
function on /components/BuyNoSdk.tsx
is an example of what may be necessary to complete one action from the Router endpoints.