Using SDK on backend

The SDK was designed for use on the frontend side. It uses some libraries which usually are available in browser only.
To use the SDK on the server side (backend):

  1. Install dependencies:
yarn add form-data
yarn add node-fetch
  1. Add dependencies to global
global.FormData = require("form-data")
global.window = {
  fetch: require("node-fetch"),
  dispatchEvent: () => {
  },
}
global.CustomEvent = function CustomEvent() {
  return
}
  1. You can check our backend example which buys Ethereum NFT on testnet

Pass private key, node RPC URL, network ID, item ID for buyout and start:

ETH_PRIVATE_KEY="0x..." \
ETHEREUM_RPC_URL="https://goerli.infura.io/..." \
ETHEREUM_NETWORK_ID="4" \
BUYOUT_ITEM_ID="0x1AF7A7555263F275433c6Bb0b8FdCD231F89B1D7:102581254137174039089845694331937600507918590364933200920056519678660477714440" \
ts-node packages/sdk-examples/src/backend/ethereum/buy.ts

Conclusion

Rarible SDK can be used in any javascript-enabled environment including backend. You have to provide implementations for form-data and fetch