Class: JsonRpcClient::Eth
- Inherits:
-
Object
- Object
- JsonRpcClient::Eth
- Defined in:
- lib/json_rpc_client/eth.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #block_number ⇒ Object
- #get_block_by_bumber(block_number_or_block_tag, transaction_detail_flag = false) ⇒ Object
-
#initialize(url, logger: Logger.new($stdout, level: :info)) ⇒ Eth
constructor
A new instance of Eth.
-
#method_missing(method, *args) ⇒ Object
example: eth.get_balance(‘0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045’, ‘latest’).
-
#respond_to_missing?(*_args) ⇒ Boolean
use method_missing to define all the methods.
Constructor Details
#initialize(url, logger: Logger.new($stdout, level: :info)) ⇒ Eth
Returns a new instance of Eth.
35 36 37 38 |
# File 'lib/json_rpc_client/eth.rb', line 35 def initialize(url, logger: Logger.new($stdout, level: :info)) @url = url @logger = logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
example:
eth.get_balance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 'latest')
62 63 64 65 66 67 |
# File 'lib/json_rpc_client/eth.rb', line 62 def method_missing(method, *args) words = method.to_s.split("_") rpc_method = "eth_#{words[0]}#{words[1..].collect(&:capitalize).join}" params = args JsonRpcClient.request(url, rpc_method, params, @logger) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
33 34 35 |
# File 'lib/json_rpc_client/eth.rb', line 33 def url @url end |
Instance Method Details
#block_number ⇒ Object
47 48 49 50 51 |
# File 'lib/json_rpc_client/eth.rb', line 47 def block_number rpc_method = "eth_blockNumber" params = [] JsonRpcClient.request(url, rpc_method, params, @logger) end |
#get_block_by_bumber(block_number_or_block_tag, transaction_detail_flag = false) ⇒ Object
40 41 42 43 44 |
# File 'lib/json_rpc_client/eth.rb', line 40 def get_block_by_bumber(block_number_or_block_tag, transaction_detail_flag = false) rpc_method = "eth_getBlockByNumber" params = [block_number_or_block_tag, transaction_detail_flag] JsonRpcClient.request(url, rpc_method, params, @logger) end |
#respond_to_missing?(*_args) ⇒ Boolean
use method_missing to define all the methods
56 57 58 |
# File 'lib/json_rpc_client/eth.rb', line 56 def respond_to_missing?(*_args) true end |