Class: Web3::Eth::EthModule
- Inherits:
-
Object
- Object
- Web3::Eth::EthModule
show all
- Includes:
- Utility
- Defined in:
- lib/web3ethereum/eth_module.rb
Constant Summary
collapse
- PREFIX =
'eth_'
Instance Method Summary
collapse
Methods included from Utility
#from_hex, #hex, #remove_0x_head, #wei_to_ether
Constructor Details
#initialize(web3_rpc) ⇒ EthModule
Returns a new instance of EthModule.
10
11
12
|
# File 'lib/web3ethereum/eth_module.rb', line 10
def initialize web3_rpc
@web3_rpc = web3_rpc
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
45
46
47
|
# File 'lib/web3ethereum/eth_module.rb', line 45
def method_missing m, *args
@web3_rpc.request "#{PREFIX}#{m}", args[0]
end
|
Instance Method Details
#blockNumber ⇒ Object
24
25
26
|
# File 'lib/web3ethereum/eth_module.rb', line 24
def blockNumber
from_hex @web3_rpc.request("#{PREFIX}#{__method__}")
end
|
#contract(abi) ⇒ Object
36
37
38
|
# File 'lib/web3ethereum/eth_module.rb', line 36
def contract abi
Web3::Eth::Contract.new abi, @web3_rpc
end
|
#getBalance(address, block = 'latest', convert_to_eth = true) ⇒ Object
14
15
16
17
|
# File 'lib/web3ethereum/eth_module.rb', line 14
def getBalance address, block = 'latest', convert_to_eth = true
wei = @web3_rpc.request("#{PREFIX}#{__method__}", [address, block]).to_i 16
convert_to_eth ? wei_to_ether(wei) : wei
end
|
#getBlockByNumber(block, full = true, convert_to_object = true) ⇒ Object
19
20
21
22
|
# File 'lib/web3ethereum/eth_module.rb', line 19
def getBlockByNumber block, full = true, convert_to_object = true
resp = @web3_rpc.request("#{PREFIX}#{__method__}", [hex(block), full])
convert_to_object ? Block.new(resp) : resp
end
|
#getTransactionByHash(tx_hash) ⇒ Object
28
29
30
|
# File 'lib/web3ethereum/eth_module.rb', line 28
def getTransactionByHash tx_hash
Transaction.new @web3_rpc.request("#{PREFIX}#{__method__}", [tx_hash])
end
|
#getTransactionReceipt(tx_hash) ⇒ Object
32
33
34
|
# File 'lib/web3ethereum/eth_module.rb', line 32
def getTransactionReceipt tx_hash
TransactionReceipt.new @web3_rpc.request("#{PREFIX}#{__method__}", [tx_hash])
end
|
#load_contract(etherscan_api, contract_address) ⇒ Object
40
41
42
|
# File 'lib/web3ethereum/eth_module.rb', line 40
def load_contract etherscan_api, contract_address
contract(etherscan_api.contract_getabi address: contract_address).at contract_address
end
|