What is web3?
We mentioned web3 briefly in Chapter 1, Truffle for Decentralized Applications, and we even used it without fully understanding it. The purpose of Chapter 1, Truffle for Decentralized Applications, was to get a fully functional and working Dapp on a local blockchain so you could understand the power of Truffle.
Now, it's time to get more granular.
Web3 is a collection of APIs that allows JavaScript to access blockchain-based data and perform common Ethereum functions such as getting all accounts in a particular network, getting the balance of an account, or getting the particular block number.
Let's take a look at some examples:
var balance =web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1"); console.log(balance); // instanceof BigNumberconsole.log(balance.toString(10)); // '1000000000000'console.log(balance.toNumber()); // 1000000000000
The web3.eth.getBalance
function takes a string as an input. Particularly, this string should be a valid Ethereum address. The example...