Ethereum JSON-RPC
The JSON-PRC Server provides an API that allows you to connect to the Financiyo blockchain and interact with the EVM. This gives you direct access to reading Ethereum-formatted transactions or sending them to the network which otherwise wouldn't be possible on a Cosmos chain, such as Financiyo.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. JSON-RPC is provided on multiple transports. Financiyo supports JSON-RPC over HTTP and WebSocket. Transports must be enabled through command-line flags or through the app.toml
configuration file. It uses JSON (RFC 4627) as data format.
More on Ethereum JSON-RPC:
NOTE
Head over to our Academy to learn about our Geth Javascript Console Guide.
JSON-RPC over HTTP
Financiyo supports most of the standard web3 JSON-RPC APIs to connect with existing Ethereum-compatible web3 tooling over HTTP. Ethereum JSON-RPC APIs use a namespace 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.
Find below the JSON-RPC namespaces supported on Financiyo or head over to the documentation for the individual API endpoints and their respective curl commands on the JSON-RPC Methods page.
clique
The clique
API provides access to the state of the clique consensus engine. You can use this API to manage signer votes and to check the health of a private network.
🚫
debug
The debug
API gives you access to several non-standard RPC methods, which will allow you to inspect, debug and set certain debugging flags during runtime.
✔
les
The les
API allows you to manage LES server settings, including client parameters and payment settings for prioritized clients. It also provides functions to query checkpoint information in both server and client mode.
🚫
The miner
API allows you to remote control the node’s mining operation and set various mining specific settings.
✔
🚫
The txpool
API gives you access to several non-standard RPC methods to inspect the contents of the transaction pool containing all the currently pending transactions as well as the ones queued for future processing.
✔
🚫
admin
The admin
API gives you access to several non-standard RPC methods, which will allow you to have a fine grained control over your node instance, including but not limited to network peer and RPC endpoint management.
🚫
Subscribing to Ethereum Events
Filters
Financiyo also supports the Ethereum JSON-RPC filters calls to subscribe to state logs, blocks or pending transactions changes.
Under the hood, it uses the Tendermint RPC client's event system to process subscriptions that are then formatted to Ethereum-compatible events.
Then you can check if the state changes with the eth_getFilterChanges
call:
Ethereum Websocket
The Ethereum Websocket allows you to subscribe to Ethereum logs and events emitted in smart contracts. This way you don't need to continuously make requests when you want specific information.
Since Financiyo is built with the Cosmos SDK framework and uses Tendermint Core as it's consensus Engine, it inherits the event format from them. However, in order to support the native Web3 compatibility for websockets of the Ethereum's PubSubAPI, Financiyo 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"
):
Then, start a websocket subscription with ws
Further Considerations
HEX value encoding
At present there are two key datatypes that are passed over JSON:
quantities and
unformatted byte arrays.
Both are passed with a hex encoding, however with different requirements to formatting.
When encoding quantities (integers, numbers), encode as hex, prefix with "0x"
, the most compact representation (slight exception: zero should be represented as "0x0"
). Examples:
0x41
(65 in decimal)0x400
(1024 in decimal)WRONG:
0x
(should always have at least one digit - zero is"0x0"
)WRONG:
0x0400
(no leading zeroes allowed)WRONG:
ff
(must be prefixed0x
)
When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays), encode as hex, prefix with "0x"
, two hex digits per byte. Examples:
0x41
(size 1,"A"
)0x004200
(size 3,"\0B\0"
)0x
(size 0,""
)WRONG:
0xf0f0f
(must be even number of digits)WRONG:
004200
(must be prefixed0x
)
Default block parameter
The following methods have an extra default block parameter:
When requests are made that act on the state of Financiyo, the last default block parameter determines the height of the block.
The following options are possible for the defaultBlock
parameter:
HEX String
- an integer block numberString "earliest"
for the earliest/genesis blockString "latest"
- for the latest mined blockString "pending"
- for the pending state/transactions
Last updated