Ir al contenido principal

LooksRare SDK Create MakerBid

⚠️ These code snippets are just examples and the data should never be used as is ⚠️

How to create a maker bid order

The code snippet below is an example of how to create a maker bid using the @looksrare/sdk-v2 library.

The main steps are:

  1. Initialize a LooksRare class instance by providing the chain id, JSON-RPC provider and a signer.
  2. Use the createMakerBid method to create a maker bid with the parameters of your order.
  3. Check and grant necessary approvals for transferring assets.
  4. Sign the maker bid order with signMakerOrder method.

The orderNonce has to be retrieved via our Public API, see get order nonce.

Here is an example:

import { ethers } from "ethers";
import { LooksRare, ChainId, CollectionType, StrategyType } from "@looksrare/sdk-v2";

const lr = new LooksRare(ChainId.MAINNET, provider, signer);

const { maker, isCurrencyApproved, isBalanceSufficient } = await lr.createMakerBid({
collection: "0x0000000000000000000000000000000000000000", // Collection address
collectionType: CollectionType.ERC721,
strategyId: StrategyType.standard,
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
endTime: Math.floor(Date.now() / 1000) + 86400, // If you use a timestamp in ms, the function will revert
price: parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
itemIds: [0], // Token id of the NFT you want to buy
amounts: [1], // Use it for listing several 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)
});

// Approve spending of the currency used for bidding
if (!isCurrencyApproved) {
const tx = await lr.approveErc20(lr.addresses.WETH);
await tx.wait();
}

// Checks if the WETH balance is enough to cover the bid
if (!isBalanceSufficient) {
throw new Error(`WETH balance too low.`);
}

// Sign your maker order
const signature = await lr.signMakerOrder(maker);

Once, the maker bid for your collection offer has been created, the approvals sorted and the order signed, you will have to send it along with the signature to the POST /api/v2/orders endpoint. For more details and examples, see create order).

Need help?

You can reach out to the LooksRare team via our Developers Discord: https://discord.gg/LooksRareDevelopers