Withdraw ERC20

Withdraw ERC20 from Loopring L2 to Ethereum L1
Withdrawing an ERC20 token will move it from the Loopring Layer2 environment to Ethereum Layer1.
Trade value should with decimals sdk.toBig(value).times("1e" + TOKEN_INFO.tokenMap.LRC.decimals)
Step 1: GetAccount
1
const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
2
owner: LOOPRING_EXPORTED_ACCOUNT.address,
3
});
4
console.log("accInfo:", accInfo);
Step 2: Get eddsaKey
1
const eddsaKey = await signatureKeyPairMock(accInfo);
2
console.log("eddsaKey:", eddsaKey.sk);
Step 3: Get apiKey
1
const {apiKey} = await LoopringAPI.userAPI.getUserApiKey({
2
accountId: accInfo.accountId,
3
},
4
eddsaKey.sk
5
);
6
console.log("apiKey:", apiKey);
Step 4: Get storageId
1
const storageId = await LoopringAPI.userAPI.getNextStorageId({
2
accountId: accInfo.accountId,
3
sellTokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
4
},
5
apiKey
6
);
7
console.log("storageId:", storageId);
Step 5: Get fee
1
const fee = await LoopringAPI.userAPI.getOffchainFeeAmt({
2
accountId: accInfo.accountId,
3
requestType: sdk.OffchainFeeReqType.OFFCHAIN_WITHDRAWAL,
4
tokenSymbol: TOKEN_INFO.tokenMap["LRC"].symbol,
5
},
6
apiKey
7
);
8
console.log("fee:", fee);
Step 6: Withdraw
1
const response = await LoopringAPI.userAPI.submitOffchainWithdraw({
2
request: {
3
exchange: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
4
accountId: LOOPRING_EXPORTED_ACCOUNT.accountId,
5
counterFactualInfo: undefined,
6
fastWithdrawalMode: false,
7
hashApproved: "",
8
maxFee: {
9
tokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
10
volume: fee.fees["LRC"].fee ?? "9400000000000000000",
11
},
12
minGas: 0,
13
owner: LOOPRING_EXPORTED_ACCOUNT.address,
14
to: LOOPRING_EXPORTED_ACCOUNT.address,
15
storageId: 0,
16
token: {
17
tokenId: TOKEN_INFO.tokenMap.LRC.tokenId,
18
volume: LOOPRING_EXPORTED_ACCOUNT.tradeLRCValue.toString(),
19
},
20
validUntil: 0,
21
},
22
web3,
23
chainId: sdk.ChainId.GOERLI,
24
walletType: sdk.ConnectorNames.MetaMask,
25
eddsaKey: eddsaKey.sk,
26
apiKey,
27
});
28
console.log("response:", response);