app.toml
configuration file. It uses JSON (RFC 4627) as data format.
More on Ethereum JSON-RPC:
Cosmos-Specific Extensions: These methods are unique to Cosmos EVM and not found in standard Ethereum:Additional Eth Methods:
eth_getTransactionLogs
- Returns logs for a specific transactioneth_getBlockReceipts
- Returns all receipts for a given block
debug_freeOSMemory
- Forces garbage collectiondebug_setGCPercent
- Sets garbage collection percentagedebug_memStats
- Returns detailed memory statisticsdebug_setBlockProfileRate
- Sets block profiling ratedebug_writeBlockProfile
- Writes block profile to filedebug_writeMemProfile
- Writes memory profile to filedebug_writeMutexProfile
- Writes mutex contention profile to file
Notable Unsupported Methods: The following standard Ethereum methods are not implemented:
eth_fillTransaction
- Transaction filling utility- All
debug_getRaw*
methods - Raw data access not implemented eth_subscribe
syncing events - Only newHeads, logs, and newPendingTransactions work- All
trace_*
methods - Parity/OpenEthereum trace namespace - All
engine_*
methods - Post-merge Engine API
Enabling the JSON-RPC Server
To use the JSON-RPC API, you must enable it in your node’s configuration. You can do this either through theapp.toml
configuration file or via command-line flags.
Configuration File
Confirm the following in yourapp.toml
:
Command-Line Flags
Alternatively, enable JSON-RPC when starting the node:JSON-RPC over HTTP
Cosmos EVM 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, theeth_call
method resides in the eth namespace. Access to RPC methods can be enabled on a per-namespace basis.
HTTP Examples
To interact with the JSON-RPC server, send HTTP POST requests with a JSON body:Namespaces supported on Cosmos EVM
See the methods page for an exhaustive list and working examples.
Namespace | Description | Supported | Enabled by Default |
---|---|---|---|
eth | Core Ethereum JSON-RPC methods for interacting with the EVM | Y | Y |
web3 | Utility functions for the web3 client | Y | Y |
net | Network information about the node | Y | Y |
txpool | Transaction pool inspection | Y | N |
debug | Debugging and tracing functionality | Y | N |
personal | Private key management | Y | N |
admin | Node administration | Y | N |
miner | Mining operations (stub for PoS) | Y | N |
clique | Proof-of-Authority consensus | N | N |
les | Light Ethereum Subprotocol | N | N |
You should only expose the debug endpoint in non production settings as it could impact network performance and uptime under certain conditions.
Subscribing to Ethereum Events
Filters
Cosmos EVM also supports the Ethereum JSON-RPC filters calls to subscribe to state logs, blocks or pending transactions changes. Under the hood, it uses the CometBFT RPC client’s event system to process subscriptions that are then formatted to Ethereum-compatible events.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 Cosmos EVM is built with the Cosmos SDK framework and uses CometBFT 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, Cosmos EVM needs to cast the CometBFT 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"
):
ws
Subscribing to Events via WebSocket
The WebSocket endpoint allows your application to subscribe to real-time events, such as new blocks or logs, without needing to poll the node constantly.Example: Subscribe to New Block Headers
-
Connect to the WebSocket: Use a tool like
wscat
orws
to connect to the WebSocket endpoint. -
Send Subscription Request: Send an
eth_subscribe
request. The parameternewHeads
tells the server you want to listen for new blocks. -
Receive Subscription ID: The server responds with a unique subscription ID.
-
Receive Notifications: As new blocks are created, the server will push notifications to your client with the block header details.
Key Concepts
Data Encoding
JSON-RPC uses hexadecimal encoding for data, but the formatting differs based on the type:Quantities
When encoding quantities (integers, numbers):- Encode as hex, prefix with
"0x"
- Use the most compact representation
- Zero should be represented as
"0x0"
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
)
Unformatted Byte Arrays
When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays):- Encode as hex, prefix with
"0x"
- Two hex digits per byte
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
Several methods that query the state of the EVM accept a default block parameter. This allows you to specify the block height at which to perform the query. Methods supporting block parameter: The possible values for thedefaultBlock
parameter:
- Hex String - A specific block number (e.g.,
0xC9B3C0
) "latest"
- The most recently mined block"pending"
- The pending state, including transactions not yet mined"earliest"
- The genesis block