> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# उपयोगकर्ता Transactions का Dry-Run करें

> जानें कि उपयोगकर्ताओं के transactions का dry-run करने के लिए Simulation API को कैसे एकीकृत करें और उन्हें आपके dapp का उपयोग करते समय वित्तीय नुकसान, निराशा और चिंता से बचने में मदद करें।

## ओवरव्यू

अपने dapp में [Simulation API](/simulations/overview) का उपयोग करना सीखें ताकि उपयोगकर्ता on-chain भेजने से पहले transaction परिणामों का पूर्वावलोकन कर सकें। इस तरह, आप उन्हें विफल या गलत transactions के कारण होने वाले वित्तीय नुकसान से बचने में मदद कर सकते हैं और आपके dapp का उपयोग करते समय उनका विश्वास बढ़ा सकते हैं।

अपने dapp में Tenderly Simulations API को एकीकृत करने के लिए ताकि यह पता लगाया जा सके कि on-chain भेजने से पहले ही कोई transaction विफल होगा या नहीं, आपको यह करना होगा:

1. ethers.js लाइब्रेरी से raw transactions को populate करें।
2. Transactions भेजने से पहले उनका simulation करें।
3. (वैकल्पिक) प्रत्येक blockchain interaction को एक Tenderly simulation में wrap करें।

एक individual कॉल के अनुरोध और प्रतिक्रिया विवरण के लिए, [single simulations](/simulations/single-simulations) देखें।

### ethers.js से raw transactions को populate करें

पहला कदम एक transaction object बनाना है जो हमारे simulation endpoint पर भेजा जाएगा। हम इसे सीधे `ethers.js` लाइब्रेरी से उत्पन्न करेंगे। नीचे दिए गए उदाहरण में, हम देखेंगे कि DAI contract के ऊपर `transfer()` function के लिए हम इसे कैसे प्राप्त कर सकते हैं:

```tsx title="example.tsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const dai = new ethers.Contract(DAI_ADDRESS, DAI_ABI, tenderlyForkProvider);

const unsignedTx = await dai.populateTransaction.transfer(
  ZERO_ADDRESS,
  YOUR_ADDRESS,
  util.ether(1),
);
```

### भेजने से पहले transactions का simulation करें

अब जब हमने एक unsigned raw transaction निकाल लिया है, तो इसे on-chain (Ethereum Mainnet पर) भेजने से पहले इसका simulation करें:

```tsx title="example.tsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
...

const body = {
    "network_id": "1",
    "from": senderAddr,
    "to": contract.address,
    "input": unsignedTx.data,
    "gas": 21204,
    "gas_price": "0",
    "value": 0,
    "save_if_fails": true
}

const headers = {
    headers: {
        'content-type': 'application/JSON',
        'X-Access-Key': TENDERLY_ACCESS_KEY,
  }
}
const resp = await axios.post(apiURL, body, headers);

if (resp.data.simulation.status === false) {
	// it failed, do as you please
}
```

### प्रत्येक blockchain interaction को एक Tenderly simulation में wrap करें (वैकल्पिक)

यह सुनिश्चित करने के लिए कि प्रत्येक blockchain interaction का पहले simulation किया जाता है, `ethers.js` signer ऑब्जेक्ट के चारों ओर एक सरल wrapper लिखें जो हमेशा transactions का simulation करेगा।

इसके अतिरिक्त, आगे बढ़ते हुए, आप typed errors पेश कर सकते हैं जिनके साथ आपका logic interact कर सकता है:

```tsx title="example.tsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export class TenderlySimulationSigner {
  public _provider: ethers.Provider;

  constructor(provider: ethers.Provider) {
    this._provider = provider;
  }

  public async sendTransaction(
    transaction: Deferrable<TransactionRequest>,
  ): Promise<TransactionResponse> {
    await this._simulateTx(transaction);

    return this._signer.sendTransaction(transaction);
  }

  public async getAddress(): Promise<string> {
    return this._signer.getAddress();
  }

  public async signTransaction(transaction: Deferrable<TransactionRequest>): Promise<string> {
    return this._signer.signTransaction(transaction);
  }

  _simulateTx(transaction: Deferrable<TransactionRequest>): Promise<void> {
    const unsignedTx = await contract.populateTransaction[funcName](...args);

    const apiURL = `https://api.tenderly.co/api/v1/account/me/project/project/simulate`;
    const body = {
      network_id: '1',
      from: senderAddr,
      to: contract.address,
      input: unsignedTx.data,
      gas: 21204,
      gas_price: '0',
      value: 0,
      save_if_fails: true,
    };

    const headers = {
      headers: {
        'content-type': 'application/JSON',
        'X-Access-Key': REACT_APP_TENDERLY_ACCESS_KEY as string,
      },
    };
    const resp = await axios.post(apiURL, body, headers);
    if (resp.data.simulation.status == false) {
      throw new Error('Transaction is going to fail');
    }

    return;
  }
}
```

<Info>
  यहाँ एक [GitHub
  repo](https://github.com/Tenderly/integration-samples/tree/main/dry-run-transactions) है जहाँ आप
  इस implementation का एक उदाहरण पा सकते हैं।
</Info>
