Expand description
§tronz
tronz connects applications to the TRON network.
An idiomatic, async-first Rust SDK for TRON — inspired by alloy.
§Installation
Add the tronz crate:
cargo add tronzOr in your Cargo.toml:
tronz = "0.5"The default features include the TLS-enabled gRPC provider, contract bindings,
and local signing. The full feature adds mnemonic, keystore, and TIP-712
signing on top; signer-aws stays opt-in because it needs an AWS account. A
full list can be found in the
tronz crate’s Cargo.toml.
§Examples
§Querying the latest block
use tronz::{ProviderBuilder, TronProvider, TRONGRID_MAINNET};
let provider = ProviderBuilder::new().connect_grpc(TRONGRID_MAINNET).await?;
let block = provider.get_now_block().await?;
println!("Latest block: {} ({}ms)", block.number, block.timestamp);§Sending TRX
use tronz::{LocalSigner, ProviderBuilder, TronProvider, TRONGRID_NILE, parse_trx};
let signer = LocalSigner::from_hex("PRIVATE_KEY_HEX").expect("valid key");
let from = signer.address();
let provider = ProviderBuilder::new()
.with_signer(signer)
.connect_grpc(TRONGRID_NILE)
.await?;
let pending = provider
.send_trx()
.to(from)
.amount(parse_trx("1")?)
.send()
.await?;
let receipt = pending.get_receipt().await?;
println!("Status: {:?}", receipt.status);§Querying solidified (irreversible) state
SolidityProvider targets a TRON SolidityNode (WalletSolidity), which only
serves state confirmed by 2/3+ of the super representatives. It is read-only by
construction — no signer, no broadcast — and wait_for_success blocks until a
transaction has solidified and its execution succeeded.
use tronz::{SolidityProvider, TRONGRID_MAINNET_SOLIDITY};
let solidity = SolidityProvider::connect(TRONGRID_MAINNET_SOLIDITY).await?;
let head = solidity.get_now_block().await?;
println!("solidified head: {}", head.number);
let tx_id = std::env::var("TRON_TX_ID")?.parse()?;
let receipt = solidity.wait_for_success(tx_id).await?;
println!("solidified in block {}", receipt.block_number);§Type-safe contract bindings
tron_sol! turns a Solidity interface into typed call and event builders. The
generated code resolves everything through this crate, so no Alloy dependency
has to be added alongside it.
use tronz::{ProviderBuilder, TRONGRID_MAINNET, primitives::Address};
tronz::tron_sol! {
#[sol(rpc)]
interface IERC20 {
function balanceOf(address owner) external view returns (uint256);
}
}
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let provider = ProviderBuilder::new().connect_grpc(TRONGRID_MAINNET).await?;
let usdt: Address = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t".parse()?;
let token = IERC20::new(usdt, provider);
let balance = token.balanceOf(usdt).call().await?;
println!("balance: {balance}");
Ok(())
}For more examples, see the throgxyz/examples repository.
§Crates
| Crate | Description |
|---|---|
tronz | SDK facade for the commonly used crates and APIs |
tronz-abi | Native TRON ABI metadata and optional Alloy JSON ABI conversion |
tronz-primitives | Address, Trx, ResourceCode, signatures |
tronz-rpc-types | TRON domain types and protobuf messages, without a network stack |
tronz-signer | TronSigner, TronSignerSync, TronNetworkWallet, TronWallet, and LocalSigner |
tronz-provider | FullNode and SolidityNode transports/providers, fillers, and builders |
tronz-contract | TRC20 / TRC721 bindings, deployment, calls, and event filters |
tronz-sol-macro | tron_sol! procedural macro for provider-bound contract bindings |
tronz-signer-aws | AWS KMS signer (signer-aws feature) |
§Supported Rust Versions (MSRV)
The minimum supported Rust version is 1.91.1.
§Contributing
See CONTRIBUTING.md.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Re-exports§
pub use primitives::Address;pub use primitives::RecoverableSignature;pub use primitives::ResourceCode;pub use primitives::Trx;pub use primitives::U256;pub use primitives::format_trx;pub use primitives::hash_message;pub use primitives::parse_trx;pub use primitives::recover_message_address;pub use primitives::verify_message;pub use tronz_abi::TronAbi;pub use tronz_abi::TronAbiEntry;pub use tronz_abi::TronAbiEntryType;pub use tronz_abi::TronAbiParam;pub use tronz_abi::TronAbiStateMutability;pub use tronz_signer::KeystoreFile;signer-keystorepub use tronz_signer::MnemonicBuilder;signer-mnemonicpub use tronz_signer::coins_bip39;signer-mnemonicpub use tronz_signer::LocalSigner;pub use tronz_signer::TronNetworkWallet;pub use tronz_signer::TronSigner;pub use tronz_signer::TronSignerSync;pub use tronz_signer::TronWallet;pub use tronz_signer_aws::AwsSigner;signer-awspub use tronz_provider::ContractReadProvider;pub use tronz_provider::ProviderBuilder;pub use tronz_provider::SolidityProvider;pub use tronz_provider::SolidityProviderBuilder;pub use tronz_provider::TronProvider;pub use tronz_provider::transport::grpc::TRONGRID_MAINNET;pub use tronz_provider::transport::grpc::TRONGRID_MAINNET_SOLIDITY;pub use tronz_provider::transport::grpc::TRONGRID_NILE;pub use tronz_provider::transport::grpc::TRONGRID_NILE_SOLIDITY;pub use tronz_contract::JsonAbi;contractpub use tronz_contract::tron_sol;contract
Modules§
- abi
- Native TRON smart-contract ABI metadata types.
- contract
contract - TRC20 / TRC721 contract bindings and provider-bound instances.
- primitives
- Core TRON primitives: addresses, amounts, resource codes, signatures.
- providers
- Interface with a TRON node.
- rpc
- RPC domain types and protobuf representations.
- signers
- TRON signers, wallets, and local key implementations.
- transports
- Low-level gRPC transport and well-known endpoint constants.