chg: update examples for POS client
RENAME
examples/node/approve-POS-ERC20-for-deposit.js
examples/node/POS-client/approve-ERC20-for-deposit.js
const bn = require('bn.js')
-const Matic = require('@maticnetwork/maticjs').default
-const config = require('./config')
-const utils = require('./utils')
+const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
+const config = require('../config')
+const utils = require('../utils')
const rootToken = config.ROPSTEN_TEST_TOKEN
const amount = new bn(1).mul(utils.SCALING_FACTOR)
const from = config.FROM_ADDRESS
// Create Matic object
-const matic = new Matic({
+const maticPOSClient = new MaticPOSClient({
maticProvider: config.MATIC_PROVIDER,
parentProvider: config.PARENT_PROVIDER,
rootChain: config.ROOTCHAIN_ADDRESS,
@@ -17,16 +17,15 @@ const matic = new Matic({
})
async function execute() {
- matic.setWallet(config.PRIVATE_KEY)
- return matic.approvePOSERC20ForDeposit(rootToken, amount, { from })
+ maticPOSClient.setWallet(config.PRIVATE_KEY)
+ return maticPOSClient.approveERC20ForDeposit(rootToken, amount, { from })
}
// eslint-disable-next-line
async function executeRaw() {
- await matic.initialize()
- const txParams = await matic.approvePOSERC20ForDeposit(rootToken, amount, { from, encodeAbi: true })
+ const txParams = await maticPOSClient.approveERC20ForDeposit(rootToken, amount, { from, encodeAbi: true })
let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
- return matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+ return maticPOSClient.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
}
// eslint-disable-next-line

RENAME
examples/node/burn-POS-ERC20.js
examples/node/POS-client/burn-ERC20.js
const bn = require('bn.js')
-const Matic = require('@maticnetwork/maticjs').default
+const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
-const config = require('./config')
+const config = require('../config')
const childToken = config.MATIC_POS_TEST_TOKEN // test token address
const amount = new bn(100000000) // amount in wei
@@ -10,16 +10,16 @@ const amount = new bn(100000000) // amount in wei
const from = config.FROM_ADDRESS // from address
// Create object of Matic
-const matic = new Matic({
+const maticPOSClient = new MaticPOSClient({
maticProvider: config.MATIC_PROVIDER,
parentProvider: config.PARENT_PROVIDER,
rootChain: config.ROOTCHAIN_ADDRESS,
posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
})
-matic.setWallet(config.PRIVATE_KEY)
-matic
- .burnPOSERC20(childToken, amount, {
+maticPOSClient.setWallet(config.PRIVATE_KEY)
+maticPOSClient
+ .burnERC20(childToken, amount, {
from,
})
.then(res => {

ADD
examples/node/POS-client/deposit-ERC20-for-user.js
+const bn = require('bn.js')
+
+const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
+const config = require('../config')
+const utils = require('../utils')
+
+const rootToken = config.ROPSTEN_TEST_TOKEN
+const amount = new bn(1).mul(utils.SCALING_FACTOR)
+const from = config.FROM_ADDRESS
+
+// Create Matic object
+const maticPOSClient = new MaticPOSClient({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
+})
+
+async function execute() {
+ maticPOSClient.setWallet(config.PRIVATE_KEY)
+ await maticPOSClient.approveERC20ForDeposit(rootToken, amount, { from, gasPrice: '10000000000' })
+ return maticPOSClient.depositERC20ForUser(rootToken, from, amount, { from, gasPrice: '10000000000' })
+}
+
+// eslint-disable-next-line
+async function executeRaw() {
+ let txParams = await maticPOSClient.approveERC20ForDeposit(rootToken, amount, { from, encodeAbi: true })
+ let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
+ await maticPOSClient.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+
+ txParams = await maticPOSClient.depositERC20ForUser(rootToken, from, amount, { from, encodeAbi: true })
+ serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
+ return maticPOSClient.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+}
+
+// eslint-disable-next-line
+execute().then(console.log)

RENAME
examples/node/deposit-POS-ether-for-user.js
examples/node/POS-client/deposit-ether-for-user.js
const bn = require('bn.js')
-const Matic = require('@maticnetwork/maticjs').default
-const config = require('./config')
-const utils = require('./utils')
+const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
+const config = require('../config')
+const utils = require('../utils')
const amount = new bn(1).mul(utils.SCALING_FACTOR)
const from = config.FROM_ADDRESS
// Create Matic object
-const matic = new Matic({
+const maticPOSClient = new MaticPOSClient({
maticProvider: config.MATIC_PROVIDER,
parentProvider: config.PARENT_PROVIDER,
rootChain: config.ROOTCHAIN_ADDRESS,
@@ -16,8 +16,8 @@ const matic = new Matic({
})
async function execute() {
- matic.setWallet(config.PRIVATE_KEY)
- return matic.depositPOSEtherForUser(from, amount, { from, gasPrice: '10000000000' })
+ maticPOSClient.setWallet(config.PRIVATE_KEY)
+ return maticPOSClient.depositEtherForUser(from, amount, { from, gasPrice: '10000000000' })
}
// eslint-disable-next-line

RENAME
examples/node/exit-POS-ERC20.js
examples/node/POS-client/exit-ERC20.js
-const Matic = require('@maticnetwork/maticjs').default
+const MaticPOSClient = require('@maticnetwork/maticjs').MaticPOSClient
-const config = require('./config')
+const config = require('../config')
const from = config.FROM_ADDRESS // from address
@@ -8,16 +8,16 @@ const from = config.FROM_ADDRESS // from address
const burnTxHash = '0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5' // Insert txHash generated from burn-POS-ERC20.js
// Create object of Matic
-const matic = new Matic({
+const maticPOSClient = new MaticPOSClient({
maticProvider: config.MATIC_PROVIDER,
parentProvider: config.PARENT_PROVIDER,
rootChain: config.ROOTCHAIN_ADDRESS,
posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
})
-matic.setWallet(config.PRIVATE_KEY)
-matic
- .exitPOSERC20(burnTxHash, {
+maticPOSClient.setWallet(config.PRIVATE_KEY)
+maticPOSClient
+ .exitERC20(burnTxHash, {
from,
})
.then(res => {

DELETE
examples/node/deposit-POS-ERC20-for-user.js
-const bn = require('bn.js')
-
-const Matic = require('@maticnetwork/maticjs').default
-const config = require('./config')
-const utils = require('./utils')
-
-const rootToken = config.PARENT_TEST_TOKEN
-const amount = new bn(1).mul(utils.SCALING_FACTOR)
-const from = config.FROM_ADDRESS
-
-// Create Matic object
-const matic = new Matic({
- maticProvider: config.MATIC_PROVIDER,
- parentProvider: config.PARENT_PROVIDER,
- rootChain: config.ROOTCHAIN_ADDRESS,
- posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
-})
-
-async function execute() {
- matic.setWallet(config.PRIVATE_KEY)
- await matic.approvePOSERC20ForDeposit(rootToken, amount, { from, gasPrice: '10000000000' })
- return matic.depositPOSERC20ForUser(rootToken, from, amount, { from, gasPrice: '10000000000' })
-}
-
-// eslint-disable-next-line
-async function executeRaw() {
- await matic.initialize()
- let txParams = await matic.approvePOSERC20ForDeposit(rootToken, amount, { from, encodeAbi: true })
- let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
- await matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
-
- txParams = await matic.depositPOSERC20ForUser(rootToken, from, amount, { from, encodeAbi: true })
- serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
- return matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
-}
-
-// eslint-disable-next-line
-execute().then(console.log)

chg: update examples for POS client