implement getTOkensCount, getAllTokens in pos erc721
MODIFY
examples/config.js
examples/config.js
-// Testnet V3 config
+const dotenv = require('dotenv');
+const path = require('path');
+const env = dotenv.config({
+ path: path.join(__dirname, '.env')
+});
+
module.exports = {
plasma: {
parent: {
@@ -15,10 +20,10 @@ module.exports = {
depositManagerAddress: '0x3Bc6701cA1C32BBaC8D1ffA2294EE3444Ad93989', // An address for a DepositManager contract in Ropsten testnet
},
parent: {
- rpc: '<goerli RPC>',
+ rpc: process.env.ROOT_RPC,
},
child: {
- rpc: 'https://rpc-mumbai.matic.today', // This is the MATIC testnet RPC
+ rpc: process.env.MATIC_RPC || 'https://rpc-mumbai.matic.today',
},
pos: {
parent: {
@@ -37,8 +42,10 @@ module.exports = {
SYNCER_URL: 'https://testnetv3-syncer.api.matic.network/api/v1', // Backend service which syncs the Matic sidechain state to a MySQL database which we use for faster querying. This comes in handy especially for constructing withdrawal proofs while exiting assets from Plasma.
WATCHER_URL: 'https://testnetv3-watcher.api.matic.network/api/v1', // Backend service which syncs the Matic Plasma contract events on Ethereum mainchain to a MySQL database which we use for faster querying. This comes in handy especially for listening to asset deposits on the Plasma contract.
user1: {
- privateKey: '<paste your private key here>', // A sample private key prefix with `0x`
- address: '<paste address belonging to private key here>', // Your address
+ // '<paste your private key here>' - A sample private key prefix with `0x`
+ privateKey: process.env.PRIVATE_KEY,
+ //'<paste address belonging to private key here>', Your address
+ address: process.env.FROM
},
user2: {
address: '<paste address here>', // Your address

MODIFY
examples/package-lock.json
examples/package-lock.json
"web3": "^1.3.0"
}
},
+ "@maticnetwork/maticjs-web3": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/@maticnetwork/maticjs-web3/-/maticjs-web3-0.1.0.tgz",
+ "integrity": "sha512-fqFKwfapbGgCTcJKgjZ1wa4ne7b0mlMBB/jqNBiQqOy9X+WggLufq7SE1P21fKU/hcfB/ub0cMaBOYEgBZwUDQ==",
+ "requires": {
+ "@maticnetwork/maticjs": "^3.0.0-beta.2",
+ "web3": "^1.6.0"
+ },
+ "dependencies": {
+ "@maticnetwork/maticjs": {
+ "version": "3.0.0-beta.2",
+ "resolved": "https://registry.npmjs.org/@maticnetwork/maticjs/-/maticjs-3.0.0-beta.2.tgz",
+ "integrity": "sha512-U1cIUqcfPtKjHbdmeRsAtJNVWawPHOFyMMHiGo2xoenl1Hvk6U1HJJ9OVkyNHuZdA5ICqpyYA4NcosOgA3ucAA==",
+ "requires": {
+ "assert": "^2.0.0",
+ "bn.js": "5.0.0",
+ "eth-sig-util": "^2.5.3",
+ "ethereumjs-block": "2.2.0",
+ "ethereumjs-tx": "1.3.7",
+ "ethereumjs-util": "^5.2.0",
+ "merkle-patricia-tree": "2.3.2",
+ "node-fetch": "^2.6.1"
+ }
+ },
+ "@types/node": {
+ "version": "12.20.33",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.33.tgz",
+ "integrity": "sha512-5XmYX2GECSa+CxMYaFsr2mrql71Q4EvHjKS+ox/SiwSdaASMoBIWE6UmZqFO+VX1jIcsYLStI4FFoB6V7FeIYw=="
+ },
+ "eth-lib": {
+ "version": "0.2.8",
+ "resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.2.8.tgz",
+ "integrity": "sha512-ArJ7x1WcWOlSpzdoTBX8vkwlkSQ85CjjifSZtV4co64vWxSV8geWfPI9x4SVYu3DSxnX4yWFVTtGL+j9DUFLNw==",
+ "requires": {
+ "bn.js": "^4.11.6",
+ "elliptic": "^6.4.0",
+ "xhr-request-promise": "^0.1.2"
+ },
+ "dependencies": {
+ "bn.js": {
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
+ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
+ }
+ }
+ },
+ "uuid": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
+ "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
+ },
+ "web3": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3/-/web3-1.6.0.tgz",
+ "integrity": "sha512-rWpXnO88MiVX5yTRqMBCVKASxc7QDkXZZUl1D48sKlbX4dt3BAV+nVMVUKCBKiluZ5Bp8pDrVCUdPx/jIYai5Q==",
+ "requires": {
+ "web3-bzz": "1.6.0",
+ "web3-core": "1.6.0",
+ "web3-eth": "1.6.0",
+ "web3-eth-personal": "1.6.0",
+ "web3-net": "1.6.0",
+ "web3-shh": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-bzz": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-bzz/-/web3-bzz-1.6.0.tgz",
+ "integrity": "sha512-ugYV6BsinwhIi0CsLWINBz4mqN9wR9vNG0WmyEbdECjxcPyr6vkaWt4qi0zqlUxEnYAwGj4EJXNrbjPILntQTQ==",
+ "requires": {
+ "@types/node": "^12.12.6",
+ "got": "9.6.0",
+ "swarm-js": "^0.1.40"
+ }
+ },
+ "web3-core": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core/-/web3-core-1.6.0.tgz",
+ "integrity": "sha512-o0WsLrJ2yD+HAAc29lGMWJef/MutTyuzpJC0UzLJtIAQJqtpDalzWINEu4j8XYXGk34N/V6vudtzRPo23QEE6g==",
+ "requires": {
+ "@types/bn.js": "^4.11.5",
+ "@types/node": "^12.12.6",
+ "bignumber.js": "^9.0.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-core-requestmanager": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-core-helpers": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core-helpers/-/web3-core-helpers-1.6.0.tgz",
+ "integrity": "sha512-H/IAH/0mrgvad/oxVKiAMC7qDzMrPPe/nRKmJOoIsupRg9/frvL62kZZiHhqVD1HMyyswbQFC69QRl7JqWzvxg==",
+ "requires": {
+ "web3-eth-iban": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-core-method": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core-method/-/web3-core-method-1.6.0.tgz",
+ "integrity": "sha512-cHekyEil4mtcCOk6Q1Zh4y+2o5pTwsLIxP6Bpt4BRtZgdsyPiadYJpkLAVT/quch5xN7Qs5ZwG5AvRCS3VwD2g==",
+ "requires": {
+ "@ethereumjs/common": "^2.4.0",
+ "@ethersproject/transactions": "^5.0.0-beta.135",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-promievent": "1.6.0",
+ "web3-core-subscriptions": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-core-promievent": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core-promievent/-/web3-core-promievent-1.6.0.tgz",
+ "integrity": "sha512-ZzsevjMXWkhqW9dnVfTfb1OUcK7jKcKPvPIbQ4boJccNgvNZPZKlo8xB4pkAX38n4c59O5mC7Lt/z2QL/M5CeQ==",
+ "requires": {
+ "eventemitter3": "4.0.4"
+ }
+ },
+ "web3-core-requestmanager": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core-requestmanager/-/web3-core-requestmanager-1.6.0.tgz",
+ "integrity": "sha512-CY5paPdiDXKTXPWaEUZekDfUXSuoE2vPxolwqzsvKwFWH5+H1NaXgrc+D5HpufgSvTXawTw0fy7IAicg8+PWqA==",
+ "requires": {
+ "util": "^0.12.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-providers-http": "1.6.0",
+ "web3-providers-ipc": "1.6.0",
+ "web3-providers-ws": "1.6.0"
+ }
+ },
+ "web3-core-subscriptions": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-core-subscriptions/-/web3-core-subscriptions-1.6.0.tgz",
+ "integrity": "sha512-kY9WZUY/m1URSOv3uTLshoZD9ZDiFKReIzHuPUkxFpD5oYNmr1/aPQNPCrrMxKODR7UVX/D90FxWwCYqHhLaxQ==",
+ "requires": {
+ "eventemitter3": "4.0.4",
+ "web3-core-helpers": "1.6.0"
+ }
+ },
+ "web3-eth": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth/-/web3-eth-1.6.0.tgz",
+ "integrity": "sha512-qJMvai//r0be6I9ghU24/152f0zgJfYC23TMszN3Y6jse1JtjCBP2TlTibFcvkUN1RRdIUY5giqO7ZqAYAmp7w==",
+ "requires": {
+ "web3-core": "1.6.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-core-subscriptions": "1.6.0",
+ "web3-eth-abi": "1.6.0",
+ "web3-eth-accounts": "1.6.0",
+ "web3-eth-contract": "1.6.0",
+ "web3-eth-ens": "1.6.0",
+ "web3-eth-iban": "1.6.0",
+ "web3-eth-personal": "1.6.0",
+ "web3-net": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-eth-abi": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.6.0.tgz",
+ "integrity": "sha512-fImomGE9McuTMJLwK8Tp0lTUzXqCkWeMm00qPVIwpJ/h7lCw9UFYV9+4m29wSqW6FF+FIZKwc6UBEf9dlx3orA==",
+ "requires": {
+ "@ethersproject/abi": "5.0.7",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-eth-accounts": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-accounts/-/web3-eth-accounts-1.6.0.tgz",
+ "integrity": "sha512-2f6HS4KIH4laAsNCOfbNX3dRiQosqSY2TRK86C8jtAA/QKGdx+5qlPfYzbI2RjG81iayb2+mVbHIaEaBGZ8sGw==",
+ "requires": {
+ "@ethereumjs/common": "^2.3.0",
+ "@ethereumjs/tx": "^3.2.1",
+ "crypto-browserify": "3.12.0",
+ "eth-lib": "0.2.8",
+ "ethereumjs-util": "^7.0.10",
+ "scrypt-js": "^3.0.1",
+ "uuid": "3.3.2",
+ "web3-core": "1.6.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-utils": "1.6.0"
+ },
+ "dependencies": {
+ "@types/bn.js": {
+ "version": "5.1.0",
+ "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-5.1.0.tgz",
+ "integrity": "sha512-QSSVYj7pYFN49kW77o2s9xTCwZ8F2xLbjLLSEVh8D2F4JUhZtPAGOFLTD+ffqksBx/u4cE/KImFjyhqCjn/LIA==",
+ "requires": {
+ "@types/node": "*"
+ }
+ },
+ "bn.js": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz",
+ "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw=="
+ },
+ "ethereumjs-util": {
+ "version": "7.1.3",
+ "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-7.1.3.tgz",
+ "integrity": "sha512-y+82tEbyASO0K0X1/SRhbJJoAlfcvq8JbrG4a5cjrOks7HS/36efU/0j2flxCPOUM++HFahk33kr/ZxyC4vNuw==",
+ "requires": {
+ "@types/bn.js": "^5.1.0",
+ "bn.js": "^5.1.2",
+ "create-hash": "^1.1.2",
+ "ethereum-cryptography": "^0.1.3",
+ "rlp": "^2.2.4"
+ }
+ }
+ }
+ },
+ "web3-eth-contract": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-contract/-/web3-eth-contract-1.6.0.tgz",
+ "integrity": "sha512-ZUtO77zFnxuFtrc+D+iJ3AzNgFXAVcKnhEYN7f1PNz/mFjbtE6dJ+ujO0mvMbxIZF02t9IZv0CIXRpK0rDvZAw==",
+ "requires": {
+ "@types/bn.js": "^4.11.5",
+ "web3-core": "1.6.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-core-promievent": "1.6.0",
+ "web3-core-subscriptions": "1.6.0",
+ "web3-eth-abi": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-eth-ens": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-ens/-/web3-eth-ens-1.6.0.tgz",
+ "integrity": "sha512-AG24PNv9qbYHSpjHcU2pViOII0jvIR7TeojJ2bxXSDqfcgHuRp3NZGKv6xFvT4uNI4LEQHUhSC7bzHoNF5t8CA==",
+ "requires": {
+ "content-hash": "^2.5.2",
+ "eth-ens-namehash": "2.0.8",
+ "web3-core": "1.6.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-promievent": "1.6.0",
+ "web3-eth-abi": "1.6.0",
+ "web3-eth-contract": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-eth-iban": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-iban/-/web3-eth-iban-1.6.0.tgz",
+ "integrity": "sha512-HM/bKBS/e8qg0+Eh7B8C/JVG+GkR4AJty17DKRuwMtrh78YsonPj7GKt99zS4n5sDLFww1Imu/ZIk3+K5uJCjw==",
+ "requires": {
+ "bn.js": "^4.11.9",
+ "web3-utils": "1.6.0"
+ },
+ "dependencies": {
+ "bn.js": {
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
+ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
+ }
+ }
+ },
+ "web3-eth-personal": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-eth-personal/-/web3-eth-personal-1.6.0.tgz",
+ "integrity": "sha512-8ohf4qAwbShf4RwES2tLHVqa+pHZnS5Q6tV80sU//bivmlZeyO1W4UWyNn59vu9KPpEYvLseOOC6Muxuvr8mFQ==",
+ "requires": {
+ "@types/node": "^12.12.6",
+ "web3-core": "1.6.0",
+ "web3-core-helpers": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-net": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-net": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-net/-/web3-net-1.6.0.tgz",
+ "integrity": "sha512-LFfG95ovTT2sNHkO1TEfsaKpYcxOSUtbuwHQ0K3G0e5nevKDJkPEFIqIcob40yiwcWoqEjENJP9Bjk8CRrZ99Q==",
+ "requires": {
+ "web3-core": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-utils": "1.6.0"
+ }
+ },
+ "web3-providers-http": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-providers-http/-/web3-providers-http-1.6.0.tgz",
+ "integrity": "sha512-sNxHFNv3lnxpmULt34AS6M36IYB/Hzm2Et4yPNzdP1XE644D8sQBZQZaJQdTaza5HfrlwoqU6AOK935armqGuA==",
+ "requires": {
+ "web3-core-helpers": "1.6.0",
+ "xhr2-cookies": "1.1.0"
+ }
+ },
+ "web3-providers-ipc": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-providers-ipc/-/web3-providers-ipc-1.6.0.tgz",
+ "integrity": "sha512-ETYdfhpGiGoWpmmSJnONvnPfd3TPivHEGjXyuX+L5FUsbMOVZj9MFLNIS19Cx/YGL8UWJ/8alLJoTcWSIdz/aA==",
+ "requires": {
+ "oboe": "2.1.5",
+ "web3-core-helpers": "1.6.0"
+ }
+ },
+ "web3-providers-ws": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-providers-ws/-/web3-providers-ws-1.6.0.tgz",
+ "integrity": "sha512-eNRmlhOPCpuVYwBrKBBQRLGPFb4U1Uo44r9EWV69Cpo4gP6XeBTl6nkawhLz6DS0fq79apyPfItJVuSfAy77pA==",
+ "requires": {
+ "eventemitter3": "4.0.4",
+ "web3-core-helpers": "1.6.0",
+ "websocket": "^1.0.32"
+ }
+ },
+ "web3-shh": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-shh/-/web3-shh-1.6.0.tgz",
+ "integrity": "sha512-ymN0OFL81WtEeSyb+PFpuUv39fR3frGwsZnIg5EVPZvrOIdaDSFcGSLDmafUt0vKSubvLMVYIBOCskRD6YdtEQ==",
+ "requires": {
+ "web3-core": "1.6.0",
+ "web3-core-method": "1.6.0",
+ "web3-core-subscriptions": "1.6.0",
+ "web3-net": "1.6.0"
+ }
+ },
+ "web3-utils": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.6.0.tgz",
+ "integrity": "sha512-bgCAWAeQnJF035YTFxrcHJ5mGEfTi/McsjqldZiXRwlHK7L1PyOqvXiQLE053dlzvy1kdAxWl/sSSfLMyNUAXg==",
+ "requires": {
+ "bn.js": "^4.11.9",
+ "ethereum-bloom-filters": "^1.0.6",
+ "ethereumjs-util": "^7.1.0",
+ "ethjs-unit": "0.1.6",
+ "number-to-bn": "1.7.0",
+ "randombytes": "^2.1.0",
+ "utf8": "3.0.0"
+ },
+ "dependencies": {
+ "@types/bn.js": {
+ "version": "5.1.0",
+ "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-5.1.0.tgz",
+ "integrity": "sha512-QSSVYj7pYFN49kW77o2s9xTCwZ8F2xLbjLLSEVh8D2F4JUhZtPAGOFLTD+ffqksBx/u4cE/KImFjyhqCjn/LIA==",
+ "requires": {
+ "@types/node": "*"
+ }
+ },
+ "bn.js": {
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
+ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
+ },
+ "ethereumjs-util": {
+ "version": "7.1.3",
+ "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-7.1.3.tgz",
+ "integrity": "sha512-y+82tEbyASO0K0X1/SRhbJJoAlfcvq8JbrG4a5cjrOks7HS/36efU/0j2flxCPOUM++HFahk33kr/ZxyC4vNuw==",
+ "requires": {
+ "@types/bn.js": "^5.1.0",
+ "bn.js": "^5.1.2",
+ "create-hash": "^1.1.2",
+ "ethereum-cryptography": "^0.1.3",
+ "rlp": "^2.2.4"
+ },
+ "dependencies": {
+ "bn.js": {
+ "version": "5.2.0",
+ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz",
+ "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw=="
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"@maticnetwork/meta": {
"version": "2.4.16",
"resolved": "https://registry.npmjs.org/@maticnetwork/meta/-/meta-2.4.16.tgz",
}
}
},
+ "assert": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz",
+ "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==",
+ "requires": {
+ "es6-object-assign": "^1.1.0",
+ "is-nan": "^1.2.1",
+ "object-is": "^1.0.1",
+ "util": "^0.12.0"
+ }
+ },
"assert-plus": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz",
"integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="
},
+ "dotenv": {
+ "version": "10.0.0",
+ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
+ "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
+ },
"duplexer3": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
"es6-symbol": "^3.1.1"
}
},
+ "es6-object-assign": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz",
+ "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw="
+ },
"es6-symbol": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
"resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz",
"integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ="
},
+ "is-nan": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz",
+ "integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==",
+ "requires": {
+ "call-bind": "^1.0.0",
+ "define-properties": "^1.1.3"
+ }
+ },
"is-negative-zero": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz",
"integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA=="
},
+ "node-fetch": {
+ "version": "2.6.5",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
+ "integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
+ "requires": {
+ "whatwg-url": "^5.0.0"
+ }
+ },
"node-gyp-build": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz",
"integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg=="
},
+ "object-is": {
+ "version": "1.1.5",
+ "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz",
+ "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==",
+ "requires": {
+ "call-bind": "^1.0.2",
+ "define-properties": "^1.1.3"
+ }
+ },
"object-keys": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-0.4.0.tgz",
"punycode": "^2.1.1"
}
},
+ "tr46": {
+ "version": "0.0.3",
+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
+ },
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
}
}
},
+ "webidl-conversions": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+ "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
+ },
"websocket": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.34.tgz",
}
}
},
+ "whatwg-url": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+ "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
+ "requires": {
+ "tr46": "~0.0.3",
+ "webidl-conversions": "^3.0.0"
+ }
+ },
"which-boxed-primitive": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz",

MODIFY
examples/package.json
examples/package.json
"author": "",
"license": "ISC",
"dependencies": {
- "@maticnetwork/maticjs": "^2.0.44"
+ "@maticnetwork/maticjs": "^2.0.44",
+ "@maticnetwork/maticjs-web3": "^0.1.0",
+ "dotenv": "^10.0.0"
}
}

ADD
examples/pos/erc721/get_all_tokens.js
+const { pos } = require('../../config');
+const { getPOSClient, from } = require('../../utils');
+
+const execute = async () => {
+ const client = await getPOSClient();
+ const erc721Token = client.erc721(pos.parent.erc721);
+
+ const result = await erc721Token.getAllTokens(from);
+
+ console.log("result", result);
+}
+execute().then(() => {
+ process.exit(0);
+})
\ No newline at end of file

ADD
examples/pos/erc721/get_tokens_count.js
+const { pos } = require('../../config');
+const { getPOSClient, from } = require('../../utils');
+
+const execute = async () => {
+ const client = await getPOSClient();
+ const erc721Token = client.erc721(pos.parent.erc721);
+
+ const result = await erc721Token.getTokensCount(from);
+
+ console.log("result", result);
+}
+execute().then(() => {
+ process.exit(0);
+})
\ No newline at end of file

MODIFY
examples/utils.js
examples/utils.js
const bn = require('bn.js')
const HDWalletProvider = require('@truffle/hdwallet-provider')
const config = require('./config')
-const Network = require('@maticnetwork/meta/network')
-const MaticPlasmaClient = require('@maticnetwork/maticjs').default
-const { MaticPOSClient } = require('@maticnetwork/maticjs')
+const { POSClient, PlasmaClient, use } = require('@maticnetwork/maticjs')
const SCALING_FACTOR = new bn(10).pow(new bn(18))
+const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
+
+use(Web3ClientPlugin);
const privateKey = config.user1.privateKey
const userAddress = config.user1.address
-async function getMaticPlasmaClient(network = 'testnet', version = 'mumbai') {
- const networkInstance = new Network(network, version)
- const from = config.user1.address
- const matic = new MaticPlasmaClient({
+
+async function getPlasmaClient(network = 'testnet', version = 'mumbai') {
+ const plasmaClient = new PlasmaClient({
network: network,
version: version,
- parentProvider: new HDWalletProvider(privateKey, config.parent.rpc),
- maticProvider: new HDWalletProvider(privateKey, config.child.rpc),
- parentDefaultOptions: { from: userAddress },
- maticDefaultOptions: { from: userAddress },
+ child: {
+ provider: new HDWalletProvider(privateKey, config.child.rpc),
+ defaultConfig: {
+ from: userAddress
+ }
+ },
+ parent: {
+ provider: new HDWalletProvider(privateKey, config.parent.rpc),
+ defaultConfig: {
+ from: userAddress
+ }
+ }
})
- await matic.initialize()
- return { matic, network: networkInstance }
+ return plasmaClient.init();
}
-const getMaticPOSClient = () => {
- return new MaticPOSClient({
- network: 'testnet', // For mainnet change this to mainnet
- version: 'mumbai', // For mainnet change this to v1
- parentProvider: new HDWalletProvider(privateKey, config.parent.rpc),
- maticProvider: new HDWalletProvider(privateKey, config.child.rpc),
- parentDefaultOptions: { from: userAddress },
- maticDefaultOptions: { from: userAddress },
- posRootChainManager: config.pos.parent.chainManagerAddress,
+const getPOSClient = (network = 'testnet', version = 'mumbai') => {
+ const posClient = new POSClient({
+ network: network,
+ version: version,
+ child: {
+ provider: new HDWalletProvider(privateKey, config.child.rpc),
+ defaultConfig: {
+ from: userAddress
+ }
+ },
+ parent: {
+ provider: new HDWalletProvider(privateKey, config.parent.rpc),
+ defaultConfig: {
+ from: userAddress
+ }
+ }
})
+ return posClient.init();
}
module.exports = {
SCALING_FACTOR,
- getMaticPlasmaClient: getMaticPlasmaClient,
- getMaticPOSClient: getMaticPOSClient,
+ getPlasmaClient: getPlasmaClient,
+ getPOSClient: getPOSClient,
child: config.child,
plasma: config.plasma,
pos: config.pos,

DELETE
examples/web/README.md
-# Matic.js on the Browser
-
-To use Matic.js on simple HTML projects, this directory contains some sample files
-
-Open `index.html` in your browser and check console to get a matic object. You can refer API docs to now use this object for function calls on the client side.

DELETE
examples/web/index.html
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Matic.js Example</title>
- <script src="https://cdn.jsdelivr.net/npm/@maticnetwork/maticjs@2.0.0-beta.10/dist/matic.js"></script>
-</head>
-<body>
- <p>Check console.</p>
-</body>
-<script>
- console.log("Matic", Matic)
-</script>
-</html>

MODIFY
package.json
package.json
"lint:fix": "tslint src/**/*.ts --fix",
"test": "npm run build:pack && cd test && npm run install:lib:test",
"debug": "npm run build:pack && cd test && npm run install:lib:debug",
- "testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000"
+ "testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000",
+ "install:example": "cd examples && npm i ../maticnetwork-maticjs-3.0.0-beta.2.tgz --no-save"
},
"repository": {
"type": "git",

MODIFY
src/plasma/erc721.ts
src/plasma/erc721.ts
@@ -20,12 +20,14 @@ export class ERC721 extends PlasmaToken {
}
/**
- * how many ERC721s are owned by this user
+ * get tokens count for the user
*
- * @param userAddress
- * @param options
+ * @param {string} userAddress
+ * @param {ITransactionOption} [options]
+ * @returns
+ * @memberof ERC721
*/
- getBalance(userAddress: string, options: ITransactionOption = {}) {
+ getTokensCount(userAddress: string, options?: ITransactionOption) {
return this.getContract().then(contract => {
const method = contract.method(
"balanceOf",
@@ -36,11 +38,13 @@ export class ERC721 extends PlasmaToken {
}
/**
- * returns token id on that index for owner
+ * returns token id on supplied index for user
*
- * @param userAddress
- * @param index starting from zero, if no token found on that it will return error
- * @param options
+ * @param {number} index
+ * @param {string} userAddress
+ * @param {ITransactionOption} [options]
+ * @returns
+ * @memberof ERC721
*/
getTokenIdForUserByIndex(index: number, userAddress: string, options?: ITransactionOption) {
return this.getContract().then(contract => {
@@ -126,7 +130,7 @@ export class ERC721 extends PlasmaToken {
}
getAllTokens(userAddress: string) {
- return this.getBalance(userAddress).then(balance => {
+ return this.getTokensCount(userAddress).then(balance => {
balance = Number(balance);
const promises = [];
for (let i = 0; i < balance; i++) {

MODIFY
src/pos/erc721.ts
src/pos/erc721.ts
@@ -24,7 +24,7 @@ export class ERC721 extends POSToken {
}, client, rootChainManager, exitManager);
}
- private validateMany_(tokenIds) {
+ private validateMany__(tokenIds) {
if (tokenIds.length > 20) {
throw new Error('can not process more than 20 tokens');
}
@@ -33,6 +33,60 @@ export class ERC721 extends POSToken {
});
}
+ /**
+ * get tokens count for the user
+ *
+ * @param {string} userAddress
+ * @param {ITransactionOption} [options]
+ * @returns
+ * @memberof ERC721
+ */
+ getTokensCount(userAddress: string, options?: ITransactionOption) {
+ return this.getContract().then(contract => {
+ const method = contract.method(
+ "balanceOf",
+ userAddress
+ );
+ return this.processRead<number>(method, options);
+ });
+ }
+
+ /**
+ * returns token id on supplied index for user
+ *
+ * @param {number} index
+ * @param {string} userAddress
+ * @param {ITransactionOption} [options]
+ * @returns
+ * @memberof ERC721
+ */
+ getTokenIdForUserByIndex(index: number, userAddress: string, options?: ITransactionOption) {
+ return this.getContract().then(contract => {
+ const method = contract.method(
+ "tokenOfOwnerByIndex",
+ userAddress,
+ index
+ );
+
+ return this.processRead<string>(method, options);
+ });
+ }
+
+ getAllTokens(userAddress: string) {
+ return this.getTokensCount(userAddress).then(balance => {
+ balance = Number(balance);
+ const promises = [];
+ for (let i = 0; i < balance; i++) {
+ promises.push(
+ this.getTokenIdForUserByIndex(i, userAddress)
+ );
+ }
+ return Promise.all(
+ promises
+ );
+ });
+ }
+
isApproved(tokenId: string, option?: ITransactionOption) {
return this.getContract().then(contract => {
const method = contract.method(
@@ -100,7 +154,7 @@ export class ERC721 extends POSToken {
}
depositMany(tokenIds: TYPE_AMOUNT[], userAddress: string, option?: ITransactionOption) {
- const tokensInUint256 = this.validateMany_(tokenIds);
+ const tokensInUint256 = this.validateMany__(tokenIds);
const amountInABI = this.client.parent.encodeParameters(
tokensInUint256,
@@ -125,7 +179,7 @@ export class ERC721 extends POSToken {
}
withdrawStartMany(tokenIds: TYPE_AMOUNT[], option?: ITransactionOption) {
- const tokensInUint256 = this.validateMany_(tokenIds);
+ const tokensInUint256 = this.validateMany__(tokenIds);
return this.getContract().then(contract => {
const method = contract.method(
"withdrawBatch",

implement getTOkensCount, getAllTokens in pos erc721