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.
Get the Quorum node’s username
username
and passwordpassword
. If you have not configured a username and password, you can configure it following the steps in Node Security Management.Get the Quorum node’s RPC service address
noderpcaddress
, you can find this information in the Access Endpoint column of My Nodes table.When you create provider in web3.js, use the following codes to connect to the node.
- web3js version >=1.0
var provider = new Web3.providers.HttpProvider(
"http://${username}:${userpwd}@${noderpcaddress}",
{
keepAlive: false,
timeout: 5000
}
);
- 0.20.6 <= web3.js version < 1.0
var provider = new Web3.providers.HttpProvider(
"http://${noderpcaddress}",
5000,
"${username}",
"${userpwd}"
);
- web3js version >=1.0