This guide describes listing an NFT on the OpenSea exchange with the Stardust API/SDK, OpenSea API/SDK, and the ethers
library. Follow the OpenSeaSDK Docs to perform operations other than creating a listing.
Prerequisites
- Node.js installed on your system
- Stardust API key and wallet Id or profile Id
- OpenSea API Key
dotenv
, ethers v6
, and opensea-js
libraries
Setup
-
Install Dependencies
First, install the OpenSea SDK
-
Create a .env
file
PROD_SYSTEM_STARDUST_API_KEY=your_stardust_api_key
OPENSEA_API_KEY=your_opensea_api_key
Code Example
Create a listing on OpenSeaSDK
with a Stardust wallet:
import dotenv from 'dotenv';
import { ethers, getDefaultProvider } from 'ethers_v6';
import { StardustCustodialSDK } from '@stardust-gg/stardust-custodial-sdk';
import { OpenSeaSDK, Chain } from "opensea-js";
dotenv.config();
const stardustAPIKey = process.env.PROD_SYSTEM_STARDUST_API_KEY!;
const profileId = process.env.PROD_SYSTEM_STARDUST_PROFILE_ID!;
async function main() {
const provider = getDefaultProvider('matic');
const sdk = new StardustCustodialSDK(stardustAPIKey);
const profile = await sdk.getProfile(profileId);
const { wallet } = profile;
const signer: ethers.Signer & {address?: string} = wallet.ethers.v6.getSigner(provider);
signer.address = await signer.getAddress();
const openseaSDK = new OpenSeaSDK(signer, {
chain: Chain.Polygon,
apiKey: process.env.OPENSEA_API_KEY,
});
const tokenId = '1';
const tokenAddress = '0x0Eccb65C249c019289505093F28555e8339E1e64';
const accountAddress = '0xd6dCA30fd4061e16683B62ac21c1c69734eE2eB3';
const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24);
const listing = await openseaSDK.createListing({
asset: {
tokenId,
tokenAddress,
},
accountAddress,
startAmount: 3,
expirationTime,
});
console.log(`Successfully created OpenSea listing: ${listing}`)
}
main();