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({
  chains: [{
    id: 1,
    baseApiUrl: 'https://api.reservoir.tools',
    default: true,
    apiKey: "YOUR_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
chainsAn array of chain objects representing reservoir chains that your application supports. Below we'll breakdown the properties of the chain object.
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.

Let's dive into the properties that make up a reservoir chain:

PropertyDescription
idThe id of the chain (e.g. 1 for mainnet)
baseApiUrlCan be one of our hosted api endpoints or any instance of the Reservoir indexer.
defaultOnly one chain can be the default at a time. This is used in the SDK when determining which default chain to select.
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.

Signers in nodejs (server side)

To create a signer object needed for the SDK actions, you must first configure an OpenZeppelin defender relayer. Once this is done, sending transactions through your relay is as simple as creating a custom signer as follows:

const { DefenderRelaySigner, DefenderRelayProvider } = require('defender-relay-client/lib/ethers');
const { ethers } = require('ethers');

const credentials = { apiKey: YOUR_API_KEY, apiSecret: YOUR_API_SECRET };
const provider = new DefenderRelayProvider(credentials);
const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fast' });

Then you can pass the signer to any of the actions below.

SDK Actions

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.