Deposit and Checkpoint Event Tracking – Plasma
When a token is deposited from Ethereum to Matic, a process called state sync mechanism comes into play that eventually mints the tokens for the user on the Matic chain. This process takes about ~5-7 minutes to happen and hence listening to the deposit event is very important to create a good user experience. This is an example script that can be used to track real time deposit events.
Realtime deposit event tracking using a web socket connection
Historical deposit completion check by querying the blockchain.
This script can be used to check if a particular deposit has been completed on the child chain or not. The main chain and the child chain keep incrementing the value of a global counter variable on both the chains. The StateSender contract emits an event that has the counter value. The counter value on the child chain can be queried from the StateReceiver contract. If the counter value on child chain is greater than or equal to the same on main chain, then the deposit can considered as completed successfully.
Real-time checkpoint status tracking
All transactions that occur on Matic chain are check-pointed to the Ethereum chain in frequent intervals of time by the validators. This time is ~10 mins on Mumbai and ~30 mins on Matic mainnet. The checkpoint occurs on a contract called the RootChain contract deployed on Ethereum chain. The following script can be used to listen to Real-time checkpoint inclusion events.
Historical checkpoint inclusion check by querying the blockchain.
This can be checked using the following API. The block number of the burn transaction on the child chain has to be given as a param to this GET API.// Testnethttps://apis.matic.network/api/v1/mumbai/block-included/block-number// Mainnethttps://apis.matic.network/api/v1/matic/block-included/block-number
Originally published @ https://docs.matic.network/docs/develop/ethereum-matic/plasma/deposit-withdraw-event-plasma