ProjectOpenSea / opensea-js

TypeScript SDK for the OpenSea marketplace
https://docs.opensea.io/reference
MIT License
2.28k stars 955 forks source link

{ code: -32603, message: "execution reverted" } when try to buy NFT #756

Closed creed-dev closed 1 year ago

creed-dev commented 1 year ago

I get an error { code: -32603, message: "execution reverted" } from console when try to buy nft which was put up for sale through the OpenSeaSDK through createSellOrder function. If put it up for sale through the UI, there is no such problem.

Code:

require('dotenv').config();
const opensea = require("opensea-js");
const Network = require("opensea-js").Network;
const OpenSeaSDK = opensea.OpenSeaSDK;
const HDWalletProvider = require("@truffle/hdwallet-provider");
const {WyvernSchemaName} = require('opensea-js/lib/types');

const MNEMONIC = process.env.MNEMONIC;
const NODE_API_KEY = process.env.INFURA_KEY || process.env.ALCHEMY_KEY;
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS;
const OWNER_ADDRESS = process.env.OWNER_ADDRESS;
const NETWORK = process.env.NETWORK;
const API_KEY = process.env.API_KEY || ""; // API key is optional but useful if you're doing a high volume of requests.

const provider = new HDWalletProvider({
    mnemonic: MNEMONIC,
    providerOrUrl: "https://" + NETWORK + ".infura.io/v3/" + NODE_API_KEY,
    chainId: 5
});

const seaport = new OpenSeaSDK(
    provider,
    {
        networkName: Network.Goerli
    },
    (arg) => console.log(arg)
);

async function listing(tokenId) {
    try {
        await seaport.createSellOrder({
            asset: {
                tokenId: tokenId,
                tokenAddress: NFT_CONTRACT_ADDRESS,
                schemaName: WyvernSchemaName.ERC721
            },
            startAmount: .001,
            accountAddress: OWNER_ADDRESS
        });

        return "Success!";
    } catch (err) {
        return err;
    }
}

listing("0").then(res => {
    console.log(res);
}).catch(rej => {
    console.log(rej);
});

package.json:

{
  "type": "commonjs",
  "dependencies": {
    "@truffle/hdwallet-provider": "^2.0.15",
    "axios": "^0.27.2",
    "dotenv": "^16.0.2",
    "ethers": "^5.7.1",
    "opensea-js": "^4.0.12",
    "web3": "^1.8.0",
    "wyvern-schemas": "^0.6.15"
  }
}

Node version: v16.17.1

Smeagolworms4 commented 1 year ago

+1 exactly the same error

carlosbalsas commented 1 year ago

+1

CokeBear666 commented 1 year ago

+1

cterech commented 1 year ago

hey - acknowledging the issue, we will look at prioritizing the fix in the next few weeks

relipa-dev commented 1 year ago

+1

maxtor3569 commented 1 year ago

+1

qnft-mjb commented 1 year ago

Still receiving this error, any update?

qnft-mjb commented 1 year ago

Not a contributor, but in my working through of trying to solve this I discovered something. This function appears to use wyvern protocol, which is deprecated. Seaport-js package has a function createOrder that should be used to make seaport protocol orders.

tantannguyen9x commented 1 year ago

+1 This bug is more than 1 month old, when will there be a fix for this bug?

Smeagolworms4 commented 1 year ago

If not fix, Do you have a workaround to solve the problem?

An example of using createOrder. Because the latter is more complex than createSellOrder.

qnft-mjb commented 1 year ago

To my understanding, createBuyOrder post orders to the wyvern protocol smart contract. This contract is no longer by used by opensea for orders so even if this bug was resolved the orders posted would not appear on opensea(or anywhere?) - opensea is now using the the seaport contract and to interact with that you need to use seaport-js sdk ... And yes sadly it is more complex.

Smeagolworms4 commented 1 year ago

The method is createShellOrder and not createBuyOrder. (Maybe it's a name mistake in your answer). Do you have an example of using createOrder? However, I did not find the reference to Wyvern on the createSellOrder method.

qnft-mjb commented 1 year ago

Sorry, my issue originated with createBuyOrder and this ticket is for createSellOrder... The error code is the same though...

Again, I am not a contributor and can't confirm this... But the order model you post with this function is designed for wyvern. The create listing/offer api endpoints on Opensea now only accept a seaport order model. Or at least I didn't see any way to successfully list a wyvern order on Opensea.

So to my knowledge, no work around... Ya gotta upgrade 🤷

Smeagolworms4 commented 1 year ago

Thank you for your answer. On the other hand I have no problem to upgrade because I use openseajs only to make a create sell order. but how do I upgrade with what? do you have an example?

qnft-mjb commented 1 year ago

So there are two issues 0xAskar has posted that have helped me. More discussion on it exists in the comments.

[https://github.com/ProjectOpenSea/seaport/discussions/594]()

[https://github.com/ProjectOpenSea/seaport/issues/600]()

Seaport orders are a little different. If you go Opensea Discord - dev resources channel, there is a video called "seaport workshop" in this they explain the order model.

But you need to use seaport-js (check the readme) to generate and fulfill orders (this will be on chain) - these orders are decoupled from Opensea it's self. Any marketplace can hook up to seaport.

But seaport was developed by OS, they are the main consumer of seaport orders. However they don't list automatically on OS you need write code that first uses seaport-js to produce a signed order, then make a API request (V2 on OS docs) to list the order ( offer = bid, listing = ask) - I don't believe opensea-js ask has a V2 function yet.

Hope this helps.

inartin commented 1 year ago

Is it still not solved? I even noticed that if I create the order via SDK as usual, this error will appear even on the main OpenSea site.

Smeagolworms4 commented 1 year ago

Still not and I haven't been able to find a workaround. Or a fix. +1

alandotcom commented 1 year ago

Try this when listing for sale:

  openseaSDK.seaport.createOrder = async (input) => {
    const override = {
      restrictedByZone: false,
      allowPartialFills: false,
    };

    const newInput = { ...input, ...override };

    return await ogCreate.call(openseaSDK.seaport, newInput);
  };
Smeagolworms4 commented 1 year ago

Thank you very mush @alandotcom


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

const oldCreateOrder = Seaport.prototype.createOrder;
Seaport.prototype.createOrder = function (input) {
    return oldCreateOrder.call(this, {
        ...input,
        ...{
            restrictedByZone: false,
            allowPartialFills: false,
        }
    });
};

Works for me

creed-dev commented 1 year ago

Try this when listing for sale:

  openseaSDK.seaport.createOrder = async (input) => {
    const override = {
      restrictedByZone: false,
      allowPartialFills: false,
    };

    const newInput = { ...input, ...override };

    return await ogCreate.call(openseaSDK.seaport, newInput);
  };

This fix the error. Thank you, @alandotcom !

Smeagolworms4 commented 1 year ago

This bug is not closed. The solution has hack for fix. Not final solution @creed-dev Can you reopen this ?

inartin commented 1 year ago

The solution has hack for fix. Not final solution

Agree, this should be fixed at the SDK level not as a workaround.

hoanggjang33889 commented 1 year ago

It seems to me that this error is caused by the goreli . contract https://etherscan.io/address/0x1e0049783f008a0085193e00003d00cd54003c71 image