Gas Estimation Error: Seaport

Hi all. This may be the wrong place to ask this but I have tried all avenues. I continuously get the gas estimation error and I have tried all means of troubleshooting the code below to no avail.

the console.logs return the valid info

import { useEvmNativeBalance } from "@moralisweb3/next";
import { MetaMaskConnector } from "wagmi/connectors/metaMask";
import { useState, useEffect } from "react";
import { useAccount, useConnect, useSignMessage, useDisconnect } from "wagmi";
import { useAuthRequestChallengeEvm } from "@moralisweb3/next";
import { Seaport } from "@opensea/seaport-js";
import { ethers, BigNumber } from "ethers";
import { ItemType, MAX_INT, OrderType } from '@opensea/seaport-js/lib/constants';
import { generateRandomSalt } from "@opensea/seaport-js/lib/utils/order";
import { isCurrencyItem } from "@opensea/seaport-js/lib/utils/item";




function HomePage() {
  const { connectAsync } = useConnect();
  const { disconnectAsync } = useDisconnect();
  const { isConnected } = useAccount();
  const { signMessageAsync } = useSignMessage();
  const { requestChallengeAsync } = useAuthRequestChallengeEvm();

  const [addy, setAddy] = useState();
  const [chane, setChain] = useState();
 


  const login = async () => {
    if (window.ethereum) {
      window.ethereum
        .request({ method: "eth_requestAccounts" })
    } else {
      alert("install metamask extension!!");
    }
  }
   

  if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined')
   {
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    var seaport = new Seaport(provider);
    console.log(seaport)


   }


    const provider1 = new ethers.providers.JsonRpcProvider('https://eth-goerli.g.alchemy.com/v2/efAOkTBfs0x30qGYA57K2TUlu7G3qly_');
    
    const signer = new ethers.Wallet('d82c400bd7cf96167ee341c56c73b67cb76b70f5dc3bd7066c3528e7d3042741', provider1);
    
    const seaport1 = new Seaport(signer);
    console.log(seaport1)
    
    const offerOrderSpecificBuyer = async () => {
      const offerer = '0x8102FBB6D59928deFbBf9924eBBB3ca115d80bE7';
      const fulfiller = (seaport1?.signer)?.address;// seaport2
      console.log(offerer)
      console.log(fulfiller)
  
      const orderCreate = await seaport?.createOrder(
          {
              conduitKey: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
              // zone ์‚ฌ์šฉ์‹œ์—๋งŒ ์ž…๋ ฅ 
              // zone: "0x00000000E88FE2628EbC5DA81d2b3CeaD633E89e",
              // zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
              // startTime: Date.now(), ์ƒ๋žตํ•˜๋ฉด ์•Œ์•„์„œ blocktime ๋“ค์–ด๊ฐ€๋‹ˆ ์™ ๋งŒํ•˜๋ฉด ์ƒ๋žตํ•  ๊ฒƒ 
              endTime:1664428149, // ํ˜„์žฌ์‹œ๊ฐ„๋ถ€ํ„ฐ ๋งˆ๊ฐ์‹œ๊ฐ„๊นŒ์ง€ timestamp ๊ณ„์‚ฐํ•ด์„œ ๋„ฃ๊ธฐ
              offer: [{ // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
                  itemType: ItemType.ERC721,
                  token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
                  identifier: "5124",
                  amount: "1",
                  endAmount: "1"
              },
              { // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
                itemType: ItemType.ERC721,
                token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
                identifier: "5123",
                amount: "1",
                endAmount: "1"
            },
            { // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
              itemType: ItemType.ERC721,
              token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
              identifier: "5122",
              amount: "1",
              endAmount: "1"
          }
            ],
              consideration: [{ // offer ์ •๋ณด item type(ether ์‹œ ์ƒ๋žต๊ฐ€๋Šฅ), address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ), recipient ์ˆ˜๋ น์ธ
                  // token: "0x0000000000000000000000000000000000000000",
                  amount: ethers?.utils?.parseEther("20")?.toString(),
                  // identifier: "0",
                  recipient: offerer
              }, { // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
                itemType: ItemType.ERC721,
                token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
                identifier: "5124",
                amount: "1",
                endAmount: "1",
                recipient: fulfiller
            },
            { // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
              itemType: ItemType.ERC721,
              token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
              identifier: "5123",
              amount: "1",
              endAmount: "1",
              recipient: fulfiller
          },
          { // offer ์ •๋ณด item type, address, id, amount(, endamount ์ƒ๋žต๊ฐ€๋Šฅ)
            itemType: ItemType.ERC721,
            token: "0x77566D540d1E207dFf8DA205ed78750F9a1e7c55",
            identifier: "5122",
            amount: "1",
            endAmount: "1",
            recipient: fulfiller
        }],
              // counter: 0, seaport๊ฐ€ ์•Œ์•„์„œ ์ฐพ์•„์ฃผ๋‹ˆ ์ƒ๋žตํ•ด๋„ ๋œ๋‹ค
              // allowPartialFills: false, // ๋ถ€๋ถ„๊ฑฐ๋ž˜ ํ—ˆ์šฉ์‹œ์—๋งŒ true
              // restrictedByZone: true, // zone ์‚ฌ์šฉ์‹œ์—๋งŒ true ์ค„ ์ˆ˜ ์žˆ๋‹ค
              // fees:[{recipient: "0x0000a26b00c1F0DF003000390027140000fAa719", basisPoints: 250}],
          },
          offerer
      );
  
      const order = await orderCreate?.executeAllActions(); // ๊ตฌ์กฐ์ƒ db์— ์ €์žฅ ํ•ด์•ผ๋œ๋‹ค
      console.log("order: ", order);
      
  
      const counterOrder = constructPrivateListingCounterOrder(
          order,
          fulfiller
      );
      console.log("counterOrder: ", counterOrder);
  
      const fulfillments = getPrivateListingFulfillments(order);
      console.log("fulfillments : ", fulfillments);
  
      // fulfillOrder ๋ง๊ณ  matchOrder ํ•จ์ˆ˜ ๋ถ€๋ฅด๋Š” ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ํ•„์š” 
      // -> order์˜ offer item์ด consideration item์— ํฌํ•จ๋œ ๊ฒฝ์šฐ
        console.log(order)
        console.log(counterOrder)
        console.log(fulfillments)
        console.log(fulfiller)
      const transaction = await seaport1?.matchOrders({
          orders: [order, counterOrder], 
          fulfillments,
          // overrides: {
          //     value: counterOrder?.parameters?.offer[0]?.startAmount,
          // },
          accountAddress: fulfiller,
      }).transact();
     
      console.log("match order : ", transaction);
  } 



  const constructPrivateListingCounterOrder = (
    order,
    privateSaleRecipient
  ) => {
    // Counter order offers up all the items in the private listing consideration
    // besides the items that are going to the private listing recipient
    const paymentItems = order?.parameters?.consideration?.filter(
      (item) =>
        item?.recipient?.toLowerCase() !== privateSaleRecipient?.toLowerCase()
    );
  
    if (!paymentItems?.every((item) => isCurrencyItem(item))) {
      throw new Error(
        "The consideration for the private listing did not contain only currency items"
      );
    }
    if (
      !paymentItems?.every((item) => item?.itemType === paymentItems[0]?.itemType)
    ) {
      throw new Error("Not all currency items were the same for private order");
    }
  
    const { aggregatedStartAmount, aggregatedEndAmount } = paymentItems?.reduce(
      ({ aggregatedStartAmount, aggregatedEndAmount }, item) => ({
        aggregatedStartAmount: aggregatedStartAmount?.add(item?.startAmount),
        aggregatedEndAmount: aggregatedEndAmount?.add(item?.endAmount),
      }),
      {
        aggregatedStartAmount: BigNumber?.from(0),
        aggregatedEndAmount: BigNumber?.from(0),
      }
    );
  
    const counterOrder = {
      parameters: {
        ...order?.parameters,
        offerer: privateSaleRecipient,
        offer: [
          {
            itemType: paymentItems[0]?.itemType,
            token: paymentItems[0]?.token,
            identifierOrCriteria: paymentItems[0]?.identifierOrCriteria,
            startAmount: aggregatedStartAmount?.toString(),
            endAmount: aggregatedEndAmount?.toString(),
          },
        ],
        // The consideration here is empty as the original private listing order supplies
        // the taker address to receive the desired items.
        consideration: [],
        salt: generateRandomSalt(),
        // totalOriginalConsiderationItems: 0,
      },
      signature: "0x",
    };
  
    return counterOrder;
};

const getPrivateListingFulfillments = (
  privateListingOrder
) => {
  const nftRelatedFulfillments = [];

  // For the original order, we need to match everything offered with every consideration item
  // on the original order that's set to go to the private listing recipient
  privateListingOrder?.parameters?.offer?.forEach((offerItem, offerIndex) => {
      const considerationIndex = privateListingOrder?.parameters?.consideration?.findIndex(
          (considerationItem) =>
              considerationItem?.itemType === offerItem?.itemType &&
              considerationItem?.token === offerItem?.token &&
              considerationItem?.identifierOrCriteria === offerItem?.identifierOrCriteria
      );
      if (considerationIndex === -1) {
          throw new Error(
              "Could not find matching offer item in the consideration for private listing"
          );
      }
      nftRelatedFulfillments.push({
          offerComponents: [{
              orderIndex: 0,
              itemIndex: offerIndex,
          }],
          considerationComponents: [{
              orderIndex: 0,
              itemIndex: considerationIndex,
          }],
      });
  });

  const currencyRelatedFulfillments = [];

  // For the original order, we need to match everything offered with every consideration item
  // on the original order that's set to go to the private listing recipient
  privateListingOrder?.parameters?.consideration?.forEach(
      (considerationItem, considerationIndex) => {
          if (!isCurrencyItem(considerationItem)) {
              return;
          }
          // We always match the offer item (index 0) of the counter order (index 1)
          // with all of the payment items on the private listing
          currencyRelatedFulfillments?.push({
              offerComponents: [{
                      orderIndex: 1,
                      itemIndex: 0,
              }],
              considerationComponents: [{
                      orderIndex: 0,
                      itemIndex: considerationIndex,
              }],
          });
      }
  );

  return [...nftRelatedFulfillments, ...currencyRelatedFulfillments];
};




  


  


// const handleAuth = async () => {
//   if (isConnected) {
//     await disconnectAsync();
//   }

//   const { account, chain } = await connectAsync({
//     connector: new MetaMaskConnector(),
//   });

//   const { message } = await requestChallengeAsync({
//     address: account,
//     chainId: chain.id,
//   });
//   setChain(chain)

//   const signature = await signMessageAsync({ message });
//   setAddy(account);
//   console.log(signature);
// };
  

  // const { data: nativeBalance, error, fetch } = useEvmNativeBalance();
  // // const {data: allBalance } = useEvmWalletTokenBalances({address})
  // useEffect(() => {
  //   if (addy && chane) {
  //     fetch({
  //       address: addy,
  //       chain: chane?.id,
  //     });
  //   }
  // }, [addy, chane]);
  // useEffect(() => {
  //   if (error) {
  //     console.log(error);
  //   }
  // }, [error]);

  return (
    <div>
      <button className="ml-20 p-10 w-4" onClick={login}>LOGIN </button>
      {/* <button onClick={signOut}></button> */}
      {/* <h3>Wallet: {addy}</h3>
      <h3>Native Balance: {nativeBalance?.balance?.ether} ETH</h3>
      <h3>Chain: {chane?.id}</h3> */}
      <button onClick={offerOrderSpecificBuyer}> OFFER</button>
      

      {/* <h3>All Balance: {allBalance} ETH</h3> */}
    </div>
  );
}

export default HomePage;

Hi @CleanMcGerk

You could also get a gas estimation error if the wallet could not find the contract address on the connect chain. So verify if you the contract address is correct and you are connected to the correct chain in metamask where the contract was deployed.

I hops this helps

I am using Goerli. And its seaport so we donโ€™t input contract address simply the conduitKey and in the event that no conduitkey is entered a default one is inputted by the seaport-js package. I have tried both the default as well as the conduitKey shown above

Oh ok. Not sure if there is any other reason for the Gas estimation error.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.