Transfer ERC20

Send ERC20 tokens to another account on Loopring L2

The SDK provides the ability to transfer a supported ERC20 token to another account on Loopring Layer2.

Trade value should with decimals

sdk.toBig(value).times("1e" + TOKEN_INFO.tokenMap.LRC.decimals)

const { exchangeInfo } = await LoopringAPI.exchangeAPI.getExchangeInfo();
const LOOPRING_EXPORTED_ACCOUNT.exchangeAddress =  exchangeInfo;
Step 1: Get account Info
const { accInfo } = await LoopringAPI.exchangeAPI.getAccount({
  owner: LOOPRING_EXPORTED_ACCOUNT.address,
});
console.log("accInfo:", accInfo);p
Step 2: Get eddsaKey
const eddsaKey = await signatureKeyPairMock(accInfo);
console.log("eddsaKey:", eddsaKey.sk);
Step 3: Get apikey
const { apiKey } = await LoopringAPI.userAPI.getUserApiKey(
  {
    accountId: accInfo.accountId,
  },
  eddsaKey.sk
);
console.log("apiKey:", apiKey);
const { userBalances } = await LoopringAPI.userAPI.getUserBalances(
  { accountId: LOOPRING_EXPORTED_ACCOUNT.accountId, tokens: "" },
  apiKey
);
Step 4: Get storageId
const storageId = await LoopringAPI.userAPI.getNextStorageId(
  {
    accountId: accInfo.accountId,
    sellTokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
  },
  apiKey
);
console.log("storageId:", storageId);
Step 5: Get fee
Step 6: Transfer

Last updated

Was this helpful?