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

> Learn how to execute a simple transaction simulation using the Tenderly SDK.

In this tutorial, you'll learn how to run a transaction simulation using the Tenderly SDK. Simulations allow you to test the behavior of your transactions without sending them on-chain. Learn more about Tenderly's [Transaction Simulator here](/simulations/quickstart).

### Prerequisites

* Node.js installed on your machine
* [Tenderly account with an API key](/platform/account/projects/api-tokens)
* [Project set up in the Tenderly Dashboard](/platform/account/projects/slug)

<Info>
  Use this link to [sign up for
  Tenderly](https://dashboard.tenderly.co/register?utm_source=homepage).
</Info>

### Step 1: Initialize a new Node.js project

Create a new directory for your project, navigate to it in the terminal, and initialize a new Node.js project:

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

### Step 2: Install Tenderly SDK

Install the [Tenderly SDK npm package](https://www.npmjs.com/package/@tenderly/sdk) as a dependency in your Node.js project:

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

### Step 3: Import the Tenderly SDK and configure it

Create a new file named **`index.js`** in your project directory, and add the following code to import the Tenderly SDK and configure it with your Tenderly account details:

```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
});
```

Make sure to replace **`your-account-name`**, **`your-project-name`**, and **`your-access-key`** with your actual Tenderly account information.

<Note>
  Follow these guides to [obtain the configuration
  details](/platform/sdk/introduction#how-to-get-the-account-name-project-slug-and-secret-key).
</Note>

### Step 4: Define the transaction details

Next, define the transaction details for the simulation.

Add the following code to **`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
};

```

Replace the **`from`**, **`to`**, **`input`**, **`value`**, **`gas`**, and **`gas_price`** fields with your desired transaction details. The **`override`** field is optional and allows you to override the state of specific contracts in the simulation.

<Warning>
  Make sure that the specified block number actually exists on the selected network.
</Warning>

### Step 5: Run the transaction simulation

Now, use the Tenderly SDK's **`simulateTransaction`** method to run the transaction simulation.

Add the following code to **`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);
  }
})();
```

This code runs an asynchronous function that calls the **`simulateTransaction`** method and logs the simulation result to the console.

### Step 6: Execute the script

Save the **`index.js`** file and run the script using the following command:

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

If the transaction simulation is successful, you'll see the simulation result printed in the console.

That's it! You've now learned how to run a transaction simulation using the Tenderly SDK.
