add withdraw example
MODIFY
.eslintrc.js
.eslintrc.js
@@ -8,6 +8,7 @@ module.exports = {
require: true,
process: true,
module: true,
+ setTimeout: true,
},
rules: {
'space-before-function-paren': ['error', 'never'],

MODIFY
examples/node/deposit.js
examples/node/deposit.js
const Matic = require('maticjs').default
const config = require('./config')
-const token = '0x343461c74133E3fA476Dbbc614a87473270a226c' // test token address
+const token = '0x670568761764f53E6C10cd63b71024c31551c9EC' // test token address
const amount = '10000000000000000' // amount in wei
const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address

MODIFY
examples/node/withdraw.js
examples/node/withdraw.js
const Matic = require('maticjs').default
const config = require('./config')
-const mtoken = '0x670568761764f53E6C10cd63b71024c31551c9EC' // test token address
+const mtoken = '0x343461c74133E3fA476Dbbc614a87473270a226c' // test token address
const amount = '10000000000000000' // amount in wei
const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
@@ -18,19 +18,36 @@ matic.wallet = '<private-key>' // prefix with `0x`
var transactionHash = null
+function sleepFor(timeInMilliSeconds = 1000) {
+ return new Promise(resolve => {
+ setTimeout(resolve, timeInMilliSeconds)
+ })
+}
+
matic
.startWithdraw(mtoken, amount, {
from,
onTransactionHash: txHash => {
transactionHash = txHash
+ // console.log(transactionHash)
},
})
- .then(() => {
+ .then(async() => {
+ await sleepFor(5000)
+ // submit checkpoint (this is for tetsing purpose only)
+ matic
+ ._apiCall({
+ url: `${config.SYNCER_URL}/block/submit-checkpoint`,
+ })
+ .then(async() => {
// wait till checkpoint is submitted, then only procced
+ await sleepFor(15000)
matic.withdraw(transactionHash, {
from,
onTransactionHash: () => {
// action on Transaction success
+ // console.log('tx', tx)
},
})
})
+ })

MODIFY
src/index.js
src/index.js
@@ -393,6 +393,7 @@ export default class Matic {
'`from` required in options or set wallet using maticObject.wallet = <private key>'
)
}
+
const [gasLimit, gasPrice, nonce, chainId] = await Promise.all([
!(options.gasLimit || options.gas)
? await txObject.estimateGas({ from, value: options.value })

add withdraw example