fix: update node example
ADD
examples/node/README.md
+# Basic Nodejs example
+
+## How to use
+
+### Clone the repo
+
+```bash
+git clone git@github.com:maticnetwork/matic.js.git
+```
+
+### Install and run:
+
+```bash
+cd examples/node
+npm install
+node index.js
+```

RENAME
examples/node/deposit/index.js
examples/node/deposit.js
-const Matic = require('../../../lib').default
+const Matic = require('maticjs')
const maticProvider = 'https://testnet.matic.network'
const parentProvider = 'https://kovan.infura.io/matic'

DELETE
examples/node/deposit/package.json
-{
- "name": "deposit",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "ISC"
-}

MODIFY
examples/node/index.js
examples/node/index.js
-const Matic = require('../../lib').default
+const Matic = require('maticjs')
const maticProvider = 'https://testnet.matic.network'
const parentProvider = 'https://kovan.infura.io/matic'

RENAME
examples/node/withdraw/package-lock.json
examples/node/package-lock.json
{
- "name": "withdraw",
+ "name": "maticjs-node",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
}
},
"maticjs": {
- "version": "1.0.0-beta.3",
- "resolved": "https://registry.npmjs.org/maticjs/-/maticjs-1.0.0-beta.3.tgz",
- "integrity": "sha512-mucuwcSKfDEYocPFVdIhi8TxNzGJCtEvJYGEGc+0RsyLcQH+rXLqyxVyRsVT/l/YC+nBO/BsuUpLhBNzHkxPmQ==",
+ "version": "1.0.0-beta.4",
+ "resolved": "https://registry.npmjs.org/maticjs/-/maticjs-1.0.0-beta.4.tgz",
+ "integrity": "sha512-DQnmdUMK8UdzwwtWd9PjXgu/vkloqzjrHF2C0SzTzr0ebS1IV/51/E3K3iQzaBfsFrZvbc34BIvHJ6uSeZDPeA==",
"requires": {
"@babel/polyfill": "7.0.0",
"@babel/runtime": "7.1.2",
}
}
},
- "readline": {
- "version": "1.3.0",
- "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
- "integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw="
- },
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",

ADD
examples/node/package.json
+{
+ "name": "maticjs-node",
+ "version": "1.0.0",
+ "description": "Example code to interact with Matic Network in node environment",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "keywords": [
+ "matic",
+ "js",
+ "node"
+ ],
+ "author": "Sayli Patil <sayli@matic.network>",
+ "license": "ISC",
+ "dependencies": {
+ "maticjs": "latest"
+ }
+}

RENAME
examples/node/transfer/index.js
examples/node/transfer.js
-const Matic = require('../../../lib').default
+const Matic = require('maticjs')
const maticProvider = 'https://testnet.matic.network'
const parentProvider = 'https://kovan.infura.io/matic'

DELETE
examples/node/transfer/package.json
-{
- "name": "transafer-example",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "ISC"
-}

RENAME
examples/node/withdraw/index.js
examples/node/withdraw.js
-const readline = require('readline')
-
-const Matic = require('../../../lib/index').default
+const Matic = require('maticjs')
const maticProvider = 'https://testnet.matic.network'
const parentProvider = 'https://kovan.infura.io/matic'
@@ -24,8 +22,6 @@ const matic = new Matic({
matic.wallet = '<private-key>'
var transactionHash = null
-readline.emitKeypressEvents(process.stdin)
-process.stdin.setRawMode(true)
matic
.startWithdraw(mtoken, amount, {
@@ -36,7 +32,6 @@ matic
})
.then(() => {
//wait till checkpoint is submitted, then only procced
- process.stdin.on('keypress', () => {
matic.withdraw(transactionHash, {
from,
onTransactionHash: () => {
@@ -45,6 +40,3 @@ matic
},
})
})
- // Please submit checkpoint and press any key for continue...
- // console.log('Please submit checkpoint and press any key for continue...')
- })

DELETE
examples/node/withdraw/package.json
-{
- "name": "withdraw",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "ISC",
- "dependencies": {
- "readline": "^1.3.0"
- }
-}

MODIFY
package.json
package.json
"babel:build": "babel src/ --out-dir lib/",
"webpack:build": "webpack --env build",
"build": "npm run lint && npm run clean && npm run babel:build && npm run webpack:build",
- "lint": "eslint --ext .js src test",
+ "lint": "eslint --ext .js src test examples",
"test": "mocha --require @babel/register --colors ./test/**/*.spec.js",
"test:watch": "mocha --require @babel/register --colors -w ./test/**/*.spec.js",
"test:ci": "scripts/run-test.sh",

fix: update node example