1

I'm building an Ethereum private network and I want to make a custom JSON-RPC endpoint.

I've been customizing and adding some things in the go-ethereum source code but I don't know yet where to look to make this and which files would be involved...

0

Trying different things I found that the answer is very simple:

Just by adding a method in go-ethereum/internal/ethapi/api.go let's say "MyMethod", it will map to the JSON-RPC method "eth_myMethod" like so:

// go-ethereum/internal/ethapi/api.go
func (s *PublicTransactionPoolAPI) MyMethod(ctx context.Context, text string) error {
    log.Info(text)
    return nil
}


RPC call:

{
    "jsonrpc": "2.0",
    "method": "eth_myMethod",
    "params": [
        "Hello, World!"
    ],
    "id": 1
}


That will return:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": null
}


And will print Hello, World! in the console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.