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;