The Top 5 Web3 JavaScript Functions for Ethereum DApps
getAccounts, sendTransaction, estimateGas, and more
Web3 bridges the gap between the traditional internet and the Ethereum blockchain. It enables users to interact with your DApp through a browser. When using JavaScript for your front end, knowing the ins and outs of Web3JS is essential.
Here is a list of some of the most useful and commonly used functions in Web3JS.
web3.eth.getAccounts()
Use this function to get all of the available account addresses.
Usage:
let accounts = await web3.eth.getAccounts();
console.log(accounts[0]);Or:
web3.eth.getAccounts().then(console.log);web3.eth.sendTransaction()
Use this to send Ether from one account to another or a smart contract address. It requires a few parameters depending on the transaction. Possible parameters include from, to, value, gas, and more.
If you’re using this method as part of your front end, you can catch certain events that occur during submission to the blockchain. These events are transactionHash, receipt, confirmation, and error.
Usage:





