Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 2.13 KB

File metadata and controls

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

📖 For a complete reference of all SDK methods with detailed parameters and return types, see the API Reference.

Installation

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

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.

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.JsonRpcProvider(
  "https://eth-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY",
);

const openseaSDK = new OpenSeaSDK(provider, {
  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.

⚠️ Security Warning: While the SDK supports browser-based providers like window.ethereum, you should never include your API key in client-side code. Exposing your API key in frontend applications allows anyone to extract and abuse it. Instead, use the SDK on a secure backend server and return transaction data to your frontend. See the README Security Warning for the recommended architecture.