Guides
Listing on OpenSea
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
, andopensea-js
libraries
Setup
-
Install Dependencies
First, install the OpenSea SDK
npm i opensea-js
-
Create a
.env
filePROD_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:
ethers v6
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();
// Configuration
const stardustAPIKey = process.env.PROD_SYSTEM_STARDUST_API_KEY!;
const profileId = process.env.PROD_SYSTEM_STARDUST_PROFILE_ID!;
async function main() {
// Initialize Provider
const provider = getDefaultProvider('matic');
// Initialize Stardust SDK
const sdk = new StardustCustodialSDK(stardustAPIKey);
// Get Wallet
const profile = await sdk.getProfile(profileId);
const { wallet } = profile;
// Get V6 Signer
const signer: ethers.Signer & {address?: string} = wallet.ethers.v6.getSigner(provider);
//! OpenSea SDK expects signer to have address as a property
signer.address = await signer.getAddress();
// Instantiate OpenSeaSDK with a stardust signer
const openseaSDK = new OpenSeaSDK(signer, {
chain: Chain.Polygon,
apiKey: process.env.OPENSEA_API_KEY,
});
// Dummy values, replace with actual values.
const tokenId = '1';
const tokenAddress = '0x0Eccb65C249c019289505093F28555e8339E1e64';
const accountAddress = '0xd6dCA30fd4061e16683B62ac21c1c69734eE2eB3';
// Expire this auction one day from now.
// Note that we convert from the JavaScript timestamp (milliseconds) to seconds:
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();
Was this page helpful?