Reservoir SDK (JS/TS/Node)

Reservoir SDK

The Reservoir SDK is the underlying package that ReservoirKit UI uses behind the scenes to execute core functionality (listing, bidding, buying and selling). The Reservoir SDK can be used if you are using another javascript framework, executing orders via a Nodejs server or building a custom experience.

If you're using ReservoirKit UI then you're already using the sdk, and you have access to the useReservoirClient hook to retrieve the sdk in a react context and use it. If you aren't using the UI package then you'll need to follow these steps to get the sdk up and running.

Installing Reservoir SDK:

yarn add @reservoir0x/reservoir-sdk

The Reservoir SDK also requires ethers to be installed, make sure that's added to your package.json if it isn't already.

yarn add ethers

Configuring the Reservoir SDK

To configure the SDK we first need to create a global instance of it:

import { createClient } from "@reservoir0x/reservoir-sdk"

createClient({
  apiBase: "https://api.reservoir.tools",
  apiKey: "YOUR_API_KEY",
  source: "YOUR.SOURCE
});

We start by importing the createClient function and then calling that function to create a global client, passing in the required parameters.

OptionDescription
apiBaseThe apiBase can be one of our hosted api endpoints or any instance of the Reservoir indexer. This is a required option.
apiKeyThe apiKey is not required but should be passed in as it allows for higher rate limits. Read more about the API Keys & Rate Limits and how to instantly generate one.
sourceThe source parameter can be any valid domain (e.g. reservoir.market). It's used to attribute orders to your particular marketplace and to scrape custom metadata from your marketplace.
marketplaceFeeFee in bps included when creating an order (listing & bidding). Only relevant for native orders.
marketplaceFeeRecipientThe recipient address to receive the marketplaceFee
automatedRoyaltiesIf true, royalties will be automatically included, defaults to true. Only relevant for creating orders (listing and bidding)
normalizeRoyaltiesGlobal setting to add royalties on top of orders that do not include royalties.

Once the client has been created there are 5 core actions available to you:

buyToken
listToken
placeBid
acceptOffer
cancelOrder

👍

Nice!

Now that the Reservoir SDK is up and running lets add sweeping to our javascript application.