Skip to content

4.2 Code Geth JSON RPC

Engine API is part of Execution APIs as documented in the spec here. It is specified to be running at a specific port than other APIs. It is also implemented in a different module than the other APIs.

Engine API#

I guess it's called 'engine' as it is the interface between consensus client and execution client. So to a consensus client, the execution client is like the engine doing the heavy job. A set of JSON-RPC calls are defined here under 'engine_' namespace. They are implemented in https://github.com/ethereum/go-ethereum/blob/v1.11.2/eth/catalyst/api.go

As explained in 3.5 Code - Lodestar - Block Building, getPayloadV1 and getPayloadV2 are used to ask the execution engine (geth in this case) to produce a new block from transaction pool. newPayloadV1 and newPayloadV2 are used when the node receives a block and sync to the execution engine.

The Other APIs#

The transaction API, together with many other APIs are implemented here: https://github.com/ethereum/go-ethereum/blob/v1.11.2/internal/ethapi/api.go. It includes:

  • EthereumAPI,
  • TxPoolAPI
  • EthereumAccountAPI
  • PersonalAccountAPI
  • BlockChainAPI
  • TransactionAPI
  • DebugAPI
  • NetAPI

The such APIs are initialized by:

More about func GetAPIS. It maps different APIs under different namespaces. For example when the namespace is 'eth', it means the JSON-RPC endpoint starts with eth_.

func GetAPIs(apiBackend Backend) []rpc.API {
    nonceLock := new(AddrLocker)
    return []rpc.API{
        {
            Namespace: "eth",
            Service:   NewEthereumAPI(apiBackend),
        }, {
            Namespace: "eth",
            Service:   NewBlockChainAPI(apiBackend),
        }, {
            Namespace: "eth",
            Service:   NewTransactionAPI(apiBackend, nonceLock),
        }, {
            Namespace: "txpool",
            Service:   NewTxPoolAPI(apiBackend),
        }, {
            Namespace: "debug",
            Service:   NewDebugAPI(apiBackend),
        }, {
            Namespace: "eth",
            Service:   NewEthereumAccountAPI(apiBackend.AccountManager()),
        }, {
            Namespace: "personal",
            Service:   NewPersonalAccountAPI(apiBackend, nonceLock),
        },
    }
}

Comparing to the spec, txpool and personal are not defined there.

Make A Transaction from Wallet#

When users use wallet like MetaMask to send a transaction, a JSON-RPC request is sent to one of the Ethereum nodes, and more specifically the execution client of the node. (But this answer says using 'LES protocol' will allow wallet to send to multiple nodes.)

How does wallet know URL or IP address of any Ethereum nodes?

The answer is Infura, a service provider that runs Ethereum nodes at fixed URLs or IP addresss. MetaMask uses them as default. Alternatively, anyone can run an Ethereum node themselves and configure MetaMask to use that specific node.

The handling of such request is further explained in 4.3 Code - Geth - Transaction Pool