curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get -y install build-essential
sudo npm install -g ethereumjs-testrpc
sudo npm install -g truffle
testrpc -a 3 # testrpc -a <num of accounts>
truffle compile
truffle migrate
truffle console
Some commands to test out,
truffle(default)> web3.eth.accounts
truffle(default)> var lot = Lottery.deployed()
truffle(default)> lot.address
truffle(default)> web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), "ether");
truffle(default)> lot.buyBet(3, {from: web3.eth.accounts[2], value: 9000000000000000000 }); # 3 in this case is the lottery number
Testing files are placed in /tests
. To run a suite of tests
truffle test
Copy and paste the code in contracts/Lottery.sol
into online compiler https://ethereum.github.io/browser-solidity/
From the compiler, copy and paste the section under 'Web3 deploy' into a file lotCompiled.js
Place the file in the directory where you initiated your geth from
> loadScript("./lotCompiled.js")
Object [null null]
> eth.pendingTransactions
[...]
> miner.start() # wait till contract mined
Contract mined! address: 0xaaaaaaaaaabbbbbbbbbbcccccccccc
> eth.getCode(lottery.address)
> lottery.jackpot.call()
0
> lottery.buyTicket(...)
> miner.start()
> lottery.jackpot.call()
500000000
Copy and paste the section under 'Interface' from the online compiler into ABI
Replace the address with the deployed contract's address
var lottery = eth.contract(ABI).at('0xaaaaaaaaaabbbbbbbbbbcccccccccc');