-
Notifications
You must be signed in to change notification settings - Fork 19
/
depositerc20.js
61 lines (47 loc) · 2.09 KB
/
depositerc20.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Network = require("@maticnetwork/meta/network");
const Matic = require("@maticnetwork/maticjs").default;
const network = new Network("testnet","v3");
const MaticNetwork = network.Matic;
const MainNetwork = network.Main;
const Ropsten_Erc20Address = '0xec5c207897c4378658f52bccce0ea648d1f17d65';
const from = '0x8727aff41b503b4c01d757391d3b3a9d38b67dcd'; // from address
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 init() {
await matic.initialize();
await matic.setWallet('0xE86F1698548CFC955C3B3556DFB2C8F35FEB6EA5B35AB90608CBC6B04B9F700F');
}
async function PromiseTimeout(delayms) {
return new Promise(function(resolve, reject) {
setTimeout(resolve, delayms);
});
}
async function demoErc20() {
await init();
const amount = "100000000000000000"; // amount in wei
console.log("*****Deposit ERC20*****");
let token = Ropsten_Erc20Address;
await matic
.approveERC20TokensForDeposit(token, amount, {
from
})
.then(async logs => {
console.log("Approve on Ropsten:" + logs.transactionHash);
await PromiseTimeout(10000);
await matic
.depositERC20ForUser(token, from, amount, {
from
})
.then(async logs => {
console.log("Deposit on Ropsten:" + logs.transactionHash);
await PromiseTimeout(10000);
});
});
}
demoErc20();