-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart_contract_instructions.txt
42 lines (33 loc) · 1.78 KB
/
smart_contract_instructions.txt
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
truffle init : turns your folder into a truffle environment
truffle migrate : compiles contracts
truffle migrate --reset : resets the contract deployment
truffle console
Also have access to web3 in truffle console
Can get address of specific contracts using nameOfContract.address
web3.eth.accounts : gives list of all accounts (can also be seen in Ganache)
you can then access instances of your smart contract: Greetings.deployed().then(function(instance){app=instance;})
you can then access methods in your smart contract: app.getGreetings.call()
Checking the state of a contract is free
Change the state of a smart contract: app.setGreetings("Hello Matthew!",{from:web3.eth.accounts[0]})
Exit truffle console: .exit
Ethereum transaction always has four fields:
1) from
2) to
3) value - how much ether should be transferred (can be 0)
4) data or input - either detail about smart contract function, code or nothing if transfer or value
To start a new development enviornment:
1) Start Ganache
2) run geth attach http://localhost:8545 in terminal
3) make sure you are in your smart contract folder, then run truffle migrate. This deploys the smart contract to your test node.
For the betting contract:
- truffle console
- truffle migrate
- Betting.deployed().then(function(instance){app=instance;})
- Add a fixture: app.addFixture('Chelsea','Arsenal',{from:web3.eth.accounts[0]})
- Add a fixture: app.addFixture('Liverpool','Tottenham',{from:web3.eth.accounts[0]})
- Query a fixture: app.getFixtureHomeTeam(0)
- Query number of fixtures: app.getNumberOfFixtures()
- Query number of bets: app.getNumberOfBets()
- Propose bet: app.proposeBet(1,2,300,2,1)
- Accept bet: app.acceptBet(0,{from:web3.eth.accounts[3]})
- Send value: app.payableFunction({from:'0xf17f52151EbEF6C7334FAD080c5704D77216b732',value:90})