Transactions
Write operations in tronz go through lazy builders. Each builder is returned
by a method on the provider, lets you set fields fluently, and performs no
I/O until you call .send(). At that point tronz fills in chain-dependent
fields, signs the transaction, and broadcasts it — returning a
PendingTransaction.
let pending = provider
.send_trx() // returns a TransferBuilder
.to(to) // set fields...
.amount(Trx::from_sun(1_000_000)?)
.send() // ...now it does I/O
.await?;Available builders
All of these are methods on TronProvider:
| Method | Operation |
|---|---|
send_trx() | Transfer TRX |
freeze_balance() | Stake TRX for a resource (Stake 2.0) |
unfreeze_balance() | Unstake TRX |
delegate_resource() | Delegate staked energy/bandwidth to another account |
undelegate_resource() | Reclaim a delegation |
withdraw_expire_unfreeze() | Withdraw TRX from expired unfreeze windows |
cancel_all_unfreeze() | Cancel all pending unfreezes |
claim_rewards() | Withdraw accrued block/vote rewards |
vote_witness() | Vote for super representatives |
create_account() | Activate a new account on-chain |
update_account_name() | Set the account's on-chain name |
set_account_id() | Set the account's permanent public ID |
update_permissions() | Update multisig permissions |
See Transferring TRX and Staking for worked examples.
TRC10, witness, governance, exchange, and market builders live on extension traits. Import the relevant trait to make those methods available. See Exchange and Market for a complete native-DEX example.
Requirements for sending
Every .send() needs:
- A signer — attach one with
.with_signer()on the builder. Without a wallet filler, the provider does not have the signing capability required by.send(). - A fee limit for contract operations.
ProviderBuilder::new()installsEnergyFiller, which estimates energy and derives one; use.with_fee_limit()when you want a fixed default instead. TAPOS (the recent-block reference every TRON transaction needs) is filled by the node endpoint that builds the transaction, so add.with_tapos()only for a locally referenced transaction.
The owner (sender) defaults to the signer's address, so you rarely set it
explicitly. You can override it with .from(addr) when signing on behalf of
another account (e.g. multisig).
The low-level path
The builders are sugar over send_transaction(req), which takes a fully-formed
TransactionRequest. If you've constructed a request yourself, you can also
broadcast(signed_tx) an already-signed transaction. Most code should prefer
the builders.
