0

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 at 14:24
  • networkName: opensea.Network.Main is probably not Rinkeby Oct 28 at 15:28
  • You might also need an infura API key afer the infura url Oct 28 at 15:31
  • it doesn't work even when i change it to mainnet.infura.io Oct 28 at 17:58
1
+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);
    });
3
  • 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 at 3:55
  • Your infura link should look like the following https://rinkeby.infura.io/v3/<api key>
    – Kunal Jain
    Nov 1 at 11:36
  • what about project id? It says invalid project id Nov 2 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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