Asset deposits and withdrawals
Asset deposits and withdrawals
Applications may want to enable users to:
Deposit assets on L1 to L2 (note these pre-requisites)
Withdraw assets from L2 to L1
For more information and use cases, see our explanatory article, Deep dive into deposits and withdrawals.
Deposit pre-requisites:
The user depositing the asset must be registered with XpansionChain
The user must own the asset on L1
The L1 smart contract holding the asset must be registered as a collection
📝GUIDES
Core SDK
API
Link SDK:
Deposits
Prepare withdrawal and complete withdrawal
Core SDK
1. Initialize the Core SDK
In order to use the Core SDK, you need to initialize it.
2. Generate signers
Enabling users to transfer assets requires a user's signature, so your application will need to create signers. See the guide on how to generate signers.
3. Deposit assets onto L2
Typescript Core SDK
📚SDK REFERENCE
deposit
The function below will deposit ETH from L1 to L2. If you wish to deposit a different asset, you can change type to either ERC20 or ERC721 and specify the asset address as an additional parameter.
Example response
Kotlin (JVM) Core SDK
📚SDK REFERENCE
Deposits API
Swift Core SDK
📚SDK REFERENCE
Deposits API
Golang Core SDK
📚SDK REFERENCE
ETH deposit:
NewETHDeposit
(*ETHDeposit) Deposit
ERC20 deposit:
NewERC20Deposit
(*ERC20Deposit) Deposit
ERC721 deposit:
NewERC721Deposit
(*ERC721Deposit) Deposit
4. Withdraw assets to L1
Typescript Core SDK
📚SDK REFERENCE
prepareWithdrawal
completeWithdrawal
Kotlin (JVM) Core SDK
📚SDK REFERENCE
createWithdrawal
getSignableWithdrawal
Swift Core SDK
📚SDK REFERENCE
getSignableWithdrawal
createwithdrawal
Golang Core SDK
📚SDK REFERENCE
PrepareWithdrawal
Complete withdrawal for token types:
(*EthWithdrawal) CompleteWithdrawal
(*ERC20Withdrawal) CompleteWithdrawal
(*ERC721Withdrawal) CompleteWithdrawal
💻EXAMPLE
Withdrawal
API
Deposit
Withdrawal
Deposit
To understand what is going on under the hood with asset deposits, please see this explainer.
Steps:
Get details of the deposit
Generate signers
Call contract method to deposit tokens
1. Get details of the deposit
💡ENDPOINT:
getSignableDeposit
Javascript example of depositing ETH from L1 to L2:
Example response:
The following response params are used in the depositEth contract method (see Step 3):
stark_keyvault_id
2. Generate signers
Enabling users to deposit assets requires a user's signature, so your application will need to create signers. See the guide on how to generate signers.
3. Call contract method to deposit tokens
Withdrawal
To understand what is going on under the hood with asset withdrawals, please see this explainer.
Steps:
Get details of the withdrawal
Generate signers
Create withdrawal
Call contract to complete withdrawal
1. Get details of the withdrawal
💡ENDPOINT:
getSignableWithdrawal
Javascript example of withdrawing ETH from L2 to L1:
Example response:
Explanation:
Response param
Description
How is it used in the createWithdrawal request? (See Step 3)
amount
Amount of token to be withdrawn to L1
As amount in the request body
asset_id
ID of the asset this user is withdrawing (applicable only to ERC721 asset type)
As asset_id in the request body
nonce
Random number generated of this transaction to verify that specific values are not reused
As nonce in the request body
payload_hash
Encoded payload hash
Used to generate the stark_signature in the request body by using the Stark (L2) signer to sign the payload_hash.
signable_message
Message to sign with L1 wallet to verity withdrawal request
Used to generate the x-imx-eth-signature header by using the Ethereum (L1) signer to sign the signable_message
stark_key
Public stark key of the withdrawing user
As stark_key in the request body
vault_id
The ID of the vault the asset belong to
As vault_id in the request body
2. Generate signers
Enabling users to withdraw assets requires a user's signature, so your application will need to create signers. See the guide on how to generate signers.
3. Create withdrawal
💡ENDPOINT:
createWithdrawal
Javascript example of withdrawing ETH from L2 to L1:
4. Get the assetType value
This value is required in the next step to complete the withdrawal.
5. Call contract to complete withdrawal
Last updated