2019-09-08 21:35:05 -04:00
|
|
|
const ganache = require("ganache-core");
|
2020-03-04 14:48:08 -04:00
|
|
|
const Web3 = require('web3');
|
2020-02-03 19:51:19 -04:00
|
|
|
const Subspace = require('../dist/index.js').default;
|
2019-08-29 15:59:53 -04:00
|
|
|
|
2019-09-08 21:35:05 -04:00
|
|
|
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
|
2020-03-04 14:48:08 -04:00
|
|
|
let web3 = new Web3(ganache.provider());
|
2019-08-29 15:59:53 -04:00
|
|
|
|
|
|
|
async function run() {
|
2020-03-04 14:48:08 -04:00
|
|
|
let accounts = await web3.eth.getAccounts();
|
2020-03-04 14:24:51 -04:00
|
|
|
console.log(accounts);
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log("ABC")
|
2020-03-04 14:48:08 -04:00
|
|
|
web3.eth.getBalance(accounts[0]).then(console.log);
|
2020-03-04 14:24:51 -04:00
|
|
|
}, 3000)
|
|
|
|
|
|
|
|
|
2019-08-29 15:59:53 -04:00
|
|
|
setTimeout(async () => {
|
2020-03-04 14:48:08 -04:00
|
|
|
await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: "100000000"});
|
|
|
|
await web3.eth.sendTransaction({from: accounts[1], to: accounts[0], value: "999999999"});
|
|
|
|
await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: "232433434"});
|
2019-09-08 21:35:05 -04:00
|
|
|
}, 2000);
|
2019-08-29 15:59:53 -04:00
|
|
|
|
2020-03-04 14:48:08 -04:00
|
|
|
const subspace = new Subspace(web3);
|
2019-08-29 15:59:53 -04:00
|
|
|
|
2019-09-27 16:04:01 -04:00
|
|
|
await subspace.init();
|
2019-08-29 15:59:53 -04:00
|
|
|
|
2019-09-27 16:04:01 -04:00
|
|
|
subspace.trackBalance(accounts[0]).subscribe((balance) => {
|
2019-08-29 15:59:53 -04:00
|
|
|
console.log("accounts[0] balance is ", balance);
|
|
|
|
})
|
|
|
|
|
2020-03-04 14:24:51 -04:00
|
|
|
subspace.trackBalance(accounts[1]).subscribe((balance) => {
|
|
|
|
console.log("accounts[1] balance is ", balance);
|
|
|
|
})
|
|
|
|
|
2019-08-29 15:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
run()
|