breaking withdraw into 2 separate files
MODIFY
examples/node/config.js
examples/node/config.js
@@ -7,8 +7,8 @@ module.exports = {
WATCHER_URL: 'https://ropsten-watcher.api.matic.network/api/v1',
MATICWETH_ADDRESS: '0xd27Ba7002CAa42C220F1Aa8aC8b9AD648E8301b0',
PRIVATE_KEY:
- '0x03599966360596FFC19F0E3E98371BD115910107016D90D5E8427B661ECA47A0',
- FROM_ADDRESS: '0xdea6D214E7505391FD64405fE8fbA206C2073Ee4',
+ '',
+ FROM_ADDRESS: '0x6d8020A6427C50fD490d90266AA8F55A38a6A76b',
MATIC_TOKEN: '0xba3204eb2d2b3d9c2071BA9310d7155B2ED1Fd63',
TEST_TOKEN: '0x48d35e70b279927ec4869c0679900a726ef1728e',
ERC721_TOKEN:'0xfeb14bc6aaf5d39fa43ff51ed94e6c260539e296',

ADD
examples/node/confirm-withdraw.js
+// const Matic = require('maticjs').default
+const Matic = require('../../lib/index').default
+const config = require('./config')
+
+const from = config.FROM_ADDRESS // from address
+
+// Create object of Matic
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChainAddress: config.ROOTCHAIN_ADDRESS,
+ syncerUrl: config.SYNCER_URL,
+ watcherUrl: config.WATCHER_URL,
+})
+
+matic.wallet = config.PRIVATE_KEY // prefix with `0x`
+
+var transactionHash = '0x38952f3fe7828d13ebe0268163e522930a606e6ec46133326fc5d64d0c818f10'
+
+//Wait for 5 mins till the checkpoint is submitted, then run the confirm withdraw
+matic.withdraw(transactionHash, {
+ from,
+ onTransactionHash: () => {
+ // action on Transaction success
+// console.log('Withdraw complete',txHash)
+ },
+})
\ No newline at end of file

MODIFY
examples/node/deposit.js
examples/node/deposit.js
const Matic = require('../../lib/index').default
const config = require('./config')
-const token = config.KOVAN_TEST // test token address
-const amount = '1000000000000000000' // amount in wei
+const token = config.TEST_TOKEN // test token address
+const amount = '10000000000000000' // amount in wei
const from = config.FROM_ADDRESS // from address
// Create object of Matic

ADD
examples/node/initiate-withdraw.js
+// const Matic = require('maticjs').default
+const Matic = require('../../lib/index').default
+const config = require('./config')
+
+// const mtoken = '0xca3C863EE5a4aFD2FCcADC5427dDBd7C28B254b0' // test token address
+const mtoken = config.MATIC_TOKEN // Matic child token address
+const amount = '10000000000000000' // amount in wei (0.01 TEST)
+const from = config.FROM_ADDRESS // from address
+
+// Create object of Matic
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChainAddress: config.ROOTCHAIN_ADDRESS,
+ syncerUrl: config.SYNCER_URL,
+ watcherUrl: config.WATCHER_URL,
+})
+
+matic.wallet = config.PRIVATE_KEY // prefix with `0x`
+
+// Initiate the withdraw on the Matic chain, and wait for ~5 minutes for
+// the checkpoint (refer https://whitepaper.matic.network/#checklayer for technical details)
+// before confirming the withdraw by executing `confirm-withdraw.js`.
+// The txHash from the output needs to be copied to the `confirm-withdraw.js` file before executing
+matic
+ .startWithdraw(mtoken, amount, {
+ from,
+ onTransactionHash: () => {
+ // console.log("Withdraw Initiated")
+ // console.log(txHash)
+ },
+})
\ No newline at end of file

MODIFY
examples/node/transfer.js
examples/node/transfer.js
-const Matic = require('maticjs').default
+// const Matic = require('maticjs').default
+const Matic = require('../../lib/index').default
const config = require('./config')
const from = config.FROM_ADDRESS // from address
-const to = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // to address
+const to = '0x732Ef34f3c8D9dE1855aEd5630C3C4071031eb5b' // to address
-const token = config.TEST_TOKEN // test token address
-const amount = '1000000000000000000' // amount in wei
+const token = config.MATIC_TOKEN // test token address
+const amount = '10000000000000000' // amount in wei
// Create object of Matic
const matic = new Matic({

MODIFY
examples/node/withdraw-testing.js
examples/node/withdraw-testing.js
-const Matic = require('maticjs').default
+// const Matic = require('maticjs').default
+const Matic = require('../../lib/index').default
const config = require('./config')
-const mtoken = '0x343461c74133E3fA476Dbbc614a87473270a226c' // test token address
+const mtoken = config.MATIC_TOKEN // test token address
const amount = '10000000000000000' // amount in wei
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const from = config.FROM_ADDRESS // from address
// Create object of Matic
const matic = new Matic({
@@ -29,18 +30,21 @@ matic
from,
onTransactionHash: txHash => {
transactionHash = txHash
- // console.log(transactionHash)
+ // console.log(txHash)
},
})
.then(async() => {
+ // console.log('Sleeping for 5 seconds')
await sleepFor(5000)
// submit checkpoint (this is for tetsing purpose only)
+ // console.log('Submitting checkpoint')
matic
._apiCall({
url: `${config.SYNCER_URL}/block/submit-checkpoint`,
})
.then(async() => {
// wait till checkpoint is submitted, then only procced
+ // console.log('Sleeping for 5 seconds')
await sleepFor(15000)
matic.withdraw(transactionHash, {
from,

breaking withdraw into 2 separate files