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_getLogs supports up to 4 topics and 50 blocks in query range
  • eth_maxPriorityFeePerGas always returns zero
  • eth_syncing always 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 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 the number of transactions sent from an address.

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

Functions

Link to this function

block_number(opts \\ [])

View Source
@spec block_number(opts()) :: result()

Get the current block number.

Returns

  • {:ok, hex_string} - Block number as hex string
Link to this function

call(call_object, block \\ "latest", opts \\ [])

View Source
@spec call(map(), block_tag(), opts()) :: result()

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
@spec chain_id(opts()) :: result()

Get the chain ID.

Returns

  • {:ok, hex_string} - Chain ID as hex string
Link to this function

estimate_gas(call_object, opts \\ [])

View Source
@spec estimate_gas(map(), opts()) :: result()

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
Link to this function

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 blocks
  • newest_block: Newest block number or tag
  • reward_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
@spec gas_price(opts()) :: result()

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
Link to this function

get_balance(address, block \\ "latest", opts \\ [])

View Source
@spec get_balance(address(), block_tag(), opts()) :: result()

Get the balance of an address.

Note: Only "latest" block is supported.

Parameters

  • address: Address to check
  • block: Block tag (only "latest" supported)

Returns

  • {:ok, hex_string} - Balance in wei as hex string
Link to this function

get_block_by_hash(block_hash, full_transactions \\ false, opts \\ [])

View Source
@spec get_block_by_hash(hash(), boolean(), opts()) :: result()

Get block by hash.

Parameters

  • block_hash: Hash of the block
  • full_transactions: If true, returns full transaction objects; if false, only hashes

Returns

  • {:ok, block} - Block object or nil if not found
Link to this function

get_block_by_number(block_number, full_transactions \\ false, opts \\ [])

View Source
@spec get_block_by_number(block_tag(), boolean(), opts()) :: result()

Get 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
Link to this function

get_block_receipts(block_hash, opts \\ [])

View Source
@spec get_block_receipts(hash(), opts()) :: result()

Get all transaction receipts for a block.

Parameters

  • block_hash: Hash of the block

Returns

  • {:ok, receipts} - List of transaction receipts
Link to this function

get_block_transaction_count_by_hash(block_hash, opts \\ [])

View Source
@spec get_block_transaction_count_by_hash(hash(), opts()) :: result()

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
Link to this function

get_block_transaction_count_by_number(block_number, opts \\ [])

View Source
@spec get_block_transaction_count_by_number(block_tag(), opts()) :: result()

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
Link to this function

get_code(address, block \\ "latest", opts \\ [])

View Source
@spec get_code(address(), block_tag(), opts()) :: result()

Get contract code at an address.

Note: Only "latest" block is supported.

Parameters

  • address: Contract address
  • block: Block tag (only "latest" supported)

Returns

  • {:ok, hex_string} - Contract bytecode
Link to this function

get_logs(filter, opts \\ [])

View Source
@spec get_logs(map(), opts()) :: result()

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)
Link to this function

get_storage_at(address, position, block \\ "latest", opts \\ [])

View Source
@spec get_storage_at(address(), quantity(), block_tag(), opts()) :: result()

Get storage at a specific position.

Note: Only "latest" block is supported.

Parameters

  • address: Contract address
  • position: Storage position as hex string
  • block: Block tag (only "latest" supported)

Returns

  • {:ok, hex_string} - Storage value
Link to this function

get_transaction_by_block_hash_and_index(block_hash, index, opts \\ [])

View Source
@spec get_transaction_by_block_hash_and_index(hash(), quantity(), opts()) :: result()

Get transaction by block hash and index.

Parameters

  • block_hash: Hash of the block
  • index: Transaction index as hex string

Returns

  • {:ok, transaction} - Transaction object or nil
Link to this function

get_transaction_by_block_number_and_index(block_number, index, opts \\ [])

View Source
@spec get_transaction_by_block_number_and_index(block_tag(), quantity(), opts()) ::
  result()

Get transaction by block number and index.

Parameters

  • block_number: Block number as hex string
  • index: Transaction index as hex string

Returns

  • {:ok, transaction} - Transaction object or nil
Link to this function

get_transaction_by_hash(tx_hash, opts \\ [])

View Source
@spec get_transaction_by_hash(hash(), opts()) :: result()

Get transaction by hash.

Parameters

  • tx_hash: Transaction hash

Returns

  • {:ok, transaction} - Transaction object or nil if not found
Link to this function

get_transaction_count(address, block \\ "latest", opts \\ [])

View Source
@spec get_transaction_count(address(), block_tag(), opts()) :: result()

Get the number of transactions sent from an address.

Note: Only "latest" block is supported.

Parameters

  • address: Address to check
  • block: Block tag (only "latest" supported)

Returns

  • {:ok, hex_string} - Transaction count as hex string
Link to this function

get_transaction_receipt(tx_hash, opts \\ [])

View Source
@spec get_transaction_receipt(hash(), opts()) :: result()

Get transaction receipt.

Parameters

  • tx_hash: Transaction hash

Returns

  • {:ok, receipt} - Transaction receipt or nil if not found
Link to this function

max_priority_fee_per_gas(opts \\ [])

View Source
@spec max_priority_fee_per_gas(opts()) :: result()

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")
@spec syncing(opts()) :: result()

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