new: examples for pos-portal calls
ADD
examples/node/approve-POS-ERC20-for-deposit.js
+const bn = require('bn.js')
+
+const Matic = require('@maticnetwork/maticjs').default
+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({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
+})
+
+async function execute() {
+ await matic.initialize()
+ matic.setWallet(config.PRIVATE_KEY)
+ return matic.approvePOSERC20ForDeposit(rootToken, amount, { from })
+}
+
+async function executeRaw() { // eslint-disable-line
+ await matic.initialize()
+ const txParams = await matic.approvePOSERC20ForDeposit(rootToken, amount, { from, encodeAbi: true })
+ let serializedTx = utils.buildRawTransaction(txParams, config.PRIVATE_KEY)
+ return matic.web3Client.parentWeb3.eth.sendSignedTransaction(serializedTx)
+}
+
+execute().then(console.log) // eslint-disable-line

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

MODIFY
examples/node/config.js
examples/node/config.js
@@ -17,4 +17,6 @@ module.exports = {
MATIC_TEST_TOKEN: '0x9a93c912F4eFf0254d178a18ACD980C1B05b57b0', // Contract for ERC20 in Matic testnet
ROPSTEN_ERC721_TOKEN: '0x07d799252cf13c01f602779b4dce24f4e5b08bbd', // Contract for ERC721 in Ropsten testnet
MATIC_ERC721_TOKEN: '0x8D5231e0B79edD9331e0CF0d4B9f3F30d05C47A5', // Contract for ERC721 in matic testnet
+ POS_ROOT_CHAIN_MANAGER_ADDRESS: '0x86B4EC021875d0123ED209A333B29D67F9AC6540', // Address of RootChainManager for POS Portal
+ MATIC_POS_TEST_TOKEN: '0x7f57bd9A688b1461633aE56452C2391b2f0d2e91', // Contract for POS ERC20 on matic testnet
}

ADD
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() {
+ await matic.initialize()
+ matic.setWallet(config.PRIVATE_KEY)
+ await matic.approvePOSERC20ForDeposit(rootToken, amount, { from, gasPrice: '10000000000' })
+ return matic.depositPOSERC20ForUser(rootToken, from, amount, { from, gasPrice: '10000000000' })
+}
+
+async function executeRaw() { // eslint-disable-line
+ 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)
+}
+
+execute().then(console.log) // eslint-disable-line

ADD
examples/node/exit-POS-ERC20.js
+const Matic = require('@maticnetwork/maticjs').default
+
+const config = require('./config')
+
+const from = config.FROM_ADDRESS // from address
+
+// Wait till checkpoint is submitted for the block containing burn tx, then run exitPOSERC20
+const burnTxHash = '0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5' // Insert txHash generated from burn-POS-ERC20.js
+
+// Create object of Matic
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ posRootChainManager: config.POS_ROOT_CHAIN_MANAGER_ADDRESS,
+})
+
+matic.initialize().then(() => {
+ matic.setWallet(config.PRIVATE_KEY)
+ matic
+ .exitPOSERC20(burnTxHash, {
+ from,
+ })
+ .then(res => {
+ console.log(res) // eslint-disable-line
+ })
+})

new: examples for pos-portal calls