0

I just trying to make an offer on OpenSea marketplace using Opensea SDK.

I took code from their tutorial https://projectopensea.github.io/opensea-js/#making-offers and tried to execute createBuyOrder()

import dotenv from 'dotenv';
dotenv.config();

import Web3 from 'web3';

import pkg from 'opensea-js';
const { Network, OpenSeaSDK } = pkg;

import HDWalletProvider from "@truffle/hdwallet-provider";

const contractAddress = "0xe24e4d4535f504d6d7957356534e23b4e787289f";
const tokenId = 1844;
const offerExpiration = 15;
const myWallet = "0x.....";

//const provider = new Web3.providers.HttpProvider(process.env.ALCHEMY_URL);
const openseaSDK = new OpenSeaSDK(provider, {
  networkName: Network.Main,
  apiKey: process.env.OPENSEA_API_KEY
});

getWETHbalance(myWallet);

// example from OpenSea API docs
const offer = await openseaSDK.createBuyOrder({
  asset: {
    tokenId,
    contractAddress,
  },
  myWallet,
  startAmount: 0.012,
}).then(function (offer) {
  console.log('[DEBUG]', new Date(), `Offer placed, expires in ${offerExpiration}min`, myOffer.orderHash, nft);
})
  .catch(function (error) {
    console.log('[ERROR]', new Date(), 'Offer failed', error);
  });


async function getWETHbalance(wallet) {
  const balanceOfWETH = await openseaSDK.getTokenBalance({
    accountAddress: wallet,
    tokenAddress: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  })

  console.log(balanceOfWETH);

}

And I get such an error:

 js-parser % node createOfferSDK2.js
https://eth-mainnet.g.alchemy.com/v2/nSP82PdJlxbmD4jB_bkB4_SkwUfPkuaT
DEPRECATED: Please use providerUtils.standardizeOrThrow() instead
DEPRECATED: Please use providerUtils.standardizeOrThrow() instead
[ERROR] 2023-05-05T16:51:41.934Z Offer failed Error: API Error 404: Not found. Full message was '{"success":false}'
    at OpenSeaAPI.<anonymous> (/Users/slava/JavaProjects/js-parser/node_modules/opensea-js/lib/api.js:563:31)
    at step (/Users/slava/JavaProjects/js-parser/node_modules/opensea-js/lib/api.js:67:23)
    at Object.next (/Users/slava/JavaProjects/js-parser/node_modules/opensea-js/lib/api.js:48:53)
    at fulfilled (/Users/slava/JavaProjects/js-parser/node_modules/opensea-js/lib/api.js:39:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
110000000000000000

As you see it outputs the contracts WETH balance so the provider and OpenseaSDK a connected properly.

And it is very strange because some API functions work, and some are "Not found"

I also found the same error here How can I solve 404 issue using the OpenSea JavaScript SDK? but I use ethereum instead of polygon

1 Answers1

0

Found a post with the solution:

Solved my side by creating instance of OpenSeaSDK rather than OpenSeaPort. Though they both are same, I don't know why it's working. I'm using 4.0.12 of opensea-js

Details: https://github.com/ProjectOpenSea/opensea-js/issues/472

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34