> ## 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 and v5 - Node RPC Integration

> EVM नेटवर्क्स पर transactions को query, trace, और simulate करने के लिए HTTPS या WebSockets पर JsonRpcProvider के साथ ethers v6 या v5 को Tenderly Node RPC से कनेक्ट करें।

[Ethers.js](https://docs.ethers.org/v5/) Ethereum ब्लॉकचेन और उसके इकोसिस्टम के साथ इंटरैक्ट करने के लिए एक स्टैंडअलोन TypeScript/JavaScript लाइब्रेरी है।

ethers v6 या v5 का उपयोग करते हुए Node RPC के माध्यम से एक नेटवर्क से कनेक्ट करने के लिए, HTTPS या WebSockets द्वारा समर्थित JSON-RPC provider का उपयोग करें।

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

एक बार कनेक्ट होने के बाद, provider के माध्यम से कोई भी मानक `eth_*` मेथड या Tenderly एक्सटेंशन जैसे `tenderly_simulateTransaction` को कॉल करें। प्रत्येक समर्थित मेथड और नेटवर्क के लिए पूर्ण [JSON-RPC reference](/node-rpc/rpc-reference) देखें।

## WebSocket provider का उपयोग करना

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