Is there a way to filter ethereum json-rpc methods to only allow read calls, not writing? ie, filter out sendTransaction
, sendRawTransaction
, create
, etc
1 Answer
If you want to do it inside the node, you will need to override some of frontiers RPC handlers. For example, you can see the EthApi
implementation here:https://github.com/paritytech/frontier/blob/master/client/rpc/src/eth.rs. You could proceed in either of two ways:
- Copy this code and change some methods eg
sendRawTransaction
to behave as you like. - Write your own struct that wraps the one I linked. For methods you want to enable, you can call into the wrapped original. And for methods you want to block, you can just return immediately with no action or error.
-
Thanks @JoshOrndorff. I think that the correct way to achieve what I want is to use a middleware as you suggested, because I only want some nodes to be read-only. In this case it's infeasible to use different implementations for each type of node. Maybe in the future we could have cli options to directly filter the methods.– afmMar 7, 2022 at 20:43