Gas Smashing
Every transaction on Sui has a gas fee that must be paid for successful execution. Gas smashing lets you pay this fee using multiple coins instead of a single one. This is useful when you have many smaller denomination coins or want to reduce the number of coins in your account. Gas smashing is most powerful when paired with the GasCoin programmable transaction block (PTB) argument.
Gas smashing happens automatically in a transaction if you provide multiple coins to pay for the gas fee. When Sui executes the transaction, the network combines, or smashes, all of the provided coins into a single coin. Smashing occurs regardless of coin amounts or the gas budget provided with the transaction, as long as it is within the minimum and maximum gas budgets. Sui deducts the gas fee from the single coin regardless of the execution status of the transaction. This means that even if the transaction fails to execute for some reason, such as an execution error, the provided gas coins remain smashed after the transaction's execution.
This design makes gas smashing a practical way to both manage coins and pay gas in the same transaction, as you can combine many small coins while simultaneously executing unrelated operations in one PTB.
You can smash at most 256 coins in a single PTB. Transactions with more than 256 gas coins fail.
Rebates
All but the first coin are deleted, often generating a storage rebate.
Rebates cannot be applied to pay for gas in the same transaction. Instead, the rebate and the remaining balance after gas deduction are credited to the first coin once execution completes.
Running out of gas with a refund
Because smashing always occurs, storage rebates can lead to unusual outcomes where a transaction both runs out of gas and still produces a net refund.
Consider the following scenario:
-
Transaction
Thas a gas budget of5000. -
You provide 5 coins with the balances:
C1 = 1000,C2 = 2000,C3 = 3000,C4 = 4000,C5 = 5000. -
The storage rebate per coin is
2000. -
If the gas cost exceeds the
5000budget,Tfails withOutOfGas.
However, after smashing and rebates:
Final balance in C1 =
(1000 + 2000 + 3000 + 4000 + 5000) // all coin balances
- 5000 // gas cost
+ (2000 * 4) // rebates for deleted coins
= 15000 - 5000 + 8000
= 18000
In this case, T fails but you still receive a net refund of 3000.