Last active
July 18, 2022 07:13
-
-
Save emo-eth/348bb303e3eb98bd0218d0cbc1c461b2 to your computer and use it in GitHub Desktop.
example script to list an 1155 token on opensea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "fs"; | |
import * as dotenv from "dotenv"; | |
import { OpenSeaPort, Network } from "opensea-js"; | |
dotenv.config(); | |
const HDWalletProvider = require("@truffle/hdwallet-provider"); | |
const mnemonic = fs.readFileSync(".mnemonic").toString().trim(); | |
const ETH_RPC_URL = process.env.ETH_RPC_URL; | |
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS || ""; | |
const OWNER_ADDRESS = process.env.OWNER_ADDRESS; | |
const NETWORK = process.env.NETWORK; | |
const TOKEN_ID = process.env.FACTORY_OPTION_ID || ""; | |
const OPENSEA_API_KEY = process.env.OPENSEA_API_KEY; | |
if (!CONTRACT_ADDRESS) { | |
console.error("Please specify a contract address."); | |
} | |
const provider = new HDWalletProvider(mnemonic, ETH_RPC_URL); | |
const seaport = new OpenSeaPort( | |
provider, | |
{ | |
networkName: | |
NETWORK === "mainnet" || NETWORK === "live" | |
? Network.Main | |
: Network.Rinkeby, | |
apiKey: OPENSEA_API_KEY, | |
}, | |
(arg: string) => console.log(arg) | |
); | |
async function main(): Promise<any> { | |
const OpenSeaAsset = await seaport.api.getAsset({ | |
tokenAddress: CONTRACT_ADDRESS, | |
tokenId: TOKEN_ID, | |
}); | |
console.log(OpenSeaAsset); | |
// list in 10 seconds | |
const listingTime = Math.round(Date.now() / 1000) + 10; | |
// expires in 24 hours | |
const expirationTime = listingTime + 60 * 60 * 24; | |
const orderArgs = { | |
asset: { ...OpenSeaAsset, schemaName: "ERC1155" }, | |
OWNER_ADDRESS, | |
startAmount: 1.2, | |
listingTime, | |
expirationTime, | |
}; | |
const listing = await seaport.createSellOrder(orderArgs); | |
console.log(listing); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment