-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwallet.js
36 lines (31 loc) · 803 Bytes
/
wallet.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
const web3 = require('./web3')
const wallet = {
account: null,
balance: null,
tokens: [],
init: function (priv) {
if (!priv) throw new Error('no priv key');
this.account = web3.eth.accounts.wallet.add(priv)
this.getBalance()
},
getBalance: function () {
let req = web3.eth.getBalance(this.account.address)
req.then( (balance) => this.balance = balance )
return req
},
send: function (dest, value) {
let transaction = web3.eth.sendTransaction({
from: this.account.address,
to: dest,
value: value, //this.balance - 1e10,
gas: 1e5
})
console.log( transaction )
if ( transaction ) {
this.balance -= value
updateBalance( this.balance )
}
}
}
// wallet.init(process.env.PRIV)
module.exports = wallet