Skip to content

Instantly share code, notes, and snippets.

@metashx
Created October 25, 2021 23:05
Show Gist options
  • Save metashx/4602ff3f8fb03b4aa21aaf3b65c0c130 to your computer and use it in GitHub Desktop.
Save metashx/4602ff3f8fb03b4aa21aaf3b65c0c130 to your computer and use it in GitHub Desktop.
Bulk listing of ERC-1155s to OpenSea

Bulk listing of ERC1155s to OpenSea

Prerequisites

Running script

The default ASSET is set as the Fractional ERC-1155 factory so it will work for all Fractional related ERC-1155s. Override it in your command if you're using a non-Fractional minted ERC-1155.

ALCHEMY_KEY="[redacted]" OPENSEA_KEY="[redacted]" ASSET_ID=1 PRICE="0.03" QUANTITY=1 PRIVATE_KEY="[redacted]" node bulk_list.js

All configurable values:

Variable Description Default
NETWORK The Ethereum network to connect to (Mainnet or Rinkeby) mainnet
ALCHEMY_KEY Free or paid Alchemy API key
OPENSEA_KEY OpenSea API key
ASSET Contract address of the ERC1155 being listed 0xb2469a7dd9e154c97b99b33e88196f7024f2979e
ASSET_ID ID of the ERC115 being listed
QUANTITY Number of listings to make 1
PRICE Price of each listing in ether
PRIVATE_KEY Private key of your Ethereum account

The OpenSea API key is the most limiting factor since obtaining one is so difficult. You can request it [here](https://docs.opensea.io/reference/request-an-api-key) but it will likely take a few weeks if it's even approved.
const HDWalletProvider = require("@truffle/hdwallet-provider");
const opensea = require('opensea-js');
const { WyvernSchemaName } = require('opensea-js/lib/types');
const NETWORK = process.env.NETWORK === 'mainnet' ? 'mainnet' : 'rinkeby';
const ALCHEMY_KEY = process.env.ALCHEMY_KEY;
const OPENSEA_KEY = process.env.OPENSEA_KEY;
// All Fractional ERC1155s are under 0xb246...979e
const ASSET = process.env.ASSET || '0xb2469a7dd9e154c97b99b33e88196f7024f2979e';
const ASSET_ID = process.env.ASSET_ID;
const QUANTITY = process.env.QUANTITY || 1;
const PRICE = process.env.PRICE;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
if (!ALCHEMY_KEY || !OPENSEA_KEY || !ASSET || !PRICE || !PRIVATE_KEY) {
console.error("ALCHEMY_KEY, OPENSEA_KEY, ASSET, PRICE, or PRIVATE_KEY not defined");
return;
}
const provider = new HDWalletProvider({
privateKeys: [PRIVATE_KEY],
providerOrUrl: 'https://eth-' + NETWORK + '.alchemyapi.io/v2/' + ALCHEMY_KEY,
pollingInterval: 8000,
});
const seaport = new opensea.OpenSeaPort(provider, {
networkName: NETWORK === 'mainnet' ? opensea.Network.Main : opensea.Network.Rinkeby,
apiKey: OPENSEA_KEY,
});
(async () => {
console.log("Creating sell order for %s of %s at %s each", QUANTITY, ASSET, PRICE);
for (let i = 0; i < QUANTITY; i++) {
try {
const listing = await seaport.createSellOrder({
asset: {
tokenAddress: ASSET,
tokenId: ASSET_ID,
schemaName: WyvernSchemaName.ERC1155,
},
accountAddress: provider.getAddress(0),
startAmount: parseFloat(PRICE),
quantity: 1,
});
console.log("Listed #%d", i);
} catch (e) {
console.error(e);
}
}
provider.engine.stop();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment