Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

reservoirprotocol/router-demo

Repository files navigation

The router demo is still functional but has been deprecated in favor of our sandbox demos and docs

router-demo

The Reservoir client SDK contains helper functions to execute common actions for an NFT marketplace.

Read the @reservoir0x/client-sdk source code.

Install

To install @reservoir0x/client-sdk, run the following commands in your terminal:

npm install @reservoir0x/client-sdk

or

yarn add @reservoir0x/client-sdk

Tutorial

The actions follow this dataflow:

  1. An SDK action is called and an Ethereum Signer and a query object are passed as arguments
  2. The query object is used to construct an HTTP request to the Reservoir API
  3. The API responds with an array of steps to be completed using the Signer object
  4. The user is prompted to sign transactions as needed

Buy a token

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

List for sale

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

Cancel an order

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

Accept an offer

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

Make a single token offer

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

Make a collection wide offer

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

Make an attribute wide offer

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

Buy multiple tokens

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

Buy a token without using the Reservoir Client SDK

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.