forked from trailofbits/publications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise1_hint.js
25 lines (18 loc) · 1.4 KB
/
exercise1_hint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Prepare the contract ABI
var bankAbi = [{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"buy","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"amount","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"user","type":"address"}],"name":"getBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]
var MyBank = web3.eth.contract(bankAbi);
var MyBankInstance = MyBank.at('0x38B30b220F0277a179958401CFD638708AA321f2');
// Show the ether balance of the bank
web3.fromWei(eth.getBalance(MyBankInstance.address), 'ether')
// Show the ether balance of our account
web3.fromWei(eth.getBalance(eth.accounts[0]), 'ether')
// Show how much token we have
MyBankInstance.getBalance(eth.accounts[0])
// Buy 1 ether worth of tokens
MyBankInstance.buy({from: eth.accounts[0], value:web3.toWei(1, 'ether')})
// Show the ether balance of the bank
web3.fromWei(eth.getBalance(MyBankInstance.address), 'ether')
// Show the ether balance of our account
web3.fromWei(eth.getBalance(eth.accounts[0]), 'ether')
// Show how much token we have
MyBankInstance.getBalance(eth.accounts[0])