View Source Hyperliquid.Rpc.Eth (hyperliquid v0.2.2)
Standard Ethereum JSON-RPC methods for Hyperliquid EVM.
All methods accept an optional opts keyword list that can include:
:rpc_url- Override the default RPC URL
Important Notes
- Methods that accept a block parameter only support
"latest"on Hyperliquid eth_getLogssupports up to 4 topics and 50 blocks in query rangeeth_maxPriorityFeePerGasalways returns zeroeth_syncingalways returns false
Usage
alias Hyperliquid.Rpc.Eth
{:ok, block_number} = Eth.block_number()
{:ok, balance} = Eth.get_balance("0x...")
{:ok, block} = Eth.get_block_by_number("0x1", true)
Summary
Functions
Get the current block number.
Execute a call without creating a transaction.
Get the chain ID.
Estimate gas for a transaction.
Convert ether to wei.
Convert a hex string to an integer.
Get the current gas price.
Get the balance of an address.
Get block by hash.
Get block by number.
Get all transaction receipts for a block.
Get the number of transactions in a block by hash.
Get the number of transactions in a block by number.
Get contract code at an address.
Get logs matching a filter.
Get storage at a specific position.
Get transaction by block hash and index.
Get transaction by block number and index.
Get transaction by hash.
Get the number of transactions sent from an address.
Get transaction receipt.
Get max priority fee per gas.
Check if the node is syncing.
Convert an integer to a hex string for RPC calls.
Convert wei to ether.
Types
@type address() :: String.t()
@type block_tag() :: String.t()
@type hash() :: String.t()
@type opts() :: Hyperliquid.Transport.Rpc.rpc_opts()
@type quantity() :: String.t()
@type result() :: Hyperliquid.Transport.Rpc.rpc_result()
Functions
Get the current block number.
Returns
{:ok, hex_string}- Block number as hex string
Execute a call without creating a transaction.
Note: Only "latest" block is supported.
Parameters
call_object: Map with call parameters (:from, :to, :gas, :gasPrice, :value, :data)block: Block tag (only "latest" supported)
Returns
{:ok, hex_string}- Return data
Get the chain ID.
Returns
{:ok, hex_string}- Chain ID as hex string
Estimate gas for a transaction.
Note: Only "latest" block is supported.
Parameters
call_object: Map with call parameters
Returns
{:ok, hex_string}- Estimated gas as hex string
@spec ether_to_wei(number()) :: non_neg_integer()
Convert ether to wei.
Examples
iex> ether_to_wei(1.0)
1000000000000000000
fee_history(block_count, newest_block, reward_percentiles \\ [], opts \\ [])
View Source@spec fee_history(non_neg_integer(), block_tag(), [number()], opts()) :: result()
Get fee history.
Parameters
block_count: Number of blocksnewest_block: Newest block number or tagreward_percentiles: List of percentiles
Returns
{:ok, fee_history}- Fee history object
@spec from_hex(String.t()) :: non_neg_integer()
Convert a hex string to an integer.
Examples
iex> from_hex("0xff")
255
iex> from_hex("0x0")
0
Get the current gas price.
Returns the base fee for the next small block.
Returns
{:ok, hex_string}- Gas price in wei as hex string
Get the balance of an address.
Note: Only "latest" block is supported.
Parameters
address: Address to checkblock: Block tag (only "latest" supported)
Returns
{:ok, hex_string}- Balance in wei as hex string
get_block_by_hash(block_hash, full_transactions \\ false, opts \\ [])
View SourceGet block by hash.
Parameters
block_hash: Hash of the blockfull_transactions: If true, returns full transaction objects; if false, only hashes
Returns
{:ok, block}- Block object or nil if not found
get_block_by_number(block_number, full_transactions \\ false, opts \\ [])
View SourceGet block by number.
Parameters
block_number: Block number as hex string or "latest", "earliest", "pending"full_transactions: If true, returns full transaction objects; if false, only hashes
Returns
{:ok, block}- Block object or nil if not found
Get all transaction receipts for a block.
Parameters
block_hash: Hash of the block
Returns
{:ok, receipts}- List of transaction receipts
Get the number of transactions in a block by hash.
Parameters
block_hash: Hash of the block
Returns
{:ok, hex_string}- Transaction count as hex string
Get the number of transactions in a block by number.
Parameters
block_number: Block number as hex string
Returns
{:ok, hex_string}- Transaction count as hex string
Get contract code at an address.
Note: Only "latest" block is supported.
Parameters
address: Contract addressblock: Block tag (only "latest" supported)
Returns
{:ok, hex_string}- Contract bytecode
Get logs matching a filter.
Note: Supports up to 4 topics and 50 blocks in query range.
Parameters
filter: Map with filter parameters:fromBlock- Starting block (hex string or tag):toBlock- Ending block (hex string or tag):address- Contract address or list of addresses:topics- List of topic filters (up to 4)
Returns
{:ok, logs}- List of log objects
Example
filter = %{
fromBlock: "0x1",
toBlock: "latest",
address: "0x...",
topics: ["0x..."]
}
{:ok, logs} = Eth.get_logs(filter)
Get storage at a specific position.
Note: Only "latest" block is supported.
Parameters
address: Contract addressposition: Storage position as hex stringblock: Block tag (only "latest" supported)
Returns
{:ok, hex_string}- Storage value
get_transaction_by_block_hash_and_index(block_hash, index, opts \\ [])
View SourceGet transaction by block hash and index.
Parameters
block_hash: Hash of the blockindex: Transaction index as hex string
Returns
{:ok, transaction}- Transaction object or nil
get_transaction_by_block_number_and_index(block_number, index, opts \\ [])
View SourceGet transaction by block number and index.
Parameters
block_number: Block number as hex stringindex: Transaction index as hex string
Returns
{:ok, transaction}- Transaction object or nil
Get transaction by hash.
Parameters
tx_hash: Transaction hash
Returns
{:ok, transaction}- Transaction object or nil if not found
Get the number of transactions sent from an address.
Note: Only "latest" block is supported.
Parameters
address: Address to checkblock: Block tag (only "latest" supported)
Returns
{:ok, hex_string}- Transaction count as hex string
Get transaction receipt.
Parameters
tx_hash: Transaction hash
Returns
{:ok, receipt}- Transaction receipt or nil if not found
Get max priority fee per gas.
Note: Always returns zero on Hyperliquid currently.
Returns
{:ok, hex_string}- Max priority fee as hex string (always "0x0")
Check if the node is syncing.
Note: Always returns false on Hyperliquid.
Returns
{:ok, false}- Node is not syncing
@spec to_hex(non_neg_integer()) :: String.t()
Convert an integer to a hex string for RPC calls.
Examples
iex> to_hex(255)
"0xff"
iex> to_hex(0)
"0x0"
@spec wei_to_ether(String.t() | non_neg_integer()) :: float()
Convert wei to ether.
Examples
iex> wei_to_ether("0xde0b6b3a7640000")
1.0