HomeDeveloper MaterialsCommunicate via JSON/RPCWeb3.js

Web3.js

An example script on Kaleido using Web3.js. This demonstrates how to connect to a Kaleido node using basic auth over HTTP and retrieve the latest block on the chain.

Requirements:

  1. Node & NPM

Steps:

  1. Clone the Kaleido Examples project
  2. In the javascript/web3js/http subdirectory open index.js and:
    • Replace the RPC_ENDPOINT placeholder with the RPC endpoint for your node.
    • Replace the USER placeholder with the basic auth credentials username.
    • Replace the PASS placeholder with the basic auth credentials password.
  3. Save the file and from the javascript/web3js/http subdirectory run npm install to install the node modules for the project.
  4. From the same directory, run node index.js to drive the program.