Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 1.73 KB

quick-start.md

File metadata and controls

60 lines (43 loc) · 1.73 KB
title category slug parentDocSlug order hidden
Quick Start Guide
64cbb5277b5f3c0065d96616
opensea-sdk-quick-start
opensea-sdk
0
false

Installation

Node.js version 16 is the minimum required for the SDK. If you have Node Version Manager (nvm), run nvm use 16.

Then in your project, run:

npm install --save opensea-js
# or
yarn add opensea-js

Initialization

To get started, first request an API key. Note the terms of use for using API data. API keys are not needed for testnets.

Then, create a new OpenSeaSDK client using your web3 provider:

import { ethers } from "ethers";
import { OpenSeaSDK, Chain } from "opensea-js";

// This example provider won't let you make transactions, only read-only calls:
const provider = new ethers.providers.JsonRpcProvider(
  "https://mainnet.infura.io",
);

const openseaSDK = new OpenSeaSDK(walletWithProvider, {
  chain: Chain.Mainnet,
  apiKey: YOUR_API_KEY,
});

Wallet

Using the example provider above won't let you authorize transactions, which are needed when approving and trading assets and currency. To make transactions, you need a provider with a private key or mnemonic set:

const walletWithProvider = new ethers.Wallet(PRIVATE_KEY, provider);

const openseaSDK = new OpenSeaSDK(walletWithProvider, {
  chain: Chain.Mainnet,
  apiKey: YOUR_API_KEY,
});

In a browser with web3 or an extension like MetaMask or Coinbase Wallet, you can use window.ethereum to access the native provider.

Testnets

For testnets, please use Chain.Goerli or Chain.Sepolia. Rinkeby was deprecated in 2022, and Goerli will be deprecated by January 2024.