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

# Viem - Node RPC Integration

> HTTPS या WebSockets के माध्यम से 100+ EVM नेटवर्क्स पर transactions को पढ़ने, भेजने, trace करने, और simulate करने के लिए viem को Tenderly Node RPC से कनेक्ट करें।

[Viem](https://viem.sh/) Ethereum के लिए एक TypeScript इंटरफ़ेस है जो Ethereum के साथ इंटरैक्ट करने के लिए low-level stateless primitives प्रदान करता है।

आप मानक RPC मेथड्स के साथ-साथ [Node RPC पर उपलब्ध कस्टम मेथड्स](/node-rpc/rpc-reference) का उपयोग करके ब्लॉकचेन के साथ इंटरैक्ट करने के लिए Tenderly का उपयोग Viem के साथ कर सकते हैं।

Viem के `createPublicClient` को कॉल करें और निम्नलिखित arguments पास करें:

* `chain`: `viem/chains` से पूर्व-परिभाषित chains में से एक
* `transport`: या तो `http` या `webSocket` को कॉल, और `https` या `wss` RPC URL के साथ इनिशियलाइज़ करें।

<Card title="Code samples: Using Viem with Node RPC" href="" />

```js title="node/samples/viem/0-a-call.ts" showLineNumbers {16-18} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}

const client = createPublicClient({
  chain: mainnet,
  transport: http(
    `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`
  ),
});


console.log("Block Number", await client.getBlockNumber());
```

## Requests को batch करना

Viem आपको [batch requests](https://viem.sh/docs/clients/transports/http#batch-json-rpc) भेजने की अनुमति देता है। batching के साथ, एक ही HTTPS request में कई JSON-RPC कॉल प्रोसेस किए जाते हैं। कई Viem actions को batch किया जाएगा और वर्तमान JavaScript संदेश queue के अंत में निष्पादित किया जाएगा। डिफ़ॉल्ट रूप से, कोई समय विलंब नहीं होता है, लेकिन एक वैकल्पिक `wait` parameter के माध्यम से कॉन्फ़िगर किया जा सकता है।

इसका अर्थ है कि कई viem actions को batch किया जाएगा और वर्तमान JavaScript संदेश queue के अंत में निष्पादित किया जाएगा। डिफ़ॉल्ट रूप से, कोई समय विलंब नहीं होता है, लेकिन एक वैकल्पिक `wait` parameter के माध्यम से कॉन्फ़िगर किया जा सकता है।

```js title="node/samples/viem/0-batch-calls.ts" showLineNumbers {16-21} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}

const client = createPublicClient({
  chain: mainnet,
  transport: http(
    `https://mainnet.gateway.tenderly.co/${process.env.TENDERLY_NODE_ACCESS_KEY}`,
    {
      batch: true,
    }
  ),
});

const [blockNumber, balance, ensName] = await Promise.all([
  client.getBlockNumber(),
  client.getBalance({ address: "0xd2135CfB216b74109775236E36d4b433F1DF507B" }),
  client.getEnsName({ address: "0xd2135CfB216b74109775236E36d4b433F1DF507B" }),
  client.getChainId(),
]);
console.log("Results are in");
console.log({ blockNumber, balance, ensName });

//  So will this
const bnPromise = client.getBlockNumber();

const balancePromise = client.getBalance({
  address: "0xd2135CfB216b74109775236E36d4b433F1DF507B",
});

console.log(await bnPromise);
console.log(await balancePromise);
```

## viem का उपयोग करके transactions को simulate करें

[Simulation RPC methods](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_simulateTransaction) का उपयोग करने के लिए, बस `client.request` मेथड का उपयोग करें:

```js title="node/samples/viem/1-simulate.ts" showLineNumbers {2-15} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const simulation = await client.request({
  method: "tenderly_simulateTransaction",
  params: [
    // transaction object
    {
      from: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      to: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      gas: "0x0",
      gasPrice: "0x0",
      value: "0x0",
      data: "0xa9059cbb00000000000000000000000020a5814b73ef3537c6e099a0d45c798f4bd6e1d60000000000000000000000000000000000000000000000000000000000000001",
    },
    // the block
    "latest",
  ],
});

console.log("Trace");
console.log(JSON.stringify(simulation.trace, null, 2));
console.log("=======================================================");
console.log("Logs");
console.log(JSON.stringify(simulation.logs, null, 2));
console.log("=======================================================");
console.log("Asset Changes");
console.log(JSON.stringify(simulation.assetChanges, null, 2));
console.log("=======================================================");
console.log("Balance Changes");
console.log(JSON.stringify(simulation.balanceChanges, null, 2));
```

## Viem का उपयोग करके transactions को trace करें

पूर्ण रूप से डिकोडेड transaction trace प्राप्त करने के लिए [`tenderly_traceTransaction`](/node-rpc/rpc-reference?network=ethereum-mainnet\&method=tenderly_traceTransaction) का उपयोग करें।

```ts showLineNumbers title="node/samples/viem/2-transaction-trace.ts" {2-6} theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const txTrace = await client.request({
  method: "tenderly_traceTransaction",
  params: [
    // transaction hash
    "0x6b2264fa8e28a641d834482d250080b39cbbf39251344573c7504d6137c4b793"
  ],
});


console.log("Logs");
console.log(JSON.stringify(txTrace.logs, null, 2));
console.log("=======================================================");
console.log("Asset Changes");
console.log(JSON.stringify(txTrace.assetChanges, null, 2));
console.log("=======================================================");
console.log("Balance Changes");
console.log(JSON.stringify(txTrace.balanceChanges, null, 2));
console.log("=======================================================");
```
