上QQ阅读APP看书,第一时间看更新
Adding a utility method
Utility methods help us get data from our contract without modifying the state.
function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
This function accepts an address and returns the balance of the passed-in address. Notice how it is marked with view. The view modifier signifies that this function does not modify the storage state of the contract. You will learn more about this in Chapter 2, Web3 and Solidity in Truffle, where we will refresh Solidity fundamentals.