
Overview
TheTxBuilder provides a fluent API for batching multiple operations into a single atomic transaction. This saves gas and guarantees all-or-nothing execution—either all operations succeed together, or none of them execute.
Basic Usage
Mixing Operations
Combine transfers, staking, approvals, and raw calls:.stake() method is smart — it automatically calls enter_delegation_pool for new members or add_to_delegation_pool for existing members.
Preflight with Builder
Fee Estimation
Extracting Calls
You can also extract the raw calls for inspection:Available Builder Methods
| Method | Description |
|---|---|
.add(...calls) | Add raw Call objects |
.approve(token, spender, amount) | ERC20 approval |
.transfer(token, transfers) | ERC20 transfer(s) |
.stake(pool, amount) | Smart stake (enter or add based on membership) |
.enterPool(pool, amount) | Enter pool as new member |
.addToPool(pool, amount) | Add to existing pool position |
.claimPoolRewards(pool) | Claim staking rewards |
.exitPoolIntent(pool, amount) | Start exit process |
.exitPool(pool) | Complete exit after window |
.calls() | Resolve all calls without sending |
.estimateFee() | Estimate gas cost |
.preflight() | Simulate the transaction |
.send(options?) | Execute all calls atomically |
Best Practices
- Use the transaction builder for complex operations to save gas
- Always preflight non-trivial batches before submitting
- Combine related operations into a single transaction when possible
- Use
.estimateFee()to show users the cost before executing
Next Steps
- Learn about Transaction Execution for direct execution methods
- Explore Staking and Delegation for staking operations
- Check the Bitcoin, Stablecoins, and Token module for token operations