Skip to content

Using the TransactionBuilder

The TransactionBuilder is a network specific transaction builder configurable with .with_* methods.

Common fields one can configure are:

It is generally recommended to use the builder pattern, as shown, rather than directly setting values (with_to versus set_to).

// Build a transaction to send 100 wei from Alice to Bob.
let tx = TransactionRequest::default()
        .with_to(bob)
        .with_nonce(0)
        .with_chain_id(provider.get_chain_id().await?)
        .with_value(U256::from(100))
        .with_gas_limit(21_000)
        .with_max_priority_fee_per_gas(1_000_000_000)
        .with_max_fee_per_gas(20_000_000_000);