Skip to content

Instantly share code, notes, and snippets.

@0xlxy
Created September 13, 2022 02:04
Show Gist options
  • Save 0xlxy/c528d111a554d2c340b4885a2e538311 to your computer and use it in GitHub Desktop.
Save 0xlxy/c528d111a554d2c340b4885a2e538311 to your computer and use it in GitHub Desktop.
PoC for NFT instant sell on Opensea
// if type module -> cannot use reqiure, need import
// In package.json: "type": "module",
import { OpenSeaSDK, Network } from "opensea-js";
import HDWalletProvider from "@truffle/hdwallet-provider";
import { config } from 'dotenv';
config();
const WALLET_PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY
const OPENSEA_API_KEY = process.env.OPENSEA_API_KEY
const RPC_URL = process.env.RPC_URL
const provider = new HDWalletProvider(
WALLET_PRIVATE_KEY, RPC_URL
);
const openseaSDK = new OpenSeaSDK(provider, {
networkName: Network.Main,
apiKey: OPENSEA_API_KEY,
});
const assetContractAddress = "0x3A112D86899578E63b373B6D09322E18Aed924Cb"
const tokenIds = "3786"
const accountAddress = "0xe3abCD85AA20279297ae52552758D6C4878c5d0C"
// Approve to Seaport: 0x1E0049783F008A0085193E00003D00cd54003c71
async function sellOrder(assetContractAddress, tokenIds, accountAddress) {
const order = await openseaSDK.api.getOrder({
side: "bid",
protocol: "seaport",
assetContractAddress: assetContractAddress,
tokenIds: tokenIds,
});
console.log(order)
console.log("start selling")
const res = await openseaSDK.fulfillOrder({ order, accountAddress });
console.log(res)
console.log("selling succeeded")
}
sellOrder(assetContractAddress, tokenIds, accountAddress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment