Getting node information

We already have a web3 client instance. We can use the following API to gather information about the current node:

web3.eth.getNodeInfo(callback)

Let's see how this works in the React application that we are building:

  1. Insert the following code right after creating the Web3 instance:
const web3 = new Web3('ws://localhost:7545');
console.log(web3);

web3.eth.getNodeInfo(function(error, result) {
if (error) {
console.error(error);
} else {
console.log('result', result);
}
});
  1. As soon as you run the application, the console log should contain the following information:
result EthereumJS TestRPC/v2.8.0/ethereum-js

You are making good progress so far. Let's display the node information in the user interface on startup. We are going to use the React Hooks feature for this.

To find out more about React Hooks, please refer to the official documentation: https://reactjs.org/docs/hooks-intro.html.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset