add example for send ethers
MODIFY
examples/node/config.js
examples/node/config.js
module.exports = {
- 'MATIC_PROVIDER': 'https://testnet.matic.network',
- 'PARENT_PROVIDER': 'https://kovan.infura.io/matic',
- 'ROOTCHAIN_ADDRESS': '0x24e01716a6ac34d5f2c4c082f553d86a557543a7',
- 'SYNCER_URL': 'https://eth-syncer.api.matic.network/api/v1',
- 'WATCHER_URL': 'https://eth-watcher.api.matic.network/api/v1',
+ MATIC_PROVIDER: 'https://testnet.matic.network',
+ PARENT_PROVIDER: 'https://kovan.infura.io/matic',
+ ROOTCHAIN_ADDRESS: '0x24e01716a6ac34d5f2c4c082f553d86a557543a7',
+ SYNCER_URL: 'https://eth-syncer.api.matic.network/api/v1',
+ WATCHER_URL: 'https://eth-watcher.api.matic.network/api/v1',
+ MATICWETH_ADDRESS: '0xeD3CAFb4dCf835E7a1D2E3169F8D296f931b4aA7',
}

MODIFY
examples/node/deposit.js
examples/node/deposit.js
const Matic = require('maticjs').default
const config = require('./config')
-const token = '0xC4375B7De8af5a38a93548eb8453a498222C4fF2' // test token address
-const amount = '10000000000000000'
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // test user address
+const token = '0x343461c74133E3fA476Dbbc614a87473270a226c' // test token address
+const amount = '10000000000000000' // amount in wei
+const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
// Create object of Matic
const matic = new Matic({
@@ -14,7 +14,7 @@ const matic = new Matic({
watcherUrl: config.WATCHER_URL,
})
-matic.wallet = '<private-key>'
+matic.wallet = '<private-key>' // prefix with `0x`
// Approve token
matic

DELETE
examples/node/index.js
-const Matic = require('maticjs').default
-const config = require('./config')
-
-const token = '0xC4375B7De8af5a38a93548eb8453a498222C4fF2' // test token address
-const user = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // test user address
-const amount = '10000000000000000'
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // test user 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 = '<Private key>'
-
-var transactionHash = null
-
-// Send Tokens
-matic.transferTokens(token, user, amount, {
- from,
- onTransactionHash: () => {
- // action on Transaction success
- },
-})
-
-// Approve token
-matic.approveTokensForDeposit(token, amount, {
- from,
- onTransactionHash: () => {
- // action on Transaction success
- },
-})
-
-// Deposit tokens
-matic.depositTokens(token, from, amount, {
- from,
- onTransactionHash: () => {
- // action on Transaction success
- },
-})
-
-// Withdraw tokens
-matic.startWithdraw(token, amount, {
- from,
- onTransactionHash: txHash => {
- transactionHash = txHash
- },
-})
-
-// submit Proof
-
-matic.withdraw(transactionHash, {
- from,
- onTransactionHash: () => {
- // action on Transaction success
- },
-})

MODIFY
examples/node/package-lock.json
examples/node/package-lock.json
"mime-types": "~2.1.18"
}
},
- "typedarray-to-buffer": {
- "version": "3.1.5",
- "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
- "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
- "requires": {
- "is-typedarray": "^1.0.0"
- }
- },
"ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
"integrity": "sha512-wAnENuZx75T5ZSrT2De2LOaUuPf2yRjq1VfcbD7+Zd79F3DZZLBJcPyCNVQ1U0fAXt0wfgCKl7sVw5pffqR9Bw==",
"requires": {
"underscore": "1.8.3",
- "web3-core-helpers": "1.0.0-beta.36",
- "websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2"
+ "web3-core-helpers": "1.0.0-beta.36"
+ },
+ "dependencies": {
+ "websocket": {
+ "version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
+ "from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
+ "requires": {
+ "debug": "^2.2.0",
+ "nan": "^2.3.3",
+ "typedarray-to-buffer": "^3.1.2",
+ "yaeti": "^0.0.6"
+ }
+ }
}
},
"web3-shh": {
}
}
},
- "websocket": {
- "version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
- "from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible",
- "requires": {
- "debug": "^2.2.0",
- "nan": "^2.3.3",
- "typedarray-to-buffer": "^3.1.2",
- "yaeti": "^0.0.6"
- }
- },
"whatwg-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"object-keys": "~0.4.0"
}
},
- "yaeti": {
- "version": "0.0.6",
- "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
- "integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc="
- },
"yauzl": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",

ADD
examples/node/sendEthers.js
+const Matic = require('maticjs').default
+const config = require('./config')
+
+const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const to = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // to address
+const amount = '1000000000000000' // 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,
+ maticWethAddress: config.MATICWETH_ADDRESS,
+})
+
+matic.wallet = '<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: () => {
+ // action on Transaction success
+ },
+})

MODIFY
examples/node/transfer.js
examples/node/transfer.js
const Matic = require('maticjs').default
const config = require('./config')
-const token = '0xC4375B7De8af5a38a93548eb8453a498222C4fF2' // test token address
-const user = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // test user address
-const amount = '10000000000000000'
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // test user address
+const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
+const to = '0x7ed7f36694153ba6eff6ca6726b60f6e2bb17fcf' // to address
+
+const token = '0x670568761764f53E6C10cd63b71024c31551c9EC' // test token address
+const amount = '10000000000000000' // amount in wei
// Create object of Matic
const matic = new Matic({
@@ -13,13 +14,15 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ maticWethAddress: config.MATICWETH_ADDRESS,
})
-matic.wallet = '<private-key>'
+matic.wallet = '<private-key>' // prefix with `0x`
// Send Tokens
-matic.transferTokens(token, user, amount, {
+matic.transferTokens(token, to, amount, {
from,
+ parent: true, // For token transfer on Main network (false for Matic Network)
onTransactionHash: () => {
// action on Transaction success
},

MODIFY
examples/node/withdraw.js
examples/node/withdraw.js
const Matic = require('maticjs').default
const config = require('./config')
-const mtoken = '0xc60CEc8200513c4eAaF179783d30CdcE8DED8492' // test token address
-const amount = '10000000000000000'
-const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // test user address
+const mtoken = '0x670568761764f53E6C10cd63b71024c31551c9EC' // test token address
+const amount = '10000000000000000' // amount in wei
+const from = '0x6e0c217de3235f1d8a95605d10bcc1b36ff7996f' // from address
// Create object of Matic
const matic = new Matic({
@@ -14,7 +14,7 @@ const matic = new Matic({
watcherUrl: config.WATCHER_URL,
})
-matic.wallet = '<private-key>'
+matic.wallet = '<private-key>' // prefix with `0x`
var transactionHash = null
@@ -31,7 +31,6 @@ matic
from,
onTransactionHash: () => {
// action on Transaction success
- process.exit()
},
})
})

add example for send ethers