0

I am facing gass issue while buying nft using opnesa-js library. enter image description here

The listing functionality is working fine. But when i try to make the buy function then it gives me gass related issue. Here is my buy function using opensea-js on goerli and mainnet ehterieum network.

const buyNftGoerli = async (req) => {
  try {
    const { privateKey, tokenId, tokenAddress, accountAddress } = req.body;
    if (!privateKey) {
      throw new Error("Please Provide Private Key");
    }
    if (!tokenId) {
      throw new Error("Please Provide Token ID");
    }
    if (!tokenAddress) {
      throw new Error("Please Provide Token Address");
    }
    if (!accountAddress) {
      throw new Error("Please Provide Account Address");
    }

    const provider = new HDWalletProvider({
      privateKeys: [privateKey],
      providerOrUrl:
        "https://goerli.infura.io/v3/[API_KEY_Infura]",
      chainId: 5,
    });
    const config = {
      apiKey: "",
      networkName: Network.Goerli,
    };
    const openseaSDK = new OpenSeaSDK(provider, config);
    const { orders } = await openseaSDK.api.getOrders({
      assetContractAddress: tokenAddress,
      tokenId,
      side: "ask",
    });

    if (!orders) {
      throw new Error("Can not Get Order From Opensea");
    }
    const order = orders[0];
    const transactionHash = await openseaSDK.fulfillOrder({
      order,
      accountAddress,
    });
    if (!transactionHash) {
      throw new Error("Can not Complete the Order");
    }
    return {
      success: true,
      data: transactionHash,
    };
  } catch (error) {
    throw new ApiError(httpStatus.UNAUTHORIZED, error);
  }
};

Its the node with express.

  • Here's 2 StackOverflow questions from people with the same problems, maybe it helps: https://ethereum.stackexchange.com/questions/112516/why-is-an-unpredictable-gas-limit-error-thrown-when-calling-a-view-function-cr and https://stackoverflow.com/questions/70622074/set-gas-limit-on-contract-method-in-ethers-js – CoderApprentice Feb 14 '23 at 14:53
  • that error happens when you call the contract function with wrong arguments – Yilmaz Feb 14 '23 at 16:57
  • I did just like you but it returned "Either a provider or custom signer with provider must be provided" error. Did you get into this issue? – marethyu Jun 19 '23 at 07:55

0 Answers0