Prerequisite: Setup
The goal of this tutorial is to use the OpenSea SDK to buy and sell NFTs programmatically. Before we get started, you'll need a few things.
Create an OpenSea wallet
Note: if you already have a wallet through a different provider (ex. Metamask), you can export your private key through their preferred method and move on to the next step.
In order to create offers and listings, you'll need a wallet funded with cryptocurrency. Start by going to the OpenSea website and creating an account by clicking the "Login" button in the top right corner. After your account is created, you'll see your new Ethereum address.
After your wallet has been created, add some funds to it. See this OpenSea Help Center article for how to add funds if you aren't sure.
For the rest of this tutorial, you'll need your newly created wallet's private key. Go to "Settings" -> "Export private key", authenticate, and note the key down somewhere safe.
Please do not share your private key with anyone.
Get an OpenSea API Key
You'll need an OpenSea API Key to use our SDK. Follow this guide to get one.
Get an Alchemy API Key
Alchemy provides tools to interact with the Ethereum network and will be our RPC provider for the rest of this tutorial. Go to their website and create an API key for the chain of your choosing.
Download the example code
This Github repo is an example on the basics of using our SDK to buy and sell NFTs. Clone it and cd
into the directory.
git clone [email protected]:ProjectOpenSea/buy-sell-opensea-sdk-demo.git
cd buy-sell-opensea-sdk-demo
Set environment variables
At this point, you should have three things:
- A funded wallet
- An OpenSea API key
- An Alchemy API Key
Set these as environment variables like this:
export OPENSEA_API_KEY='<YOUR_OPENSEA_API_KEY>' &&
export WALLET_PRIV_KEY='<YOUR_WALLET_PRIVATE_KEY>'
&& export ALCHEMY_API_KEY='<YOUR_ALCHEMY_API_KEY>'
Updated 9 months ago
After completing setup, choose whichever of the following guides you're interested in.