Skip to content
Logo

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.

# async fn run(provider: impl tronz::TronProvider, to: tronz::Address) -> anyhow::Result<()> {
# use tronz::Trx;
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?;
# Ok(()) }

Available builders

All of these are methods on TronProvider:

MethodOperation
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
update_permissions()Update multisig permissions

See Transferring TRX and Staking for worked examples.

Requirements for sending

Every .send() needs:

  1. A signer — attach one with .with_signer() on the builder. Without it, .send() returns a "no signer" error.
  2. The TAPOS filler — add it with .with_tapos() or .with_recommended_fillers(). TRON transactions must reference a recent block.

The owner (sender) defaults to the signer's address, so you rarely set it explicitly. You can override it with .owner(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.