[SOLVED] Using Seaport-js with moralis

Hi all - not sure if this is a silly question however it is quite difficult finding any tutorials regarding this whatsoever.

I am trying to interact with seaport using Moralis in nextjs… The following is my _app.js file

import "../styles/globals.css"
import Head from "next/head"
import { MoralisProvider } from "react-moralis"


const APP_ID = process.env.NEXT_PUBLIC_APP_ID
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL


function MyApp({ Component, pageProps, router }) {
    return (
        <div>
            <Head>
                <title>Seaplay</title>
                <link rel="icon" href="/favicon.ico" />
                <link rel="apple-touch-icon" href="/favicon.ico"/>
                
            </Head>
            <MoralisProvider appId={APP_ID} serverUrl={SERVER_URL}>
             
                    <Component {...pageProps} key={router.route}/>
    
            </MoralisProvider>
        </div>
    )
}

export default MyApp

However in the seaport docs provided on Github the following is inferred. I understand it is redundant however I am unsure as to how to integrate the two so as to be able to interact with seaport or if this is even possible at all.

import { Seaport } from "@opensea/seaport-js";
import { ethers } from "ethers";

const provider = new ethers.providers.JsonRpcProvider(
  "https://<network>.alchemyapi.io/v2/YOUR-API-KEY"
);

const seaport = new Seaport(provider);

If my question is ill-informed and anyone has any supplementary resources kindly forward them - I have read through the seaport docs extensively

What is the issue exactly? Or what are you wanting to do with the Seaport SDK and how does it relate to the use of moralis-v1 / react-moralis?

I want to fetch all nfts using Moralis and it doesn’t seem like Moralis is interoperable with seaport

Please correct me if I’m wrong

I would love to be able to login using web3uikit <ConnectButton/> component however then I wouldn’t be able to call const seaport = new Seaport(provider) That’s the issue I face… I would prefer not using my own rpc and use Moralis entirely

Would love to skip over everything but the last line of course and use moralis as the provider

 const provider1 = new ethers.providers.JsonRpcProvider(
    process.env.NEXT_PUBLIC_GOERLI
  );
  const signer = new ethers.Wallet(`${process.env.NEXT_PUBLIC_PRIVATE_KEY}`, provider1);
  const seaport1 = new Seaport(signer)

If you want to get the provider, one way is to use enableWeb3. E.g. const provider = await enableWeb3(). Or use web3 from useMoralis() if web3 is already enabled.

I am not trying to sign in - I am already signed in I simply need the provider and the const provider = await enableWeb3() doesn’t seem to solve the issue at hand whereas this link https://github.com/MoralisWeb3/react-moralis#web3 refers to enabling web3 and not necessarily obtaining the provider. When I tested using the method below it was successful however, I am not signing in by my own means in my example - I have used web3uikit and moralis ofc.

const login = async () => {
    if (window.ethereum) {
      window.ethereum
        .request({ method: "eth_requestAccounts" }).then((addy) => setAddress(addy[0]));
    } else {
      alert("install metamask extension!!");
    }
  }
   

  if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined')
   {
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    var seaport = new Seaport(provider);


   }

I also tried the following but that didn’t seem to do the trick either

const provider = new ethers.providers.Web3Provider(Moralis.provider);
    var seaport = new Seaport(provider);

As you can see below my jsonrpc provider is available (tried web3 & window.ethereum)


Here is the error I receive - which does not happen outside of my moralis project as I tested it before trying to integrate.

I am assuming this has something to do with this but I am no profressional

enableWeb3() doesn’t sign you in. web3() does get the provider (if you have used either authenticate() or enableWeb3()).

What is the provider code that leads to this? You have not posted that.

Try it with the signer:

const provider = await enableWeb3();

const signer = provider.getSigner();

const seaport = new Seaport(signer);

Uncaught (in promise) Error: invalid address (argument=“address”, value=“759”, code=INVALID_ARGUMENT, version=address/5.7.0)

it tells me its an ethers project error. I have tried hardcoding both offerer and fulfiller variables presented below but it seems as if its connected to the provider/rpc etc…

const provider1 = new ethers.providers.JsonRpcProvider(
  process.env.NEXT_PUBLIC_GOERLI
);

const signer = new ethers.Wallet(`${process.env.NEXT_PUBLIC_PRIVATE_KEY}`, provider1);
const seaport1 = new Seaport(signer)

const offerer = account;

const fulfiller = (seaport1?.signer)?.address; 


const orderly = {
    startTime: "0",
    offer: [],
    consideration: [
      {
          amount: ethers.utils.parseEther("10").toString(),
          recipient: offerer,
      }
    ],

}

const lend = nftBalance.length
for(let i=0; i<lend; i++)
{
  orderly.offer.push({
    itemType: ItemType.ERC721,
    token: nftBalance[i]?.token_address,
    identifier: nftBalance[i]?.token_id,
  })
  orderly.consideration.push({
    itemType: ItemType.ERC721,
    token: nftBalance[i]?.token_address,
    identifier: nftBalance[i]?.token_id,
    recipient:fulfiller,
  })

  
}




const offerOrderSpecificBuyer = async () => {
  const provider = await enableWeb3()
    const signee = provider.getSigner()
    const seaport= new Seaport(signee);
    console.log(seaport)
 
  
  const orderCreate = await seaport?.createOrder(
      orderly,
      offerer
  );
 
  const order = await orderCreate?.executeAllActions();
  console.log("order: ", order);
  //setOrder(orders)
}

nevermind solved it thanks for you help king