gleeth/provider
Provider is the main entry point for interacting with an Ethereum network. It wraps a validated JSON-RPC URL and an optional chain ID, giving library consumers a safe handle they can pass to RPC calls, contract interactions, and transaction builders.
Warning: gleeth has not been audited. Recommended for testnet and development use only.
Because Provider is opaque, the only way to construct one is through
new, mainnet, or sepolia - all of which guarantee the URL is valid.
Examples
let assert Ok(local) = provider.new("http://localhost:8545")
let url = provider.rpc_url(local)
let eth = provider.mainnet()
let eth = provider.with_chain_id(eth, 1)
Types
Values
pub fn chain_id(provider: Provider) -> option.Option(Int)
Return the chain ID if one has been set, or None otherwise.
Examples
let assert Ok(p) = provider.new("http://localhost:8545")
provider.chain_id(p)
// -> None
pub fn mainnet() -> Provider
Convenience constructor for Ethereum mainnet using a public RPC endpoint.
Examples
let eth = provider.mainnet()
provider.rpc_url(eth)
// -> "https://eth.llamarpc.com"
pub fn new(
rpc_url: String,
) -> Result(Provider, types.GleethError)
Create a new provider from the given RPC URL.
The URL must be non-empty and start with http:// or https://.
Returns Error(InvalidRpcUrl(...)) if validation fails.
Examples
let assert Ok(p) = provider.new("http://localhost:8545")
let assert Error(_) = provider.new("")
let assert Error(_) = provider.new("ws://bad-scheme")
pub fn rpc_url(provider: Provider) -> String
Return the RPC URL held by this provider.
Examples
let assert Ok(p) = provider.new("http://localhost:8545")
provider.rpc_url(p)
// -> "http://localhost:8545"
pub fn sepolia() -> Provider
Convenience constructor for the Sepolia testnet using a public RPC endpoint.
Examples
let sep = provider.sepolia()
provider.rpc_url(sep)
// -> "https://ethereum-sepolia.publicnode.com"
pub fn with_chain_id(provider: Provider, id: Int) -> Provider
Return a new provider with the given chain ID attached.
This does not mutate the original provider - a fresh copy is returned.
Examples
let assert Ok(p) = provider.new("http://localhost:8545")
let p = provider.with_chain_id(p, 1)
provider.chain_id(p)
// -> Some(1)