ProjectOpenSea / seaport-js

A TypeScript library to interface with the Seaport marketplace.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue creating a listing.

FiveNine opened this issue · comments

There were barely any examples of creating a listing in the docs for this; so i've been scraping code off of some issues here. I cant figure out what to do next to create a listing. It looks like infura api is getting requests but no listing is created on testnet opensea.

All Im trying to do is create a listing for a testnet NFT. Any help appreciated :)

const { Seaport } = require('@opensea/seaport-js');
const { ethers } = require('ethers');

// Provider must be provided to the signer when supplying a custom signer
const provider = new ethers.providers.JsonRpcProvider(
  "https://goerli.infura.io/v3/<API_KEY>"
);
const privateKey = "";
const signer = new ethers.Wallet("privateKey", provider);

const seaport = new Seaport(signer);

const main = async () => {
    const offerer = "0x096483d4AdDD6ccB428D81400483D503DaE2e505";
    const { executeAllActions } = await seaport.createOrder(
        {
            offerer: offerer,
            zone: "0x0000000000000000000000000000000000000000",
            zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
            startTime: Math.floor(new Date().getTime() / 1000).toString(),
            endTime: Math.floor(new Date().getTime() / 1000 + 60 * 60).toString(),
            offer: [
                {
                    itemType: 2,
                    token: "0xd08d514c3a6f4625a3546a9dff43c8e27a5cd00a",
                    identifier: "18",
                },
            ],
            consideration: [
                {
                    amount: ethers.utils.parseEther("0.0002").toString(),
                    recipient: offerer,
                },
            ],
            orderType: 1,
        },
        offerer
    );

    const order = await executeAllActions();
    console.log(order);
}
main();

Current output:

{
  parameters: {
    offerer: '0x096483d4AdDD6ccB428D81400483D503DaE2e505',
    zone: '0x0000000000000000000000000000000000000000',
    zoneHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
    startTime: '1686777408',
    endTime: '1686781008',
    orderType: 0,
    offer: [ [Object] ],
    consideration: [ [Object] ],
    totalOriginalConsiderationItems: 1,
    salt: '0x000000000000000000000000000000000000000000000000aaea3fd9cdfbc111',
    conduitKey: '0x0000000000000000000000000000000000000000000000000000000000000000',
    counter: '0'
  },
  signature: '0x37a68eca15edf5c5978501417f29f6d09651b3439d8ddc77b9ea1d30cbf5de6e14541f29947aad6c31d5d9c030515f76c00d6ca7f85cae1597a4bed679e'
}

you have to call validate() if you want it to list it on chain, otherwise use opensea-js and create a self serve API key to submit it to opensea without an on chain tx

you have to call validate() if you want it to list it on chain,

validate like so?

   const validated = seaport.validate([order]);
   const transaction = await validated.transact();
   console.log('validated: ', await transaction.wait());

I've tried this before but i get this result

validated:  {
 to: '0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC',
 from: '0x096483d4AdDD6ccB428D81400483D503DaE2e505',
 contractAddress: null,
 transactionIndex: 124,
 gasUsed: BigNumber { _hex: '0x0101d6', _isBigNumber: true },
 logsBloom: '0x00000000400008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000100000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
 blockHash: '0x1df56ecd9a27c6481c0869ca42630aff1a4b7dfc53be535f24453fa1341e',
 transactionHash: '0xc8cfdf17d4f13a39915b205d0fe8230668c85c12a3181fddc8ee92fe6c625',
 logs: [
   {
     transactionIndex: 124,
     blockNumber: 9179549,
     transactionHash: '0xc8cfdf17d4f13a39915b205df0b0fe8230668c85c12a3181fde92fe6c625',
     address: '0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC',
     topics: [Array],
     data: '0xff7daa4ff4a7398384e15824bc924a048a0b3168910e4156e428e848e6a2816800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000964b428d81400483d503dae2e505000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000648a399d00000000000000000000000000000000000000000000000000000000648a47ad00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009e27946a922795c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d08d514c3a6f4625a3546a9dff43c8e27a5cd00a00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b5e620f480000000000000000000000000000000000000000000000000000000b5e620f48000000000000000000000000000096483d4addd6ccb428d81400483d503dae2e505',
     logIndex: 220,
     blockHash: '0x1df56ecd9a27c6481c0869ca42630aff1252ea4b7dfc53be535f24453fa1341e'
   }
 ],
 blockNumber: 9179549,
 confirmations: 1,
 cumulativeGasUsed: BigNumber { _hex: '0xc947b8', _isBigNumber: true },
 effectiveGasPrice: BigNumber { _hex: '0x5e60db4b', _isBigNumber: true },
 status: 1,
 type: 2,
 byzantium: true
}

thanks, yeah looks good but i found the error on our backend:

You provided an invalid conduit key: 0x0000000000000000000000000000000000000000000000000000000000000000, please use OpenSea's conduit key: 0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000 for order placement

so you'll want to approve the conduit for that contract from your account too before you send the validate()

the conduit address is 0x1e0049783f008a0085193e00003d00cd54003c71

I'm not sure I understand what you mean by that. Sorry kinda new to this, could you elaborate on that a bit?
how would i go about doing that?

no prob

  1. on your token contract from your offerer address call setApprovalForAll with operator= 0x1e0049783f008a0085193e00003d00cd54003c71
  2. set the conduitKey in your order to 0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000

im not sure if i did it right but it still didnt show up on opensea hmmm

    const conduitAddress = "0x1e0049783f008a0085193e00003d00cd54003c71";
    const conduitKey = "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000";

    const tokenContractAddress = "0xd08d514c3a6f4625a3546a9dff43c8e27a5cd00a";
    const tokenContract = new ethers.Contract(tokenContractAddress, contractABI, signer);
    await tokenContract.setApprovalForAll(conduitAddress, true);

    const { executeAllActions } = await seaport.createOrder(
        {
            offerer: offerer,
            zone: "0x0000000000000000000000000000000000000000",
            zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
            startTime: Math.floor(new Date().getTime() / 1000).toString(),
            endTime: Math.floor(new Date().getTime() / 1000 + 60 * 60).toString(),
            offer: [
                {
                    itemType: 2,
                    token: "0xd08d514c3a6f4625a3546a9dff43c8e27a5cd00a",
                    identifier: "18",
                },
            ],
            consideration: [
                {
                    amount: ethers.utils.parseEther("0.0002").toString(),
                    recipient: offerer,
                },
            ],
            orderType: 1,
            conduitKey: conduitKey
        },
        offerer
    );

output if that helps:

{
 parameters: {
   offerer: '0x096483d4AdDD6ccB428D81400483D503DaE2e505',
   zone: '0x0000000000000000000000000000000000000000',
   zoneHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
   startTime: '1686781877',
   endTime: '1686785477',
   orderType: 0,
   offer: [ [Object] ],
   consideration: [ [Object] ],
   totalOriginalConsiderationItems: 1,
   salt: '0x0000000000000000000000000000000000000000000000002c2b1798d6bcac9c',
   conduitKey: '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000',
   counter: '0'
 },
 signature: '0xfc4e861fe863024905b1ddd7c48753bb0d42654b8b434ee5bb4dc0ba643a56c4a3e1afcd39d2c8977535e3aff21116992d94a9bd2f95828738622b8e59fb10c5'
}
validated:  {
 to: '0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC',
 from: '0x096483d4AdDD6ccB428D81400483D503DaE2e505',
 contractAddress: null,
 transactionIndex: 7,
 gasUsed: BigNumber { _hex: '0x0102ea', _isBigNumber: true },
 logsBloom: '0x00000000400008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000100000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
 blockHash: '0x29dc868582fb2d15c078d21d159fe598f91b02ca96a34c4c3ec2e55dd8593c11',
 transactionHash: '0x13483c0839743df8d1cd6f56949cf06c10b9e910601db537e29ec9eb39ca1311',
 logs: [
   {
     transactionIndex: 7,
     blockNumber: 9179656,
     transactionHash: '0x13483c0839743df8d1cd6f56949cf06c10b9e910601db537e29ec9eb39ca1311',
     address: '0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC',
     topics: [Array],
     data: '0x4be7498271e1d63493d2e9e3be5df54ea31f1b220233bc597f4aaccbaffcd9230000000000000000000000000000000000000000000000000000000000000040000000000000000000000000096483d4addd6ccb428d81400483d503dae2e505000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000648a3fb500000000000000000000000000000000000000000000000000000000648a4dc500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c2b1798d6bcac9c0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d08d514c3a6f4625a3546a9dff43c8e27a5cd00a00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b5e620f480000000000000000000000000000000000000000000000000000000b5e620f48000000000000000000000000000096483d4addd6ccb428d81400483d503dae2e505',
     logIndex: 1,
     blockHash: '0x29dc868582fb2d15c078d21d159fe598f91b02ca96a34c4c3ec2e55dd8593c11'
   }
 ],
 blockNumber: 9179656,
 confirmations: 1,
 cumulativeGasUsed: BigNumber { _hex: '0x04187d', _isBigNumber: true },
 effectiveGasPrice: BigNumber { _hex: '0x5d7df740', _isBigNumber: true },
 status: 1,
 type: 2,
 byzantium: true
}

update:
I added operator approval through etherscan and it still doesnt get listed on opensea. Any idea what's going wrong?
https://goerli.etherscan.io/tx/0xe994c99afd647b35cb75f2a338c46e5fa96843084eac6f0225994edd1f411b26

@FiveNine the error is:

Failed to submit an order: An incorrect OpenSea fee has been provided. Expecting 250 basis points, but received 0. . Transaction hash 0x414938abd987583392ecaa68ec2c6bf2594ed3431b6647b5d710bc8a6d6fad86 , order hash 0xe86ddabea324068e5c593291aa40673073f4e468be4da2cde5637118d6998687

you'll need to add 2.5% of the total order value as a consideration item to 0x0000a26b00c1F0DF003000390027140000fAa719

ah thank you so much, it worked!
I'm just gonna leave my code here and close the issue in case anyone else stumbles upon this

const { Seaport } = require('@opensea/seaport-js');
const { ethers } = require('ethers');


const provider = new ethers.providers.JsonRpcProvider(
  "https://goerli.infura.io/v3/<API_KEY>"
);

const signer = new ethers.Wallet("<Private_KEY>", provider);

const seaport = new Seaport(signer);

const main = async () => {
    const offerer = "0x096483d4AdDD6ccB428D81400483D503DaE2e505"; // address of the NFT owner

    const conduitKey = "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000";

    const { executeAllActions } = await seaport.createOrder(
        {
            offerer: offerer,
            zone: "0x0000000000000000000000000000000000000000",
            zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
            startTime: Math.floor(new Date().getTime() / 1000).toString(),
            endTime: Math.floor(new Date().getTime() / 1000 + 60 * 60).toString(),
            offer: [
                {
                    itemType: 2,
                    token: "0xd08d514c3a6f4625a3546a9dff43c8e27a5cd00a",
                    identifier: "18",
                },
            ],
            consideration: [
                {
                    amount: ethers.utils.parseEther("0.0002").toString(),
                    recipient: offerer,
                },
                {
                    amount: (ethers.utils.parseEther("0.0002") * 0.025).toString(),
                    token: "0x0000000000000000000000000000000000000000",
                    recipient: "0x0000a26b00c1F0DF003000390027140000fAa719" // opensea fee
                }
            ],
            orderType: 1,
            conduitKey: conduitKey
        },
        offerer
    );

    const order = await executeAllActions();
    console.log(order);
    
    const validated = seaport.validate([order]);
    const transaction = await validated.transact();
    console.log('validated: ', await transaction.wait());
    

}
main();

great to hear, thanks!