Truffle Notes
Truffle Notes
$ mkdir ballot
$ cd ballot
ballot1$ truffle init
it generates some folders and files, which can be seen by typing ls command.
it creates a folder build -> contracts, in which json files are created.
Step 4: Place the the following content in the truffle.js against appropriate fields
module.exports = {
networks: {
development: {
host: "localhost",
port: 9545, // RPC port alloted by truffle
network_id: "*" // match any network id
}
}
};
Step 5: add a file to the migrations directory to deploy our smart contract
module.exports = function(deployer) {
// deployment steps
deployer.deploy(MyContract);
};
It creates 1) public and private keys for 10 accounts, 2) keywords to recover the
accounts, and 3) http binding with 9545 port
truffle(develop)>
Step 7: Open a new termanal and go to ballot project folder and enter the following
command to migrate the smartcontract on to the blockchain network
Step 8: Then what can we do with the truffle console appeared in Step 6?
It provides a command line interface to peform operations on the accounts created
on the test chain and
also to access to the management APIs such as web3, eth, etc.
truffle(develop)>
web3.eth.sendTransaction({from:web3.eth.coinbase,to:web3.eth.accounts[1],value:99})
'0x1ca2e3a204a52333db052fe88ddaefef0432ce97f78e3b32898d2ccaa53f26f9'
truffle(develop)> web3.eth.getBalance(web3.eth.coinbase)
BigNumber { s: 1, e: 19, c: [ 999272, 87899999978901 ] }
truffle(develop)> web3.eth.getBalance(web3.eth.coinbase).toNumber()
99927287899999980000
truffle(develop)> web3.eth.getBalance(web3.eth.accounts[1]).toNumber()
100000000000000000000
truffle(develop)> web3.eth.getBalance(web3.eth.accounts[0]).toNumber()
99927287899999980000
truffle(develop)> web3.eth.getBalance(web3.eth.accounts[9]).toNumber()
100000000000000000000
truffle(develop)>
web3.eth.sendTransaction({from:web3.eth.accounts[2],to:web3.eth.accounts[1],value:99})
'0xf8fd40f9766a19aa490579181f855426aa22dad8e913c194fd22f60e8c6a3577'
truffle(develop)> web3.eth.getBalance(web3.eth.accounts[2]).toNumber()
99999999999999980000