Blockchain Interaction
This section explains how developers can interact with the blockchain using APIs, RPC, and WebSockets. It provides details on available JSON-RPC APIs, example API calls, Web3.js integration, adding the chain to MetaMask, and deploying smart contracts.
API Interaction
Developers can interact with the blockchain network through JSON-RPC and WebSocket APIs. These interfaces allow developers to query blockchain data, send transactions, and perform administrative tasks.
HTTP RPC and WebSocket URLs
For interaction with your private blockchain network, the following RPC and WebSocket URLs are available:
Boot Node:
HTTP RPC URL:
http://34.173.46.64:8545
WebSocket URL:
ws://34.173.46.64:8546
Sub-Node:
HTTP RPC URL:
http://34.170.1.72:8547
WebSocket URL:
ws://34.170.1.72:8548
These URLs allow developers to access the blockchain network, submit transactions, deploy smart contracts, and query node information.
Available JSON-RPC APIs
The blockchain supports a wide range of JSON-RPC APIs for interacting with the network. Below is a list of the commonly used namespaces:
eth: Provides methods for interacting with Ethereum-like functionalities (accounts, contracts, etc.).
web3: Provides utility functions for working with the blockchain.
net: Provides network-related methods (network information, peers, etc.).
admin: Provides administrative methods (managing nodes, peers, etc.).
raft: Provides methods for interacting with the Raft consensus mechanism.
quorum: Provides methods specific to Quorum for managing privacy, permissions, and consensus.
Common API Methods:
eth_blockNumber: Returns the latest block number.
eth_getBlockByNumber: Returns information about a specific block.
eth_sendTransaction: Sends a transaction to the network.
eth_call: Calls a smart contract function without submitting a transaction.
admin_nodeInfo: Returns information about the node.
raft_addPeer: Adds a new node to the Raft consensus cluster.
quorum_nodeInfo: Returns Quorum-specific information about the node.
Example API Calls for Interacting with the Blockchain
Here are a few example API calls to demonstrate how to interact with the blockchain using JSON-RPC:
Get the Latest Block Number:
Get Information About a Specific Block:
Send a Transaction:
Call a Smart Contract Function:
Add a Peer to the Raft Consensus:
These examples showcase basic interactions like querying the blockchain and sending transactions. For more advanced operations, you can use Web3.js or a similar library to interact with the blockchain programmatically.
Web3.js Integration
Web3.js is a JavaScript library that enables interaction with the blockchain over JSON-RPC or WebSocket. It is commonly used for creating dApps (decentralized applications) and interacting with smart contracts.
Setting Up Web3.js:
Install Web3.js:
You can install Web3.js using npm:
Initialize Web3 in Your Application:
In your JavaScript file, you can initialize Web3 to connect to your private blockchain:
Example: Querying the Latest Block
Once Web3.js is set up, you can interact with the blockchain. Hereβs an example of how to get the latest block number using Web3.js:
Example: Sending a Transaction
To send a transaction using Web3.js, you can use the sendTransaction
method:
Adding the Chain to MetaMask
To interact with your private blockchain using MetaMask, you need to add the custom network to the MetaMask extension. Follow these steps:
Open MetaMask and click the network selector dropdown (by default, it shows "Ethereum Mainnet").
Click "Add Network" and fill in the details:
Network Name: Go-Quorum Private Chain (or any name you prefer)
New RPC URL:
http://34.173.46.64:8545
Chain ID:
33333
Currency Symbol:
ETH
(or any custom symbol if required)Block Explorer URL: (optional, if a block explorer is available)
Click "Save".
MetaMask will now be connected to your private blockchain network, and you can send transactions or deploy smart contracts directly from the MetaMask UI.
Sample Code for Web3.js Interaction
Hereβs a sample code snippet to show how you can interact with your blockchain network using Web3.js, including connecting, sending transactions, and querying contract data.
Contract Deployment and Interaction
Smart contracts can be deployed and interacted with on the private blockchain using Web3.js or Remix IDE. Below is an example of deploying a smart contract using Web3.js.
Example: Deploying a Smart Contract
This section provides a complete guide to interacting with your blockchain using RPC, Web3.js, and MetaMask. The next section will focus on advanced contract interaction and network scaling.
Last updated