neetbear / seaport_practice Goto Github PK
View Code? Open in Web Editor NEWparctice for seaport
parctice for seaport
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>
)
}
just kidding
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.