add transfer ethers examples and fix config
MODIFY
examples/node/config.js
examples/node/config.js
@@ -9,6 +9,7 @@ module.exports = {
MATICWETH_ADDRESS: '0xFCbE295b918848001eB43941Db3fF9b6439a5e13',
PRIVATE_KEY:
'0xecdccb2bded99cfd3fbcc47fe9add154cf861940e10ba77a492bfa1ca89bee8d',
+ FROM_ADDRESS: '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f',
TEST_TOKEN: '0x7c779D7353d746535E6dBDb7edA2E457262C5a7d',
KOVAN_TEST: '0x670568761764f53E6C10cd63b71024c31551c9EC',
}

MODIFY
examples/node/deposit.js
examples/node/deposit.js
@@ -2,8 +2,8 @@ const Matic = require('maticjs').default
const config = require('./config')
const token = config.KOVAN_TEST // test token address
-const amount = '4200000000000000000000000000000' // amount in wei
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const amount = '1000000000000000000' // amount in wei
+const from = config.FROM_ADDRESS // from address
// Create object of Matic
const matic = new Matic({
@@ -12,6 +12,7 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ depositManagerAddress: config.DEPOSITMANAGER_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`

MODIFY
examples/node/depositEther.js
examples/node/depositEther.js
const Matic = require('maticjs').default
const config = require('./config')
-const token = config.KOVAN_TEST // test token address
-const amount = '4200000000000000000000000000000' // amount in wei
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const amount = '1000000000000000000' // amount in wei
+const from = config.FROM_ADDRESS // from address
// Create object of Matic
const matic = new Matic({
@@ -12,6 +11,8 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ withdrawManagerAddress: config.WITHDRAWMANAGER_ADDRESS,
+ depositManagerAddress: config.DEPOSITMANAGER_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`

MODIFY
examples/node/transfer.js
examples/node/transfer.js
const Matic = require('maticjs').default
const config = require('./config')
-const from = '0x6E0c217dE3235F1D8a95605d10bCC1B36ff7996f' // from address
+const from = config.FROM_ADDRESS // from address
const to = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // to address
const token = config.TEST_TOKEN // test token address
-const amount = '1' // amount in wei
+const amount = '1000000000000000000' // amount in wei
// Create object of Matic
const matic = new Matic({
@@ -14,7 +14,6 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
- maticWethAddress: config.MATICWETH_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`

ADD
examples/node/transferEthers.js
+const Matic = require('maticjs').default
+const config = require('./config')
+
+const from = config.FROM_ADDRESS // from address
+const to = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // to address
+
+const amount = '1000000000000000000' // amount in wei
+
+// 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`
+
+// Send Tokens
+matic.transferEthers(to, amount, {
+ from,
+ // parent: true, // For token transfer on Main network (false for Matic Network)
+ onTransactionHash: tx => {
+ // action on Transaction success
+ console.log(tx)
+ },
+})

MODIFY
examples/node/withdraw.js
examples/node/withdraw.js
const Matic = require('maticjs').default
const config = require('./config')
-const mtoken = config.TEST_TOKEN // test token address
-const amount = '10000000000000000' // amount in wei
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const token = config.TEST_TOKEN // test token address
+const amount = '1000000000000000000' // amount in wei
+const from = config.FROM_ADDRESS // from address
// Create object of Matic
const matic = new Matic({
@@ -12,6 +12,7 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ withdrawManagerAddress: config.WITHDRAWMANAGER_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`
@@ -19,14 +20,15 @@ matic.wallet = config.PRIVATE_KEY // prefix with `0x`
var transactionHash =
'0x4b4879943dbc209794741807214df8fb1da06c751ae6e4d6ffdf5aad64c17936'
-// matic.startWithdraw(mtoken, amount, {
-// from,
-// onTransactionHash: txHash => {
-// transactionHash = txHash
-// console.log(txHash)
-// },
-// })
-// .then(() => {
+matic
+ .startWithdraw(token, amount, {
+ from,
+ onTransactionHash: txHash => {
+ transactionHash = txHash
+ console.log(txHash)
+ },
+ })
+ .then(() => {
//wait till checkpoint is submitted, then only procced
matic.withdraw(transactionHash, {
from,
@@ -35,4 +37,4 @@ matic.withdraw(transactionHash, {
console.log(tx)
},
})
-// })
+ })

MODIFY
src/index.js
src/index.js
@@ -113,6 +113,20 @@ export default class Matic {
return this._tokenMappedCache[_a]
}
+ async depositEthers(user, options = {}) {
+ if (options && (!options.from || !user || !options.value)) {
+ throw new Error('Missing Parameters')
+ }
+ const depositTx = this._rootChainContract.methods.depositEthers(user)
+ const _options = await this._fillOptions(
+ options,
+ depositTx,
+ this._parentWeb3
+ )
+
+ return this._wrapWeb3Promise(depositTx.send(_options), options)
+ }
+
async approveTokensForDeposit(token, amount, options = {}) {
if (options && (!options.from || !amount || !token)) {
throw new Error('Missing Parameters')
@@ -134,20 +148,6 @@ export default class Matic {
return this._wrapWeb3Promise(approveTx.send(_options), options)
}
- async depositEthers(user, options = {}) {
- if (options && (!options.from || !user || !options.value)) {
- throw new Error('Missing Parameters')
- }
- const depositTx = this._rootChainContract.methods.depositEthers(user)
- const _options = await this._fillOptions(
- options,
- depositTx,
- this._parentWeb3
- )
-
- return this._wrapWeb3Promise(depositTx.send(_options), options)
- }
-
async depositTokens(token, user, amount, options = {}) {
if (options && (!options.from || !token || !user || !amount)) {
throw new Error('Missing Parameters')

add transfer ethers examples and fix config