Post
Share your knowledge.
What’s the best way to manage gas costs?
Gas adds up fast when batching actions. Any tips for estimating or reducing gas usage when working with Sui?
- Sui
- SDKs and Developer Tools
- Transaction Processing
- Security Protocols
Answers
6To save gas on Sui, the key is keeping things light. Every object you read or change (especially shared ones or dynamic fields) adds to the gas cost. So try to mutate fewer objects and only batch stuff if it truly helps the user
If you're working with Sui and want to manage gas costs effectively—especially when batching actions—the best approach is to estimate usage upfront and optimize your transactions based on how Sui handles gas. You should first use the sui_dryRunTransactionBlock method or CLI’s sui client dry-run command to simulate a transaction and view its exact gas breakdown. This helps you understand what’s consuming the most gas before you actually broadcast the transaction.
To reduce gas:
Batch wisely: Combine only essential calls into one transaction block. Splitting into multiple small transactions can sometimes be cheaper if one fails, especially under re-execution scenarios.
Minimize object transfers: Moving too many objects between accounts or passing them unnecessarily into functions increases computation costs.
Avoid redundant reads/writes: Keep your logic lean—store only what’s needed, and read from as few dynamic fields or shared objects as possible.
Use pure functions when possible: Functions that don’t mutate state or require object access are cheaper.
Pick the right gas coin: Ensure you're using a coin with enough balance and avoid splitting SUI coins mid-transaction.
Sui’s gas model is based on computation + storage + rebate. You get refunded for deleting data (like removing an object), so strategically removing unused objects can help offset costs.
Here’s a dry run example using CLI:
sui client dry-run --tx-bytes
And via JS SDK:
const dryRun = await client.dryRunTransactionBlock({ transactionBlock }); console.log('Gas used:', dryRun.effects.gasUsed);
To estimate in advance, build the transaction using the SDK’s TransactionBlock object and dry-run it before submission.
🔗 Read more: Sui Gas Model – Official Docs
Let me know if you want a gas estimation helper template or analyzer for batched calls.
The gas fee is usually based on the computation units so the easiest way to save gas that you optimize the code with less computation. You can read more at https://docs.sui.io/concepts/tokenomics/gas-in-sui
Managing gas costs on Sui efficiently—especially when batching actions—requires understanding how Sui’s execution and object model impacts transaction costs. Here are the best practices to reduce and estimate gas usage:
-
Understand the gas model: Sui charges gas based on computation, storage read/write, and object access. Each additional object you touch in a transaction increases cost.
-
Minimize object dependencies: Only include necessary objects in a transaction. Large transactions with many input objects (especially shared ones) will incur higher gas.
-
Batch smartly: Instead of batching many actions in one large transaction, consider splitting into smaller ones if the cost scales non-linearly. Evaluate tradeoffs between latency and fees.
-
Use view functions: Mark non-mutating functions with #[view] to avoid gas costs entirely. These functions can read from the chain but don’t change state.
-
Cache frequently-used data: Structure contracts to reduce the number of reads/writes per call. For example, storing computed values in one object rather than recalculating across multiple.
-
Simulate before execution: Use the Sui CLI or SDK (e.g. sui client dry-run) to estimate gas costs for a transaction without submitting it. This is the safest way to forecast actual fees.
-
Avoid unnecessary serialization: Complex data structures or large objects cost more to load and write. Use efficient formats and avoid nesting objects unless necessary.
-
Recycle objects: In some designs, you can update and reuse the same object rather than minting/burning new ones, which saves storage-related gas.
-
Use shared objects with care: Shared objects are powerful but more expensive due to consensus checks. Prefer owned objects for low-cost actions unless concurrency is essential.
-
Stay updated on protocol improvements: Gas pricing and cost behavior may change across network upgrades. Monitor release notes from Mysten Labs to adapt your optimization strategies.
Managing gas costs effectively in Sui is essential, especially when batching multiple actions or working with complex smart contracts. Here are the best practices and techniques to estimate, reduce, and manage gas usage efficiently:
- Understand How Gas Works on Sui
Gas = computation + storage: You're charged for CPU usage and for any object storage/changes.
Storage rebate: When objects are deleted, part of the original storage cost is refunded.
Gas coins: Transactions consume sui::coin::Coin
- Use the Sui CLI or SDK to Estimate Gas
Use:
sui client dry-run --tx-path tx.json
This simulates the transaction and gives you an estimated gas cost without executing it.
In the SDK, dryRunTransactionBlock() performs the same function.
- Minimize Object Mutations
Mutating objects is expensive: Only mutate what's necessary.
Avoid excessive reads/writes to large tables or vectors, as each entry touched incurs gas.
- Break Transactions Into Smaller Batches
Instead of batching 10 complex calls in one transaction, consider splitting into smaller chunks.
Each transaction can be parallelized and retried more easily and saves total gas if some fail.
- Cache Expensive Computations Off-Chain
Offload non-critical calculations or verifications off-chain and only submit validated proofs or results on-chain.
Use oracles or client-side logic to reduce complexity.
- Use Shared Objects Efficiently
Shared objects cost more gas than owned objects because they require consensus.
Minimize shared object access unless it’s critical (e.g., for DAOs, NFTs, or markets).
- Optimize Data Layout in Move
Avoid nested or deeply nested structs or vectors.
Use lightweight types and keep stored objects minimal.
- Clean Up and Reuse Objects
Burn and delete unused coins or items to reclaim rebates.
Avoid creating excess temporary or redundant objects during operations.
- Profile with Localnet
Run a local validator with sui-test-validator and use the CLI to analyze gas usage in real time.
Useful for catching surprises before deploying to testnet or mainnet.
- Use Gas Budget Capping
Always set a max gas budget per transaction to avoid unintended costs:
sui client call --gas-budget 10000000 ...
Proper gas optimization helps you build more scalable and user-friendly apps on Sui, especially when dealing with NFTs, DAOs, or DeFi protocols.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410