Comment on page
🔄
JSON RPC and API
JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
Echelon supports all standard Web3 JSON-RPC APIs.
JSON-RPC is provided on multiple transports. Echelon supports JSON-RPC over HTTP and WebSocket. Transports must be enabled through command-line flags or through the
app.toml
configuration file. For more details see below.Ethereum JSON-RPC APIs use a name-space system. RPC methods are grouped into several categories depending on their purpose. All method names are composed of the namespace, an underscore, and the actual method name within the namespace. For example, the
eth_call
method resides in the eth namespace.Access to RPC methods can be enabled on a per-namespace basis.
Eth
,Net
and Web3
namespaces are enabled by default. In order to enable other namespaces use flag --json-rpc.api
.echelond start --json-rpc.api eth,txpool,personal,net,debug,web3,miner
If accessing the RPC from a browser and if you do not put the RPC behind a reverse proxy, CORS will need to be enabled with the appropriate domain set. Otherwise, JavaScript calls are limit by the same-origin policy and requests will fail.
The CORS setting can be updated from the
app.toml
###############################################################################
### API Configuration ###
###############################################################################
[api]
# ...
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
enabled-unsafe-cors = true # default false
Since Echelon runs using Tendermint Core as it's consensus engine and it's built with the Cosmos SDK framework, it inherits the event format from them. However, in order to support the native Web3 compatibility for websockets of the Ethereum's PubSubAPI (opens new window), Echelon needs to cast the Tendermint responses retrieved 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"
):echelond 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 modified 1yr ago