sui_dryRunTransactionBlock - Simulate Su...
Simulate transaction execution on Sui blockchain without committing. Test transactions, estimate gas costs, and preview effects with Dwellir's reliable Sui RPC.
Simulates transaction execution without committing to the blockchain, providing detailed effects and gas estimates.
Overview
The sui_dryRunTransactionBlock method allows you to simulate transaction execution to preview effects, estimate gas costs, and validate transaction logic before submission. This is essential for testing complex transactions, estimating costs, and ensuring transactions will succeed before spending gas.
Code Examples
Use Cases
Gas Estimation
async function estimateGas(tx) {
const result = await client.dryRunTransactionBlock({
transactionBlock: await tx.build({ client })
});
const gasUsed = result.effects.gasUsed;
const totalGas =
Number(gasUsed.computationCost) +
Number(gasUsed.storageCost) -
Number(gasUsed.storageRebate);
// Add 10% buffer for safety
return Math.ceil(totalGas * 1.1);
}Transaction Validation
async function validateTransaction(tx) {
const result = await client.dryRunTransactionBlock({
transactionBlock: await tx.build({ client })
});
if (result.effects.status.status !== 'success') {
throw new Error(`Transaction would fail: ${result.effects.status.error}`);
}
// Check specific conditions
const created = result.effects.created || [];
const deleted = result.effects.deleted || [];
console.log(`Transaction would create ${created.length} objects`);
console.log(`Transaction would delete ${deleted.length} objects`);
return true;
}Complex Transaction Testing
async function testDeFiTransaction() {
const tx = new TransactionBlock();
// Complex DeFi operation
const [coin] = tx.splitCoins(tx.gas, [tx.pure(1000000000)]);
tx.moveCall({
target: '0xdefi::pool::swap',
arguments: [
coin,
tx.pure('0x2::sui::SUI'),
tx.pure('0xcustom::token::TOKEN')
]
});
// Test without executing
const result = await client.dryRunTransactionBlock({
transactionBlock: await tx.build({ client })
});
// Analyze events that would be emitted
const swapEvents = result.events.filter(e =>
e.type.includes('SwapExecuted')
);
console.log('Swap events:', swapEvents);
return result;
}Best Practices
- Always dry run before execution for critical transactions
- Add gas buffer of 10-20% to estimates for safety
- Validate object versions before submission
- Check for expected events in simulation results
- Handle simulation failures gracefully
Common Errors
| Error | Description | Solution |
|---|---|---|
InsufficientGas | Gas budget too low | Increase gas budget based on estimate |
ObjectNotFound | Referenced object doesn't exist | Verify object IDs |
InvalidInput | Malformed transaction | Check transaction construction |
ObjectVersionMismatch | Object was modified | Refresh object references |
Related Methods
- sui_executeTransactionBlock - Execute the transaction
- sui_devInspectTransactionBlock - Debug transaction execution
- sui_getObject - Verify object state
Need help? Contact our support team or check the Sui documentation.
sui_devInspectTransactionBlock - Debug S...
Debug and inspect Sui transaction execution with detailed traces. Analyze Move function calls, gas usage, and execution paths with Dwellir's Sui RPC.
sui_executeTransactionBlock - Execute Su...
Submit and execute signed transactions on Sui blockchain. Send coins, call smart contracts, and manage objects with Dwellir's reliable Sui RPC infrastructure.