Docs

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

JavaScript
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

JavaScript
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

JavaScript
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

  1. Always dry run before execution for critical transactions
  2. Add gas buffer of 10-20% to estimates for safety
  3. Validate object versions before submission
  4. Check for expected events in simulation results
  5. Handle simulation failures gracefully

Common Errors

ErrorDescriptionSolution
InsufficientGasGas budget too lowIncrease gas budget based on estimate
ObjectNotFoundReferenced object doesn't existVerify object IDs
InvalidInputMalformed transactionCheck transaction construction
ObjectVersionMismatchObject was modifiedRefresh object references

Need help? Contact our support team or check the Sui documentation.