# Simulation Balance Diffs

Parse chain simulation events into structured balance changes — see exactly what coins and tokens move in each direction before signing.

## Quick Start: simulateAndReview()

```typescript
import { BitBadgesSigningClient } from 'bitbadges';

const client = new BitBadgesSigningClient({ adapter });
const review = await client.simulateAndReview(messages);

console.log('Gas used:', review.gasUsed);
console.log('Fee:', review.fee);

// See what moves
for (const [address, denoms] of Object.entries(review.netChanges.coinChanges)) {
  for (const [denom, amount] of Object.entries(denoms)) {
    console.log(`${address}: ${amount > 0n ? '+' : ''}${amount} ${denom}`);
  }
}

// If acceptable, broadcast
if (agentApprovesChanges(review.netChanges)) {
  const result = await client.signAndBroadcast(messages);
}
```

## Low-Level: parseSimulationEvents + calculateNetChanges

```typescript
import { parseSimulationEvents, calculateNetChanges } from 'bitbadges';

// If you have raw simulation events (e.g., from the API)
const parsed = parseSimulationEvents(events, txMessageInfos);
// parsed.coinTransferEvents — coins moving between addresses
// parsed.badgeTransferEvents — badges/tokens moving
// parsed.ibcTransferEvents — IBC transfers

const netChanges = calculateNetChanges(parsed, fee, signerAddress);
// netChanges.coinChanges — per-address coin deltas
// netChanges.badgeChanges — per-address badge deltas
```

## What Events Are Parsed

* Coin transfers (send, delegate, redelegate)
* Mint and burn events
* Badge/token transfers
* IBC transfers
* Protocol fees

## Also Available Via

* **Builder**: The `simulate_transaction` tool returns structured `parsedEvents` and `netChanges`
* **Frontend**: The TxModal "Net Changes" tab uses this under the hood


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bitbadges.io/for-developers/bitbadges-sdk/common-snippets/simulation-balance-diffs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
