L
L
Loopring Dev Docs
Search…
⌃K

Mint NFT

Mint a Layer 2 NFT. Loopring follows the IPFS NFT format.
The SDK can be used to mint NFTs on Loopring's Layer 2 Minting uses IPFS and the CID will convert into the nftId. Review MetaNFT.md for additional details.

Step 1. get Account

Prepare Loopring Layer 2 account. Retrieve account information.
const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
owner: LOOPRING_EXPORTED_ACCOUNT.address,
});
console.log("accInfo:", accInfo);

Step 2. get eddsaKey

Once you have the account information, retrieve the account's EdDSA key for the minting process. Get Layer 2 EdDSA key.
const eddsaKey = await signatureKeyPairMock(accInfo);
console.log("eddsaKey:", eddsaKey.sk);

Step 3. get apiKey

Retrieve the account's API key.
const {apiKey} = await LoopringAPI.userAPI.getUserApiKey(
{
accountId: accInfo.accountId,
},
eddsaKey.sk
);
console.log("apiKey:", apiKey);

Step 4. get fee

Retrieve the mint fee. Get mint fee.
const fee = await LoopringAPI.userAPI.getNFTOffchainFeeAmt(
{
accountId: accInfo.accountId,
tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
requestType: sdk.OffchainNFTFeeReqType.NFT_MINT,
},
apiKey
);

Step 5. get storageId

Get fee token storageId
const storageId = await LoopringAPI.userAPI.getNextStorageId(
{
accountId: accInfo.accountId,
sellTokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId, // same as maxFee tokenId
},
apiKey
);

Step 6. get tokenAddress

Compute NFT tokenAddress
const counterFactualNftInfo = {
nftOwner: accInfo.owner,
nftFactory: sdk.NFTFactory[sdk.ChainId.GOERLI],
nftBaseUri: "",
};
const nftTokenAddress =
LoopringAPI.nftAPI.computeNFTAddress(counterFactualNftInfo)
.tokenAddress || "";
console.log("nftTokenAddress", nftTokenAddress);

Step 7. Mint

Mint the NFT
const response = await LoopringAPI.userAPI.submitNFTMint({
request: {
exchange: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
minterId: accInfo.accountId,
minterAddress: accInfo.owner,
toAccountId: accInfo.accountId,
toAddress: accInfo.owner,
nftType: 0,
tokenAddress: nftTokenAddress,
nftId: LOOPRING_EXPORTED_ACCOUNT.nftId, //nftId.toString(16),
amount: "1",
validUntil: LOOPRING_EXPORTED_ACCOUNT.validUntil,
storageId: storageId.offchainId ?? 9,
maxFee: {
tokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
amount: fee.fees["LRC"].fee ?? "9400000000000000000",
},
royaltyPercentage: 5,
counterFactualNftInfo,
forceToMint: true, // suggest use as false, for here is just for run test
},
web3,
chainId: sdk.ChainId.GOERLI,
walletType: sdk.ConnectorNames.Unknown,
eddsaKey: eddsaKey.sk,
apiKey: apiKey,
});