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

# Ethers.js v6 и v5 - интеграция с Node RPC

> Подключите ethers v6 или v5 к Tenderly Node RPC с помощью JsonRpcProvider через HTTPS или WebSocket для запросов, трассировки и симуляции транзакций в EVM-сетях.

[Ethers.js](https://docs.ethers.org/v5/) — это самостоятельная библиотека на TypeScript/JavaScript для взаимодействия с блокчейном Ethereum и его экосистемой.

Чтобы подключиться к сети через Node RPC с использованием ethers v6 или v5, используйте JSON-RPC-провайдер поверх HTTPS или WebSocket.

## Использование JsonRpcProvider (ethers v6 и v5)

<Tabs>
  <Tab title="Ethers 6">
    ```js title="ethers-6/json-rpc-provider.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    // Installation Instructions: https://docs.ethers.io/v6/getting-started
    import { ethers } from "ethers";

    const RPC_URL = `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`

    async function executeMethod() {
      // Initialize an ethers provider instance
      const provider = new ethers.JsonRpcProvider(RPC_URL);

      const blockNumber = await provider.getBlockNumber();

      console.log(blockNumber);
    }

    await executeMethod();
    ```
  </Tab>

  <Tab title="Ethers 5">
    ```js title="ethers-5/json-rpc-provider.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    // Installation Instructions: https://docs.ethers.io/v5/getting-started
    import { ethers } from "ethers";

    const RPC_URL = `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`

    async function executeMethod() {
      // Initialize an ethers provider instance
      const provider = new ethers.providers.JsonRpcProvider(RPC_URL);

      const blockNumber = await provider.getBlockNumber();

      console.log(blockNumber);
    }

    await executeMethod();
    ```
  </Tab>
</Tabs>

После подключения вызывайте через провайдер любой стандартный метод `eth_*` или расширение Tenderly, например `tenderly_simulateTransaction`. Все поддерживаемые методы и сети смотрите в полном [справочнике JSON-RPC](/node-rpc/rpc-reference).

## Использование WebSocket-провайдера

<Tabs>
  <Tab title="Ethers 6">
    ```js title="ethers-6/wss-provider.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    // Installation Instructions: https://docs.ethers.io/v6/getting-started
    import { ethers } from "ethers";

    const RPC_URL_WSS = `wss://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`

    async function executeMethod() {
      // Initialize an ethers provider instance
      const provider = new ethers.WebSocketProvider(RPC_URL_WSS);

      const blockNumber = await provider.getBlockNumber();

      console.log(blockNumber);
    }

    await executeMethod();
    ```
  </Tab>

  <Tab title="Ethers 5">
    ```js title="ethers-5/wss-provider.ts" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    // Installation Instructions: https://docs.ethers.io/v5/getting-started
    import { ethers } from "ethers";

    const RPC_URL_WSS = `wss://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`

    async function executeMethod() {
      // Initialize an ethers provider instance
      const provider = new ethers.providers.WebSocketProvider(RPC_URL_WSS);

      const blockNumber = await provider.getBlockNumber();

      console.log(blockNumber);
    }

    await executeMethod();
    ```
  </Tab>
</Tabs>
