JSON RPC & WebSockets

Learn about the blockchain communication protocol, JSON-RPC on Vince Chain

What is JSON and JSON-RPC?

JSON (aka, JavaScript Object Notation) is a JavaScript-derived language-independent data interchange format that uses human-readable text to store and transmit data objects consisting of attributes such as numbers, strings, ordered sequences of values, and collections of names, value pairs, and arrays.

Encoded in JSON, is the JSON-RPC, a stateless, lightweight remote procedure call (RPC) protocol, basically used to define data structures and the rules of their processing. JSON-RPC is one of several methods that enables a software application to invoke functionality from another application. I.e., allowing software to communicate with one another. It enables this communication over web sockets and HTTP. using the JSON (RFC 4627) data format.

JSON-RPC EVM Support on Vince Chain

Vince Chain JSON-RPC APIs and all Web3 communication API protocols standards.

The Ethereum JSON-RPC APIs use a name-space system. The JSON-PRC Server provides an API that allows you to connect to Vince Chain's mainnet and interact with the EVM. Vince Chain supports JSON-RPC over HTTP and WebSocket, enabled through command-line flags or through the app.toml configuration file.

The remote procedure call protocol (RPC) methods may use several categories depending on their motive. All method names comprise the namespace, an underscore, and the actual method name within the namespace. A typical example is the eth_call method that resides in the eth namespace. You can enable access to RPC methods on a per-namespace basis.

How to define namespaces

Eth,Net and Web3 namespaces are enabled by default. In order to enable other namespaces, use the flag --json-rpc.api.

Example:

vinced start --json-rpc.api eth,txpool,personal,net,debug,web3,miner

Cross-Origin Resource Sharing (CORS)

CORS is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served.

If you do not put the RPC by a reverse proxy when accessing the RPC from a browser, you will need to enable CORS with an appropriate domain set. Otherwise, the JavaScript calls will be limited by the same origin policy, which could cause RPC requests to fail.

You can update the CORS setting from the app.toml

Example:

###############################################################################
###                           API Configuration                             ###
###############################################################################

[api]

# ...

# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
enabled-unsafe-cors = true # default false

EVM Websocket

Since Vince Chain's core consensus engine is the Tendermint Core (because of the Cosmos SDK framework), it assumes their event format.

Nevertheless, to support the native Web3 compatibility for the WebSockets of the Ethereum PubSubAPI (opens new window), Vince Chain needs to cast its retrieved Tendermint responses into the Ethereum types.

You can start a connection with the Ethereum WebSocket using the --json-rpc.ws-address flag when starting the node (default "0.0.0.0:8546"):

vinced start --json-rpc.address"0.0.0.0:8545" --json-rpc.ws-address="0.0.0.0:8546" --evm.rpc.api="eth,web3,net,txpool,debug" --json-rpc.enable

Connect to JSON RPC tendermint WebSocket at port 8546 as defined above: ws ws://localhost:8546/

Last updated