check deposit success on matic chain by deposit id or deposit transaction hash
MODIFY
examples/node/config.js
examples/node/config.js
@@ -9,6 +9,7 @@ module.exports = {
SYNCER_URL: 'https://testnetv3-syncer.api.matic.network/api/v1', // Backend service which syncs the Matic sidechain state to a MySQL database which we use for faster querying. This comes in handy especially for constructing withdrawal proofs while exiting assets from Plasma.
WATCHER_URL: 'https://testnetv3-watcher.api.matic.network/api/v1', // Backend service which syncs the Matic Plasma contract events on Ethereum mainchain to a MySQL database which we use for faster querying. This comes in handy especially for listening to asset deposits on the Plasma contract.
ROOTWETH_ADDRESS: '0x7BdDd37621186f1382FD59e1cCAE0316F979a866', // This is a wrapped ETH ERC20 contract address so that we can support ETH deposits to the sidechain
+ CHILDCHAIN_ADDRESS: '0xa2EF03edfA084ac9e5Bf110e409Ed5483BAe4101', // This is child chain contract address
MATICWETH_ADDRESS: '0x8567184E6F9b1B77f24AfF6168453419AD22f90e', // The corresponding wrapped ETH ERC20 contract address on the Matic chain
PRIVATE_KEY: '<paste your private key here>', // A sample private key prefix with `0x`
FROM_ADDRESS: '<paste address belonging to private key here>',// Your address

ADD
examples/node/deposit-data.js
+const bn = require('bn.js')
+
+const Matic = require('../../dist/index').default
+const config = require('./config')
+const utils = require('./utils')
+
+const token = config.PARENT_TEST_TOKEN
+const amount = new bn(1).mul(utils.SCALING_FACTOR)
+const from = config.FROM_ADDRESS
+
+// Create Matic object
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ registry: config.REGISTRY_ADDRESS,
+ depositManager: config.DEPOSITMANAGER_ADDRESS,
+ withdrawManager: config.WITHDRAWMANAGER_ADDRESS,
+ childChain: config.CHILDCHAIN_ADDRESS,
+})
+
+async function execute() {
+ await matic.initialize()
+ matic.setWallet(config.PRIVATE_KEY)
+ // return matic.depositDataByHash('0x8cff1ef2b198273fe7f9fb41918cd7e3e8d04c58650614af39b3086e1de1a7e6')
+ return matic.depositManager.depositDataByID(101230019, '0xa2EF03edfA084ac9e5Bf110e409Ed5483BAe4101')
+}
+
+async function executeRaw() { // eslint-disable-line
+ await matic.initialize()
+ let txParams = await matic.approveERC20TokensForDeposit(token, amount, { from, encodeAbi: true })
+ let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
+ await matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+
+ txParams = await matic.depositERC20ForUser(token, from, amount, { from, encodeAbi: true })
+ serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
+ return matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+}
+
+execute().then(console.log) // eslint-disable-line

MODIFY
package.json
package.json
},
"lint-staged": {
"linters": {
- "*.{ts,js}": [
+ "*.ts": [
"eslint --fix src",
"git add"
]

MODIFY
src/index.ts
src/index.ts
@@ -14,6 +14,7 @@ export default class Matic extends ContractsBase {
public rootChain: RootChain
public withdrawManager: WithdrawManager
public registry: Registry
+ public childChainAddress: address
constructor(options: any = {}) {
const web3Client = new Web3Client(
@@ -36,6 +37,7 @@ export default class Matic extends ContractsBase {
this.web3Client,
this.registry,
)
+ this.childChainAddress = options.childChain
}
initialize() {
@@ -156,6 +158,24 @@ export default class Matic extends ContractsBase {
return this.depositManager.depositEther(amount, options)
}
+ async depositDataByHash(txHash: string) {
+ const depositReceipt = await this.web3Client.parentWeb3.eth.getTransactionReceipt(txHash)
+ if(!depositReceipt) {
+ return 'Transaction hash is not Found'
+ }
+ const newDepositEvent = depositReceipt.logs.find(
+ l => l.topics[0].toLowerCase() === DepositManager.NEW_DEPOSIT_EVENT_SIG,
+ )
+
+ const data = newDepositEvent.data
+ const depositId = parseInt(data.substring(data.length - 64), 16)
+ const depositExists = await this.depositManager.depositDataByID(depositId, this.childChainAddress)
+ if (!depositExists) {
+ return 'Deposit is not processed on Matic chain'
+ }
+ return depositReceipt
+ }
+
approveERC20TokensForDeposit(
token: address,
amount: BN | string,

MODIFY
src/root/DepositManager.ts
src/root/DepositManager.ts
import BN from 'bn.js'
import Contract from 'web3/eth/contract'
import DepositManagerArtifact from 'matic-protocol/contracts-core/artifacts/DepositManager.json'
+import ChildChainArtifact from 'matic-protocol/contracts-core/artifacts/ChildChain.json'
import ContractsBase from '../common/ContractsBase'
import { address, SendOptions } from '../types/Common'
import Web3Client from '../common/Web3Client'
export default class DepositManager extends ContractsBase {
+ static NEW_DEPOSIT_EVENT_SIG = '0x1dadc8d0683c6f9824e885935c1bec6f76816730dcec148dda8cf25a7b9f797b'.toLowerCase()
+
public depositManagerContract: Contract
constructor(depositManager: address, web3Client: Web3Client) {
@@ -17,6 +20,14 @@ export default class DepositManager extends ContractsBase {
)
}
+ async depositDataByID(depositId: number, childChainAddress: address) {
+ const childChainContract = new this.web3Client.web3.eth.Contract(
+ ChildChainArtifact.abi,
+ childChainAddress
+ )
+ return childChainContract.methods.deposits(this.encode(depositId)).call()
+ }
+
async approveERC20(
token: address,
amount: BN | string,

check deposit success on matic chain by deposit id or deposit transaction hash