Provider builder
ProviderBuilder assembles a provider step by step: you stack
fillers, optionally attach a
signer, set an API key, and finally bind a transport by
connecting. This mirrors alloy's ProviderBuilder + JoinFill pattern.
use tronz::ProviderBuilder;A minimal read-only provider
use tronz::{ProviderBuilder, TronProvider, TRONGRID_MAINNET};
let provider = ProviderBuilder::new()
.connect_grpc(TRONGRID_MAINNET)
.await?;ProviderBuilder::new() starts with the recommended EnergyFiller, which
estimates contract energy and derives fee_limit. Use
ProviderBuilder::default() for an empty (Identity) filler chain, or
.disable_recommended_fillers() to remove the recommended filler while
preserving other builder settings.
A read/write provider
To send transactions you need two things: a way to fill in chain-dependent fields, and a signer.
use tronz::{LocalSigner, ProviderBuilder, TRONGRID_NILE};
let signer = LocalSigner::from_hex(&std::env::var("TRON_PRIVATE_KEY")?)?;
let provider = ProviderBuilder::new()
.with_signer(signer) // sign before broadcast
.connect_grpc(TRONGRID_NILE)
.await?;Builder methods
| Method | Effect |
|---|---|
with_recommended_fillers() | Adds an EnergyFiller to an empty/custom chain |
disable_recommended_fillers() | Removes the EnergyFiller installed by new() |
with_tapos() | Adds the TAPOS filler (reference block + expiration) |
with_fee_limit(Trx) | Sets a default fee_limit for contract operations |
with_signer(signer) | Attaches a signer so .send() works |
wallet(wallet) | Attaches a multi-key wallet; falls back to its default key |
strict_wallet(wallet) | Attaches a wallet but rejects owners without a matching key |
maybe_api_key(Option<...>) | Optionally attach a TronGrid API key |
EnergyFiller estimates the call's energy and reads the network energy price,
then applies a safety margin to derive fee_limit. It does not add TAPOS:
every currently supported transaction is built by a node endpoint that already
fills TAPOS. Add with_tapos() explicitly only for locally referenced
transactions. See Fillers.
API keys
TronGrid rate-limits anonymous traffic. maybe_api_key takes an Option, so
you can pass an env var straight through without a match:
use tronz::{ProviderBuilder, TRONGRID_MAINNET};
let api_key: Option<String> = std::env::var("TRON_API_KEY").ok();
let provider = ProviderBuilder::new()
.maybe_api_key(api_key)
.connect_grpc(TRONGRID_MAINNET)
.await?;If you always have a key, use the convenience connector:
let provider = ProviderBuilder::new()
.connect_grpc_with_key(TRONGRID_MAINNET, "your-api-key")
.await?;Connecting
connect_grpc(uri) opens the gRPC connection and returns the provider. uri
examples:
"https://grpc.trongrid.io:443"— TronGrid mainnet (TLS)"http://127.0.0.1:50051"— a local FullNode (plain HTTP/2)
connect(uri) aliases connect_grpc(uri), and connect_with_key(uri, key)
aliases connect_grpc_with_key. The crate constants TRONGRID_MAINNET and
TRONGRID_NILE cover the common endpoints — see
gRPC transport.
Solidified reads use SolidityProvider and a separate endpoint, such as TRE's
http://127.0.0.1:50052. The matching constants are
TRONGRID_MAINNET_SOLIDITY and TRONGRID_NILE_SOLIDITY; see
SolidityNode provider.
