I am facing gass issue while buying nft using opnesa-js library.
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.