Skip to content

Instantly share code, notes, and snippets.

@Theo6890
Created December 4, 2021 03:26
Show Gist options
  • Save Theo6890/e70b686b03944585ef8d55061419cae4 to your computer and use it in GitHub Desktop.
Save Theo6890/e70b686b03944585ef8d55061419cae4 to your computer and use it in GitHub Desktop.
Lazy mint & list NFT asset with sell order using ethers & IPFS via Rarible SDK
require("dotenv").config();
const { EthersEthereum } = require("@rarible/ethers-ethereum");
const fetch = (...args) =>
import("node-fetch").then(({ default: fetch }) => fetch(...args));
global.FormData = require("form-data");
global.window = {
fetch: fetch,
dispatchEvent: () => {},
};
const { createRaribleSdk } = require("@rarible/protocol-ethereum-sdk");
const { toAddress, toBigNumber } = require("@rarible/types");
const erc721Address = "";
const minterOwner = "";
const uri = "/ipfs/QmVsbGaT5Yave5fnLQgHYQyhNbhj3KduGPLLJyxkVSCHwR/";
const configureSDK = async () => {
const [owner] = await ethers.getSigners(); // You can do this using: npx hardhat run rarible_mint_sell.js --network rinkeby (or other depending on your hardhat config file)
const sdk = new createRaribleSdk(new EthersEthereum(owner), "rinkeby", {
fetchApi: fetch,
});
return sdk;
};
const lazyMintCollection = async () => {
const sdk = await configureSDK();
const mintRequest = {
collection: {
id: toAddress(erc721Address), // contract address
type: "ERC721", // type of asset to mint, "ERC721" || "ERC1155"
supportsLazyMint: true, // true if contract supports lazy minting
},
uri: uri, // token uri
creators: [{ account: toAddress(minterOwner), value: 10000 }],
royalties: [], // royalties
lazy: true, // true if mint lazy or false when mint onchain
};
const tokenId = await sdk.nft.mint(mintRequest);
return tokenId;
};
const sellCollection = async (tokenId) => {
const sdk = await configureSDK();
const request = {
makeAssetType: {
assetClass: "ERC721",
contract: toAddress(erc721Address),
tokenId: tokenId,
},
maker: toAddress(minterOwner),
amount: "1",
originFees: [],
payouts: [],
price: "10000000000000000", // 0.01
takeAssetType: { assetClass: "ETH" },
};
const order = await sdk.order.sell(request);
console.log({ order });
return order;
};
async function main() {
const res = await lazyMintCollection();
const { tokenId } = res;
console.log({ res });
console.log("tokenId: ", tokenId);
console.log("list & sell collection...");
await sellCollection(tokenId.toString());
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment