GithubHelp home page GithubHelp logo

seaport_practice's People

Contributors

neetbear avatar

Stargazers

 avatar

Watchers

 avatar

seaport_practice's Issues

Gas Estimation Error when following your practice using Nextjs

I would appreciate it if you guided me a little as to why it is failing

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import { Seaport } from "@opensea/seaport-js";
import { ethers, BigNumber } from "ethers";
import { ItemType, MAX_INT, OrderType } from '@opensea/seaport-js/lib/constants';
import { generateRandomSalt } from "@opensea/seaport-js/lib/utils/order";
import { isCurrencyItem } from "@opensea/seaport-js/lib/utils/item";



export default function Home() {

  const login = async () => {
    if (window.ethereum) {
      window.ethereum
        .request({ method: "eth_requestAccounts" })
    } 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);


   }
  
  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)

  console.log((seaport1.signer).address)
  
  const offerOrderSpecificBuyer = async () => {
    const offerer = (seaport?.signer)?.address;
    const fulfiller = (seaport1?.signer)?.address;  
     

    const orderCreate = await seaport.createOrder(
        {
            // conduitKey: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
            // zone 
            orderType: OrderType.FULL_RESTRICTED,
            salt: generateRandomSalt(),
            zone: fulfiller,
            // zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
            // startTime: Date.now(),  
            endTime: MAX_INT.toString(),
        
            offer: [{ 
                itemType: ItemType.ERC721,
                token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
                identifier: "2338673",
                amount: "1",
                endAmount: "1"
            },
              { 
                itemType: ItemType.ERC721,
                token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
                identifier: "2338672",
                amount: "1",
                endAmount: "1"
            },
              { 
                itemType: ItemType.ERC721,
                token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
                identifier: "2338671",
                amount: "1",
                endAmount: "1"
            }],
            consideration: [{
                // token: "0x0000000000000000000000000000000000000000",
                amount: ethers.utils.parseEther("0.2").toString(),
                // endAmount: ethers.utils.parseEther("0.2").toString(),
                // identifier: "0",
                recipient: offerer
            }, { 
                itemType: ItemType.ERC721,
                token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
                identifier: "2338673",
                amount: "1",
                endAmount: "1",
                recipient: fulfiller
            },
            { 
              itemType: ItemType.ERC721,
              token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
              identifier: "2338672",
              amount: "1",
              endAmount: "1",
              recipient: fulfiller
          },
          { 
            itemType: ItemType.ERC721,
            token: "0xf5de760f2e916647fd766B4AD9E85ff943cE3A2b",
            identifier: "2338671",
            amount: "1",
            endAmount: "1",
            recipient: fulfiller
        }],
            // counter: 0, 
          
        },
        offerer
    );

    const order = await orderCreate.executeAllActions();
    console.log("order: ", order);

    const counterOrder = constructPrivateListingCounterOrder(
        order,
        fulfiller
    );
    console.log("counterOrder: ", counterOrder);

    const fulfillments = getPrivateListingFulfillments(order);
    console.log("fulfillments : ", fulfillments);

   
    const transaction = await seaport1.matchOrders({
        orders: [order, counterOrder], 
        fulfillments,
        // overrides: {
            // value: counterOrder.parameters.offer[0].startAmount,
        // },
        accountAddress: fulfiller,
    }).transact();
    console.log("match order : ", transaction);
} 

const constructPrivateListingCounterOrder = (
  order,
  privateSaleRecipient
) => {
  // Counter order offers up all the items in the private listing consideration
  // besides the items that are going to the private listing recipient
  const paymentItems = order.parameters.consideration.filter(
    (item) =>
      item.recipient.toLowerCase() !== privateSaleRecipient.toLowerCase()
  );

  if (!paymentItems.every((item) => isCurrencyItem(item))) {
    throw new Error(
      "The consideration for the private listing did not contain only currency items"
    );
  }
  if (
    !paymentItems.every((item) => item.itemType === paymentItems[0].itemType)
  ) {
    throw new Error("Not all currency items were the same for private order");
  }

  const { aggregatedStartAmount, aggregatedEndAmount } = paymentItems.reduce(
    ({ aggregatedStartAmount, aggregatedEndAmount }, item) => ({
      aggregatedStartAmount: aggregatedStartAmount.add(item.startAmount),
      aggregatedEndAmount: aggregatedEndAmount.add(item.endAmount),
    }),
    {
      aggregatedStartAmount: BigNumber.from(0),
      aggregatedEndAmount: BigNumber.from(0),
    }
  );

  const counterOrder = {
    parameters: {
      ...order.parameters,
      offerer: privateSaleRecipient,
      offer: [
        {
          itemType: paymentItems[0].itemType,
          token: paymentItems[0].token,
          identifierOrCriteria: paymentItems[0].identifierOrCriteria,
          startAmount: aggregatedStartAmount.toString(),
          endAmount: aggregatedEndAmount.toString(),
        },
      ],
      // The consideration here is empty as the original private listing order supplies
      // the taker address to receive the desired items.
      consideration: [],
      salt: generateRandomSalt(),
      totalOriginalConsiderationItems: 0,
    },
    signature: "0x",
  };

  return counterOrder;
};


const getPrivateListingFulfillments = (
  privateListingOrder
) => {
  const nftRelatedFulfillments = [];

  // For the original order, we need to match everything offered with every consideration item
  // on the original order that's set to go to the private listing recipient
  privateListingOrder.parameters.offer.forEach((offerItem, offerIndex) => {
      const considerationIndex = privateListingOrder.parameters.consideration.findIndex(
          (considerationItem) =>
              considerationItem.itemType === offerItem.itemType &&
              considerationItem.token === offerItem.token &&
              considerationItem.identifierOrCriteria === offerItem.identifierOrCriteria
      );
      if (considerationIndex === -1) {
          throw new Error(
              "Could not find matching offer item in the consideration for private listing"
          );
      }
      nftRelatedFulfillments.push({
          offerComponents: [{
              orderIndex: 0,
              itemIndex: offerIndex,
          }],
          considerationComponents: [{
              orderIndex: 0,
              itemIndex: considerationIndex,
          }],
      });
  });

  const currencyRelatedFulfillments = [];

  // For the original order, we need to match everything offered with every consideration item
  // on the original order that's set to go to the private listing recipient
  privateListingOrder.parameters.consideration.forEach(
      (considerationItem, considerationIndex) => {
          if (!isCurrencyItem(considerationItem)) {
              return;
          }
          // We always match the offer item (index 0) of the counter order (index 1)
          // with all of the payment items on the private listing
          currencyRelatedFulfillments.push({
              offerComponents: [{
                      orderIndex: 1,
                      itemIndex: 0,
              }],
              considerationComponents: [{
                      orderIndex: 0,
                      itemIndex: considerationIndex,
              }],
          });
      }
  );

  return [...nftRelatedFulfillments, ...currencyRelatedFulfillments];
};


  return (
    <div className={styles.container}>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <button onClick={()=>login()}>Login</button>
      <button onClick={()=>offerOrderSpecificBuyer()}>MatchIt</button>

      <footer className={styles.footer}>
        <a
          href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
          target="_blank"
          rel="noopener noreferrer"
        >
          Powered by{' '}
          <span className={styles.logo}>
            <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
          </span>
        </a>
      </footer>
    </div>
  )
}

nah

just kidding

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.