Mint Counterfactual 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 for additional details.

Step 1: Get Account

Prepare your Loopring Layer 2 account. Retrieve account information.

const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
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);
Step 3: Get apiKey

Retrieve the account's API key.

const {apiKey} = await LoopringAPI.userAPI.getUserApiKey(
    accountId: accInfo.accountId,
console.log("apiKey:", apiKey);
Step 4: Get storageId

Get fee token storageId

const storageId = await LoopringAPI.userAPI.getNextStorageId(
    accountId: accInfo.accountId,
    sellTokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId, // same as maxFee tokenId
Step 5: Get tokenAddress

Before mint user should create an collection for information with an url, follow code using the user own collection-list first item as demo

const collectionRes = await LoopringAPI.userAPI
   owner: accInfo.owner,
   isMintable: true
if ((collectionRes &&
 ((collectionRes as sdk.RESULT_INFO).code ||
  (collectionRes as sdk.RESULT_INFO).message)) || !collectionRes.collections.length
) {
 console.log("Collection is disable to mint ");
 throw "Collection is disable to mint ";

const collectionMeta = (collectionRes as any).collections[ 0 ] as CollectionMeta;

const counterFactualNftInfo: NFTCounterFactualInfo = {
 nftOwner: accInfo.owner,
 nftFactory: collectionMeta.nftFactory ?? sdk.NFTFactory_Collection[ sdk.ChainId.GOERLI ],
 nftBaseUri: collectionMeta.baseUri,
const nftTokenAddress = collectionMeta.contractAddress,
Step 6: Get fee

Retrieve the mint fee.

 const fee = await LoopringAPI.userAPI.getNFTOffchainFeeAmt(
    accountId: accInfo.accountId,
    tokenAddress: nftTokenAddress,
    requestType: sdk.OffchainNFTFeeReqType.NFT_MINT,
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,
    forceToMint: true, // suggest use as false, for here is just for run test
  chainId: sdk.ChainId.GOERLI,
  walletType: sdk.ConnectorNames.Unknown,
  apiKey: apiKey,

Congratulations! You have now minted your counterfactual NFT!

Last updated