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 MetaNFT.md for additional details.

chevron-rightStep 1: Get Accounthashtag

Prepare your Loopring Layer 2 account. Retrieve account information.

const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
  owner: LOOPRING_EXPORTED_ACCOUNT.address,
});
console.log("accInfo:", accInfo);
chevron-rightStep 2: Get eddsaKeyhashtag

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);
chevron-rightStep 3: Get apiKeyhashtag

Retrieve the account's API key.

const {apiKey} = await LoopringAPI.userAPI.getUserApiKey(
  {
    accountId: accInfo.accountId,
  },
  eddsaKey.sk
);
console.log("apiKey:", apiKey);
chevron-rightStep 4: Get storageIdhashtag

Get fee token storageId

const storageId = await LoopringAPI.userAPI.getNextStorageId(
  {
    accountId: accInfo.accountId,
    sellTokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId, // same as maxFee tokenId
  },
  apiKey
);
chevron-rightStep 5: Get tokenAddresshashtag

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
 .getUserOwenCollection({
   owner: accInfo.owner,
   isMintable: true
  },
  apiKey
 )
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,
chevron-rightStep 6: Get feehashtag

Retrieve the mint fee.

chevron-rightStep 7: Minthashtag

Mint the NFT

circle-check

Last updated