Withdraw NFT

Withdraw Loopring L2 NFT to Ethereum L1

When token is not deployed the fee is different:

deployInWithdraw: tokenInfo?.deploymentStatus === DEPLOYMENT_STATUS.NOT_DEPLOYED

chevron-rightStep 1: Get Accounthashtag

Prepare 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

Generate 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 NFT tokenId storageId

const storageId = await LoopringAPI.userAPI.getNextStorageId(
  {
    accountId: accInfo.accountId,
    sellTokenId: LOOPRING_EXPORTED_ACCOUNT.nftTokenId,
  },
  apiKey
);
console.log("storageId:", storageId);

//Step 5. getUserNFTBalances
const {userNFTBalances} = await LoopringAPI.userAPI.getUserNFTBalances(
  {accountId: LOOPRING_EXPORTED_ACCOUNT.accountId},
  apiKey
);
const tokenInfo = userNFTBalances.find(
  (item) =>
    item.tokenAddress?.toLowerCase() ===
    LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress.toLowerCase() &&
    item.nftId &&
    web3.utils.hexToNumberString(item.nftId) ===
    LOOPRING_EXPORTED_ACCOUNT.nftTokenId.toString()
);
chevron-rightStep 5: Withdraw feehashtag

Get withdrawal fee.

If the tokenAddress hasn't been deployed, deployInWithdraw set to true will retrieve the deployment fee plus withdrawal fee.

If the tokenAddress is deployed, deployInWithdraw set to true will return withdrawal fee.

const fee = await LoopringAPI.userAPI.getNFTOffchainFeeAmt(
  {
    accountId: accInfo.accountId,
    requestType: sdk.OffchainNFTFeeReqType.NFT_WITHDRAWAL,
    tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
    deployInWithdraw:
      tokenInfo?.deploymentStatus === DEPLOYMENT_STATUS.NOT_DEPLOYED, // when token is not deploy the fee is diff
  },
  apiKey
);
console.log("fee:", fee);
chevron-rightStep 6: Withdrawhashtag
circle-check

Last updated