3

I'm using opensea-js alongside with nodejs to make offer on opensea testnet assets. The code is following:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

const Web3 = require('web3')
const opensea = require('opensea-js')

const provider = new Web3.providers.HttpProvider('https://rinkeby.infura.io')

const seaport = new opensea.OpenSeaPort(provider, {
  networkName: opensea.Network.Main
})

const call = async () => {
  const accountAddress = "my_metamask_wallet_address_on_rinkeby_network"
  const tokenId = 12
  const tokenAddress = "0x7dca125b1e805dc88814aed7ccc810f677d3e1db"
  const offer = await seaport.createBuyOrder({
    asset: {
      tokenAddress: tokenAddress,
      tokenId: tokenId,
    },
    accountAddress: accountAddress,
    startAmount: 1
  })
  console.log(offer.expirationTime)
}

call()

But it throws a 404 not found error, what am I doing wrong? The response is {"success": false}.

4
  • 1
    Not familiar with opensea, but seeing rinkeby testnet provider and opensea main net together seems strange. Oct 28, 2021 at 14:24
  • networkName: opensea.Network.Main is probably not Rinkeby Oct 28, 2021 at 15:28
  • You might also need an infura API key afer the infura url Oct 28, 2021 at 15:31
  • it doesn't work even when i change it to mainnet.infura.io Oct 28, 2021 at 17:58

2 Answers 2

5
+50

Few things

  1. You cannot use HttpProvider as the opensea-js library should be able to sign the transaction on your behalf. Try using HDWalletProvider or something similar with your mnemonic or private key to allow signing of the buy order.
const HDWalletProvider = require("@truffle/hdwallet-provider");

const provider = new HDWalletProvider({
    mnemonic: "<your wallet mnemonic>",
    providerOrUrl: "rinkeby infura link",
    addressIndex: 1
});
  1. You need to connect OpenSeaPort to the Rinkeby network.
const seaport = new opensea.OpenSeaPort(provider, {
  networkName: opensea.Network.Rinkeby
})

Final code should look something like

const Web3 = require('web3')
const opensea = require('opensea-js')
const HDWalletProvider = require("@truffle/hdwallet-provider");

const provider = new HDWalletProvider({
    mnemonic: "<your wallet mnemonic>",
    providerOrUrl: "https://rinkeby.infura.io",
    addressIndex: 0
});

const seaport = new opensea.OpenSeaPort(provider, {
  networkName: opensea.Network.Rinkeby
})

const call = async () => {
  const accountAddress = "my_metamask_wallet_address_on_rinkeby_network"
  const tokenId = 12
  const tokenAddress = "0x7dca125b1e805dc88814aed7ccc810f677d3e1db"
  const offer = await seaport.createBuyOrder({
    asset: {
      tokenAddress: tokenAddress,
      tokenId: tokenId,
    },
    accountAddress: accountAddress,
    startAmount: 1
  })
  console.log(offer.expirationTime)
}

call()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });
4
  • 1
    is there a reason I'm getting 404 not found error? Instead of just rinkeby.infura.io I'm putting a link from infura. thats xxxxxxxx:yyyyy/@eth2-beacon-mainnet.infura.io. Wallet address and mnemonics are correct. Nov 1, 2021 at 3:55
  • 1
    Your infura link should look like the following https://rinkeby.infura.io/v3/<api key>
    – Kunal Jain
    Nov 1, 2021 at 11:36
  • what about project id? It says invalid project id Nov 2, 2021 at 6:45
  • <api key> should be <project id> above. Your infura project id to be sure. @KunalJain has the correct answer.
    – EdwardG
    Mar 10, 2022 at 21:52
0

Same thing happened to me. It turns out the asset I was trying to retrieve was on Mumbai testnet, not on Rinkeby.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 11, 2022 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.