Created
February 3, 2020 10:46
-
-
Save probablyangg/d66915df30f0cef9a5630e233c17a0b0 to your computer and use it in GitHub Desktop.
maticjs 2.0.0 deposit sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"network":"testnet", | |
"version": "v3", | |
"privateKey": "0x..", // prepend with '0x' | |
"from": "0x..", // address corresponding to the private key | |
"RootTokenAddress": "...", | |
"ChildTokenAddress": "...", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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