Loopring Dev Docs
Ask or search…
K

Deposit NFT

Deposit NFTs (ERC1155 and ERC721) from Ethereum Layer 1 to Loopring Layer 2
All Deposit Methods: Users should have enough ETH to pay for the Ethereum Gas fee (Loopring does not charge a fee for Deposit).
Step 1: getNFTBalance & getEthBalances
Get Layer 1 NFT balance and ETH balance
1
const {ethBalance} = await LoopringAPI.exchangeAPI.getEthBalances({
2
owner: LOOPRING_EXPORTED_ACCOUNT.address,
3
});
4
const nftBalance = await LoopringAPI.nftAPI.getNFTBalance({
5
web3,
6
account: LOOPRING_EXPORTED_ACCOUNT.address,
7
tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
8
nftId: LOOPRING_EXPORTED_ACCOUNT.nftId,
9
nftType: sdk.NFTType.ERC1155,
10
});
Step 2: isApprovedForAll
Check NFT token is approved by the Loopring exchange address
1
const isApprovedForAll = await LoopringAPI.nftAPI.isApprovedForAll({
2
web3,
3
from: LOOPRING_EXPORTED_ACCOUNT.address,
4
exchangeAddress: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
5
nftType: sdk.NFTType.ERC1155, // todo: sdk.NFTType.ERC721
6
tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
7
});
8
console.log(`check is approveNFT`, isApprovedForAll);
Step 3: approveNFT All
Approve NFT to Loopring exchange address
1
if (!isApprovedForAll) {
2
const nonce = await sdk.getNonce(
3
web3,
4
LOOPRING_EXPORTED_ACCOUNT.address
5
);
6
const approveNFT = await LoopringAPI.nftAPI.approveNFT({
7
web3,
8
from: LOOPRING_EXPORTED_ACCOUNT.address,
9
depositAddress: LOOPRING_EXPORTED_ACCOUNT.depositAddress,
10
tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
11
nftType: sdk.NFTType.ERC1155, // todo: sdk.NFTType.ERC721
12
gasPrice: LOOPRING_EXPORTED_ACCOUNT.gasPrice,
13
gasLimit: LOOPRING_EXPORTED_ACCOUNT.gasLimit,
14
chainId: sdk.ChainId.GOERLI,
15
nonce,
16
sendByMetaMask: true,
17
});
18
console.log(`nonce: ${nonce} approveNFT: ${approveNFT?.result}`);
19
}
Step 4: nonce
We will need to retrieve a Layer1 nonce in order to perform the deposit. Use the getNonce function to retrieve this for an address. Get Layer 1 nonce
1
const nonce = await sdk.getNonce(web3, LOOPRING_EXPORTED_ACCOUNT.address);
2
3
console.log(
4
`deposit: NFT, gasPrice: ${LOOPRING_EXPORTED_ACCOUNT.gasPrice}, `
5
);
Step 5: depositNFT
Deposit NFT to the Loopring exchange
1
const response = await LoopringAPI.nftAPI.depositNFT({
2
web3,
3
from: LOOPRING_EXPORTED_ACCOUNT.address,
4
exchangeAddress: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
5
nftType: sdk.NFTType.ERC1155, // todo: sdk.NFTType.ERC721
6
tokenAddress: LOOPRING_EXPORTED_ACCOUNT.nftTokenAddress,
7
nftId: LOOPRING_EXPORTED_ACCOUNT.nftId,
8
amount: 2, // todo:when sdk.NFTType.ERC721 amount: 1,
9
gasPrice: LOOPRING_EXPORTED_ACCOUNT.gasPrice,
10
gasLimit: LOOPRING_EXPORTED_ACCOUNT.gasLimit + 100000,
11
chainId: sdk.ChainId.GOERLI,
12
nonce,
13
sendByMetaMask: true,
14
});
15
console.log(`nonce: ${nonce} deposit NFT ERC1155: `, response);
Congratulations! You have successfully your Layer 1 NFT to Loopring Layer 2!