1

I am creating a dapp for personal use that incorporates opensea-js, ethers.js, and MetaMask. The dapp is currently capable of opening a new seaport using MetaMask as the provider, and is able to successfully fetch assets using the seaport. I am using my own Opensea API key. The error arises when trying to place an offer on an asset. Please see the screenshot for the error, and see below for my code.

I am very unfamiliar with a lot of these pieces but have been slowly learning. Any and all help is greatly appreciated!

createBuyOrder error

import { OpenSeaPort, Network, EventType } from 'opensea-js'
const meta = require('@metamask/detect-provider')
const { ethers } = require("ethers");

export default async function makeOfferFunc () {

        //Use MetaMask as the provider
        const provider = new ethers.providers.Web3Provider(window.ethereum)
        
        //Create new seaport using MetaMask Provider
        const seaport = new OpenSeaPort(provider, {
            networkName: Network.Main,
            apiKey: "My_API_Key"
          })

        //Fetch asset
         const myAsset = await seaport.api.getAsset({
             tokenAddress: 'NFT_Contract_Address_Of_Choice',
             tokenId: "TOKEN_ID_Of_Choice"
           })

        // //Make offer
        const offer = await seaport.createBuyOrder({
             asset: myAsset,
             accountAddress: myWalletAddress,
             startAmount: .05,
             quantity: 1,
             expirationTime: 0,
          }).then(output => {
             console.log('then: ', offer);
         }).catch(err => {
           console.error('catch: ', err)
         });

          alert(offer)
}

1 Answer 1

2

The ethers.providers.Web3Provider() method wraps the provider inside an ethers.js "Web3Provider". I've not used OpenSeaPort, but it may be because you are not sending it a provider it can use.

Try to access the inner "provider" component of the Web3Provider wrapper. As you have it coded, edit this line to be:

const seaport = new OpenSeaPort(provider.provider, {.....})

I'd recommend a different syntax to make it easier to read:

const EthersProvider = new ethers.providers.Web3Provider(window.ethereum)
const seaport = new OpenSeaPort(EthersProvider.provider, {......})

Hope this helps for your case!

Your Answer

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

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