Example for detecting XRC20 Deposits and transferring them to admin wallet.
You can tweek the code as per your requirements.
- Call the XRC20Listener.js file in your app.js so it will start listening for new blocks on the XDC Network.
- On every new block processBlock function will be called in the XRC20Helper.js file.
- It will process the block :
- Fetch the transactions for the block for the provided contract address of the XRC20 token .
- Check whether the toAddress of any of the transactions is related to the one that we need.
- Update the details in the DB to indicate pending transfer to the required address.
- Call the adminTransferProcess function in the XRC20Helper.js file as per your required interval.
- Fetch the pending transfers to the required address from the DB.
- Check the XDC balance of the from address, if not sufficient balance, transfer the amount of XDC needed for the XRC20 to be transferred.
- Wait for the XDC to be credited, then transfer the complete XRC20 balance to the required address.