Deposit ERC20
Deposit ERC20 from Ethereum L1 to Loopring L2
This action will require a gas fee for interacting with Ethereum Layer1, please be sure the account used has enough ETH to perform the action.
Be aware there is a slight difference in processes to deposit ETH versus ERC20 tokens.
All Deposit Methods: Users should have enough
ETH
to pay for the Ethereum Gas fee (Loopring does not charge a fee for Deposit).Provider will give the Gas Price & Limit. SDK will also have a method to get the gasPrice:
const gasPrice = (await LoopringAPI.exchangeAPI.getGasPrice() ).gasPrice;
1
const response = await sdk.deposit(
2
web3,
3
LOOPRING_EXPORTED_ACCOUNT.address,
4
LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
5
TOKEN_INFO.tokenMap.ETH,
6
LOOPRING_EXPORTED_ACCOUNT.tradeETHValue,
7
0,
8
LOOPRING_EXPORTED_ACCOUNT.gasPrice,
9
LOOPRING_EXPORTED_ACCOUNT.gasLimit,
10
sdk.ChainId.GOERLI,
11
nonce,
12
true
13
);
14
15
console.log(`nonce: ${nonce} deposit_ETH: `, response);
1
const {tokenAllowances} = await LoopringAPI.exchangeAPI.getAllowances({
2
owner: LOOPRING_EXPORTED_ACCOUNT.address,
3
token: [TOKEN_INFO.tokenMap.LRC.address],
4
});
5
if (
6
tokenAllowances.has(TOKEN_INFO.tokenMap.LRC.address) &&
7
Number(tokenAllowances.get(TOKEN_INFO.tokenMap.LRC.address)) <
8
LOOPRING_EXPORTED_ACCOUNT.tradeLRCValue
9
) {
10
const nonce = await web3.eth.getTransactionCount(
11
LOOPRING_EXPORTED_ACCOUNT.address
12
);
13
await sdk.approveMax(
14
web3,
15
LOOPRING_EXPORTED_ACCOUNT.address,
16
TOKEN_INFO.tokenMap.LRC.address, // LRC address {tokenIdMap} = getTokens(); tokenIdMap['LRC']
17
LOOPRING_EXPORTED_ACCOUNT.depositAddress, //{exchangeInfo} = getExchangeInfo() exchangeInfo.depositAddress
18
LOOPRING_EXPORTED_ACCOUNT.gasPrice,
19
LOOPRING_EXPORTED_ACCOUNT.gasLimit,
20
sdk.ChainId.GOERLI,
21
nonce,
22
true
23
);
24
}
1
const response = await sdk.deposit(
2
web3,
3
LOOPRING_EXPORTED_ACCOUNT.address,
4
LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
5
TOKEN_INFO.tokenMap.LRC,
6
sdk
7
.toBig(LOOPRING_EXPORTED_ACCOUNT.tradeLRCValue)
8
.div("1e" + TOKEN_INFO.tokenMap.LRC.decimals)
9
.toNumber(),
10
0,
11
LOOPRING_EXPORTED_ACCOUNT.gasPrice,
12
LOOPRING_EXPORTED_ACCOUNT.gasLimit,
13
sdk.ChainId.GOERLI,
14
nonce,
15
true
16
);
17
18
console.log(`nonce: ${nonce} deposit_LRC: `, response);
Last modified 6mo ago