All Products
Search
Document Center

Blockchain as a Service:Configure web3.js

Last Updated:Mar 04, 2019

Web3.js is the Ethereum compatible JavaScript API which implements the Generic JSON RPC spec. It’s available on npm as a node module, for Bower and component as embeddable scripts, and as a meteor.js package. You can use web3.js to connect to the Quorum node of the Alibaba Cloud BaaS by following the steps below.

  1. Get the Quorum node’s username username and password password. If you have not configured a username and password, you can configure it following the steps in Node Security Management.

  2. Get the Quorum node’s RPC service address noderpcaddress, you can find this information in the Access Endpoint column of My Nodes table.

  3. When you create provider in web3.js, use the following codes to connect to the node.

    • web3js version >=1.0
      1. var provider = new Web3.providers.HttpProvider(
      2. "http://${username}:${userpwd}@${noderpcaddress}",
      3. {
      4. keepAlive: false,
      5. timeout: 5000
      6. }
      7. );
    • 0.20.6 <= web3.js version < 1.0
      1. var provider = new Web3.providers.HttpProvider(
      2. "http://${noderpcaddress}",
      3. 5000,
      4. "${username}",
      5. "${userpwd}"
      6. );