1.1.6 • Published 2 years ago
@esrevitlu/mkt-client v1.1.6
@esrevitlu/mkt-client
Installation
yarn add @esrevitlu/mkt-client -S
Getting Started
Instantiate your instance using your ethers provider:
Examples
Through a browser provider (i.e. Metamask)
import { MKT } from "@esrevitlu/mkt-client";
import { ethers } from "ethers";
const provider = new ethers.providers.Web3Provider(window.ethereum);
const mktClient = new MKT(provider);
Use Cases
Listing
const provider = new ethers.providers.Web3Provider((window as any).ethereum);
const signer = provider.getSigner();
const address = await signer.getAddress();
const mkt = new MKT(provider);
const {
isCollectionApproved,
actions,
executeAllActions
} = await mkt.createOrder({
collection: "", // Collection address
// (Optional) collectionType: CollectionType.ERC721,
// (Optional) strategyId: StrategyType.standard,
// (Optional) subsetNonce: 0, // keep 0 if you don't know what it is used for
orderNonce: 0, // You need to retrieve this value from the API
price: ethers.utils.parseUnits("0.001", "ether"), // Be careful to use a price in wei, this example is for 1 ETH
itemIds: [1], // Token id of the NFT(s) you want to sell, add several ids to create a bundle
amounts: [1], // Use it for listing multiple ERC-1155 (Optional, Default to [1])
startTime: Math.floor(Date.now() / 1000), // Use it to create an order that will be valid in the future (Optional, Default to now)
endTime: Math.floor(Date.now() / 1000) + 3600 // If you use a timestamp in ms, the function will revert
});
// If only get the message for signature
for await (const action of actions) {
if (action.type === "create") {
console.log("create order sign msg", await action.getMessageToSign());
}
if (action.type === "approval") {
console.log(
"approval sign msg",
await action.transactionMethods.buildTransaction()
);
}
}
// Execute all actions, include the all approvals if needed
const order = await executeAllActions();
// *List order through API /order/makerAsk
Buy
import { MKT } from "@esrevitlu/mkt-client";
import { ethers } from "ethers";
const provider = new ethers.providers.Web3Provider((window as any).ethereum);
const mkt = new MKT(provider);
// Get order from API /orders
const { actions, executeAllActions } = await mkt.fulfillOrder(order);
await executeAllActions();
// Buy multiple orders
const { actions, executeAllActions } = await mkt.fulfillOrders(orders);
await executeAllActions();
Cancel
const { call, buildTransaction } = await mkt.cancelOrders([order.orderNonce]);
const res = await call();
// Sign message for canceling
const msg = await buildTransaction();
Check orderNonce (Same as exchange contract function userOrderNonce
)
console.log(
"check userOrderNonce",
address,
orderNonce,
await mkt.userOrderNonce(address, orderNonce)
);
Bid
const {
maker,
actions,
executeAllActions,
isBalanceSufficient,
isCurrencyApproved
} = await mkt.createOffer({
collection: "", // Collection address
// (Optional) collectionType: CollectionType.ERC721,
// (Optional) strategyId: StrategyType.standard,
// (Optional) subsetNonce: 0, // keep 0 if you don't know what it is used for
orderNonce: 0, // You need to retrieve this value from the API
price: ethers.utils.parseUnits("0.001", "ether"), // Be careful to use a price in wei, this example is for 1 ETH
itemIds: [1], // Token id of the NFT(s) you want to sell, add several ids to create a bundle
amounts: [1], // Use it for listing multiple ERC-1155 (Optional, Default to [1])
startTime: Math.floor(Date.now() / 1000), // Use it to create an order that will be valid in the future (Optional, Default to now)
endTime: Math.floor(Date.now() / 1000) + 3600 // If you use a timestamp in ms, the function will revert
});
// Execute all actions, include the all approvals if needed
const order = await executeAllActions();
Accept Bid
Just same as buy
(fulfillOrder
).
balanceOf
const balance = await mkt.balanceOf();
1.1.6
2 years ago
1.1.5
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago