> ## 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.

# Simulate Transactions via SDK

> जानें कि Tenderly SDK का उपयोग करके एक सरल transaction simulation कैसे निष्पादित करें।

इस ट्यूटोरियल में, आप सीखेंगे कि Tenderly SDK का उपयोग करके एक transaction simulation कैसे चलाएं। Simulations आपको अपने transactions के व्यवहार का परीक्षण करने की अनुमति देते हैं बिना उन्हें on-chain भेजे। Tenderly के [Transaction Simulator के बारे में यहां](/simulations/quickstart) अधिक जानें।

### आवश्यक शर्तें

* आपकी मशीन पर Node.js इंस्टॉल किया गया हो
* [एक API key के साथ Tenderly अकाउंट](/platform/account/projects/api-tokens)
* [Tenderly Dashboard में सेट अप किया गया Project](/platform/account/projects/slug)

<Info>
  [Tenderly के लिए साइन अप करने](https://dashboard.tenderly.co/register?utm_source=homepage) के लिए इस लिंक का उपयोग करें।
</Info>

### चरण 1: एक नया Node.js project इनिशियलाइज़ करें

अपने project के लिए एक नई डायरेक्टरी बनाएं, टर्मिनल में उस पर नेविगेट करें, और एक नया Node.js project इनिशियलाइज़ करें:

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
mkdir tenderly-simulation
cd tenderly-simulation
npm init -y
```

### चरण 2: Tenderly SDK इंस्टॉल करें

अपने Node.js project में एक निर्भरता के रूप में [Tenderly SDK npm package](https://www.npmjs.com/package/@tenderly/sdk) इंस्टॉल करें:

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @tenderly/sdk
```

### चरण 3: Tenderly SDK आयात करें और इसे कॉन्फ़िगर करें

अपनी project डायरेक्टरी में **`index.js`** नामक एक नई फ़ाइल बनाएं, और Tenderly SDK आयात करने और इसे अपने Tenderly अकाउंट विवरण के साथ कॉन्फ़िगर करने के लिए निम्नलिखित कोड जोड़ें:

```javascript title="example.js" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const { Network, Tenderly } = require('@tenderly/sdk');

const tenderly = new Tenderly({
  accountName: 'your-account-name',
  projectName: 'your-project-name',
  accessKey: 'your-access-key',
  network: Network.MAINNET, // Replace with the appropriate network
});
```

सुनिश्चित करें कि **`your-account-name`**, **`your-project-name`**, और **`your-access-key`** को अपनी वास्तविक Tenderly अकाउंट जानकारी से बदलें।

<Note>
  [कॉन्फ़िगरेशन विवरण प्राप्त करने](/platform/sdk/introduction#how-to-get-the-account-name-project-slug-and-secret-key) के लिए इन गाइड्स का पालन करें।
</Note>

### चरण 4: Transaction विवरण परिभाषित करें

इसके बाद, simulation के लिए transaction विवरण परिभाषित करें।

**`index.js`** में निम्नलिखित कोड जोड़ें:

```js title="example.js" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const transactionParameters = {
  from: '0x0000000000000000000000000000000000000000',
  to: '0x1f98431c8ad98523631ae4a59f267346ea31f984',
  input: '0xa1671295000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000152649ea73beab28c5b49b26eb48f7ead6d4c8980000000000000000000000000000000000000000000000000000000000000bb8',
  value: '0',
  gas: 8000000,
  gas_price: '0',
};

const simulation = {
  transaction: transactionParameters,
  blockNumber: 18813657, // simulation's target block number
  //overrides: {...} // optional state overrides field
};

```

**`from`**, **`to`**, **`input`**, **`value`**, **`gas`**, और **`gas_price`** फ़ील्ड्स को अपने वांछित transaction विवरण से बदलें। **`override`** फ़ील्ड वैकल्पिक है और आपको simulation में विशिष्ट contracts के state को override करने की अनुमति देता है।

<Warning>
  सुनिश्चित करें कि निर्दिष्ट block number वास्तव में चयनित नेटवर्क पर मौजूद है।
</Warning>

### चरण 5: Transaction simulation चलाएं

अब, transaction simulation चलाने के लिए Tenderly SDK के **`simulateTransaction`** मेथड का उपयोग करें।

**`index.js`** में निम्नलिखित कोड जोड़ें:

```js title="example.js" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
(async () => {
  try {
    const simulationResult = await tenderly.simulator.simulateTransaction(simulation);
    console.log('Simulation result:', simulationResult);
  } catch (error) {
    console.error('Error running simulation:', error);
  }
})();
```

यह कोड एक asynchronous function चलाता है जो **`simulateTransaction`** मेथड को कॉल करता है और simulation परिणाम को कंसोल पर लॉग करता है।

### चरण 6: स्क्रिप्ट निष्पादित करें

**`index.js`** फ़ाइल को सहेजें और निम्नलिखित कमांड का उपयोग करके स्क्रिप्ट चलाएं:

```bash title="example" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
node index.js
```

यदि transaction simulation सफल है, तो आप कंसोल में मुद्रित simulation परिणाम देखेंगे।

बस इतना ही! अब आपने Tenderly SDK का उपयोग करके transaction simulation चलाना सीख लिया है।
