Skip to content

Instantly share code, notes, and snippets.

@probablyangg
Created February 3, 2020 10:46
Show Gist options
  • Save probablyangg/d66915df30f0cef9a5630e233c17a0b0 to your computer and use it in GitHub Desktop.
Save probablyangg/d66915df30f0cef9a5630e233c17a0b0 to your computer and use it in GitHub Desktop.
maticjs 2.0.0 deposit sample code
{
"network":"testnet",
"version": "v3",
"privateKey": "0x..", // prepend with '0x'
"from": "0x..", // address corresponding to the private key
"RootTokenAddress": "...",
"ChildTokenAddress": "...",
}
const Matic = require("@maticnetwork/maticjs").default
const Network = require("@maticnetwork/meta/network")
const config = require('./config')
const network = new Network(config.network, config.version)
const MaticNetwork = network.Matic
const MainNetwork = network.Main
const ChildTokenAddress = config.ChildTokenAddress
const RootTokenAddress = config.RootTokenAddress
const from = config.from
const amount = 1 // amount in wei
// Create object of Matic
const matic = new Matic({
maticProvider: MaticNetwork.RPC,
parentProvider: MainNetwork.RPC,
rootChain: MainNetwork.Contracts.RootChain,
withdrawManager: MainNetwork.Contracts.WithdrawManagerProxy,
depositManager: MainNetwork.Contracts.DepositManagerProxy,
registry: MainNetwork.Contracts.Registry
})
async function testDeposit() {
await matic.initialize()
await matic.setWallet(config.privateKey)
await matic.approveERC20TokensForDeposit(RootTokenAddress, amount, {
from,
// gas: 8000000,
// gasPrice: '10000000000'
}).then((r) => console.log('approval succesful, ', r.transactionHash))
await matic.depositERC20ForUser(RootTokenAddress, from, amount, {
from,
// gas: 8000000,
// gasPrice: '100000000000'
}).then((r) => {
console.log('deposit successful; tx hash, ', r.transactionHash)
})
}
testDeposit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment