High Level Flow
Deposit ERC1155 -
- Approve ERC1155Predicate contract to spend the tokens that have to be deposited.
- Make depositFor call on RootChainManager.
Withdraw ERC1155 -
- Burn tokens on matic chain.
- Call exit function on RootChainManager to submit proof of burn transaction. This call can be made after checkpoint is submitted for the block containing burn transaction.
Configuring Matic SDK
Install Matic SDK (2.0.2)
While creating MaticPOSClient object network,version,maticProvider, parentProvider, posERC1155Predicate and posRootChainManager need to be provided.
This is a normal ERC1155 approval so that ERC1155Predicate can call transferFrom function. Matic POS client exposes approveERC1155ForDeposit method to make this call.
Deposit can be done by calling depositFor on RootChainManager contract. Note that token needs to be mapped and approved for transfer beforehand. Once tokens are transferred deposit proceeds using StateSync mechanism. Matic POS client exposes depositSingleERC1155ForUser & depositBatchERC1155ForUser method to make this call.
deposit function of ChildToken is called by the ChildChainManager. Tokens should be minted when this call is made.
User can call withdraw function of ChildToken contract. This function should burn the tokens. Matic POS client exposes burnSingleERC1155 & burnBatchERC1155 method to make this call.
Store the transaction hash for this call and use it while generating burn proof.
Once the checkpoint has been submitted for the block containing burn transaction, user should call the exit function of RootChainManager contract and submit the proof of burn. Upon submitting valid proof tokens are transferred to the user. Matic POS client exposes exitBatchERC1155 & exitSingleERC1155 method to make this call.