View Source Hyperliquid.Rpc.Registry (hyperliquid v0.2.2)
Dynamic registry for named RPC endpoints.
Allows registering, retrieving, and managing multiple RPC endpoints by name at runtime. The registry is initialized from application configuration and can be updated dynamically.
Usage
# Register a new RPC endpoint at runtime
Hyperliquid.Rpc.Registry.register(:alchemy, "https://arb-mainnet.g.alchemy.com/v2/KEY")
# Get an RPC URL by name
{:ok, url} = Hyperliquid.Rpc.Registry.get(:alchemy)
# Use in RPC calls
Hyperliquid.Transport.Rpc.call("eth_blockNumber", [], rpc_name: :alchemy)
# List all registered RPCs
Hyperliquid.Rpc.Registry.list()
# Remove an RPC endpoint
Hyperliquid.Rpc.Registry.unregister(:alchemy)Configuration
Named RPCs can be configured in your config file:
config :hyperliquid,
named_rpcs: %{
alchemy: "https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY",
quicknode: "https://your-endpoint.quiknode.pro/YOUR_KEY",
local: "http://localhost:8545"
}
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all registered RPC endpoints.
Checks if a named RPC endpoint exists in the registry.
Gets the URL for a named RPC endpoint.
Gets the URL for a named RPC endpoint, raises if not found.
Lists all registered RPC endpoints.
Registers a named RPC endpoint.
Starts the RPC registry.
Removes a named RPC endpoint from the registry.
Types
@type rpc_url() :: String.t()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Clears all registered RPC endpoints.
Examples
iex> Hyperliquid.Rpc.Registry.clear()
:ok
Checks if a named RPC endpoint exists in the registry.
Parameters
name- Name of the RPC endpoint to check
Returns
trueif the RPC existsfalseotherwise
Examples
iex> Hyperliquid.Rpc.Registry.exists?(:alchemy)
true
iex> Hyperliquid.Rpc.Registry.exists?(:nonexistent)
false
Gets the URL for a named RPC endpoint.
Parameters
name- Name of the RPC endpoint
Returns
{:ok, url}- If the RPC exists:error- If the RPC does not exist
Examples
iex> Hyperliquid.Rpc.Registry.get(:alchemy)
{:ok, "https://arb-mainnet.g.alchemy.com"}
iex> Hyperliquid.Rpc.Registry.get(:nonexistent)
:error
Gets the URL for a named RPC endpoint, raises if not found.
Parameters
name- Name of the RPC endpoint
Returns
url- The RPC URL
Raises
RuntimeErrorif the RPC endpoint is not found
Examples
iex> Hyperliquid.Rpc.Registry.get!(:alchemy)
"https://arb-mainnet.g.alchemy.com"
Lists all registered RPC endpoints.
Returns
- Map of all registered RPC endpoints (name => url)
Examples
iex> Hyperliquid.Rpc.Registry.list()
%{
alchemy: "https://arb-mainnet.g.alchemy.com",
quicknode: "https://quicknode.com",
local: "http://localhost:8545"
}
Registers a named RPC endpoint.
Parameters
name- Name to register the RPC under (atom or string)url- RPC endpoint URL
Examples
iex> Hyperliquid.Rpc.Registry.register(:alchemy, "https://arb-mainnet.g.alchemy.com")
:ok
iex> Hyperliquid.Rpc.Registry.register("quicknode", "https://quicknode.com")
:ok
@spec start_link(keyword()) :: Agent.on_start()
Starts the RPC registry.
Options
:rpcs- Initial map of named RPC endpoints (default: %{})
This is typically called by the application supervisor.
@spec unregister(rpc_name()) :: :ok
Removes a named RPC endpoint from the registry.
Parameters
name- Name of the RPC endpoint to remove
Examples
iex> Hyperliquid.Rpc.Registry.unregister(:alchemy)
:ok