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

# Node RPC Access

> Learn how to set up a Web3 Action with access to the Mainnet through Node RPC.

You can access [Node RPC](/node-rpc/overview) directly from your Web3 Action functions. This allows you to send transactions on the Mainnet or testnets and read on-chain data automatically through Web3 Actions.

Setting up Web3 Actions to access the blockchain requires minimal setup, a single Javascript variable. No need to worry about copying/pasting RPC URLs, managing secret keys, etc. Tenderly takes care of all this for you in the background.

In this guide, you’ll learn how to configure your Web3 Action function code to use Tenderly’s production node to access the Mainnet.

## Node RPC in Context

In Web3 Actions, access to Tenderly’s node is enabled through the `context` object. Learn more about [Web3 Actions Context](/monitoring/web3-actions/references/context) here.

The `context` object contains a property called `gateways` which gives you access to the `getGateway()` method. This method requires one argument `Network`, which is used to specify the network you want to access.

The `Network` argument is also an object which gives you access to all the supported networks in Node RPC:

* `Network.MAINNET`
* `Network.GOERLI`
* `Network.SEPOLIA`
* `Network.HOLESKY`
* `Network.POLYGON`
* `Network.MUMBAI`
* `Network.OPTIMISTIC`
* `Network.OPTIMISTIC_GOERLI`
* `Network.ARBITRUM_SEPOLIA`
* `Network.BASE`
* `Network.BASE_GOERLI`
* `Network.BOBA_ETHEREUM`
* `Network.BOBA_GOERLI`
* `Network.BOBA_BINANCE`
* `Network.BOBA_BINANCE_RIALTO`

You can see the network list in **@tenderly/actions** npm package [here](https://github.com/Tenderly/tenderly-actions/blob/main/packages/actions/src/actions.ts).

To demonstrate how all of this comes together, here’s an example Javascript variable that is configured to access the Mainnet:

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const defaultGatewayURL = context.gateways.getGateway(Network.MAINNET);
```

## Example Web3 Action function to access the Mainnet

Let’s create a simple Web3 Action that will get triggered every time a new block is mined on the Mainnet. Each time a block gets mined, the Web3 Action will execute the custom code, also referred to as “function”. Read more about [Web3 Action functions](/monitoring/web3-actions/references/functions-events-triggers#action-functions) here.

For the sake of simplicity, the example function below will get the block number of the latest block mined and log it to the console.

You can read the comments to understand what each line of code does.

```jsx title="example.jsx" showLineNumbers theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
// Required libraries that must be included for the code to work
const ethers = require('ethers');
const { Network } = require('@tenderly/actions');

// Do not change the default 'actionFn' name.
const actionFn = async (context, blockEvent) => {
  // Setting a variable that will store the Node RPC RPC URL and secret key
  const defaultGatewayURL = context.gateways.getGateway(Network.MAINNET);

  // Using the Ethere.js provider class to call the RPC URL
  const provider = new ethers.providers.JsonRpcProvider(defaultGatewayURL);

  // Logging the block number of the latest mined block
  console.log(await provider.getBlockNumber());
};

// Exporting the default module. Do not change this.
module.exports = { actionFn };
```

Next, go to the **Dashboard** → **Web3 Actions** → **Add Action**.

<Frame caption="Web3 Action set up wizard">
  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/web3-actions/web3-gateway-access-1.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=cd389b5d5a1b03614749f8109efc0564" alt="Web3 Action set up wizard" width="924" height="516" data-path="images/web3-actions/web3-gateway-access-1.webp" />
</Frame>

* For the Trigger Type, select **Block.**
* In the **Function** textbox, paste the code from the example above and click **Next**.

<Frame caption="Custom code that is executed when the Web3 Action is triggered">
  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/web3-actions/web3-gateway-access-2.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=59de42e2f199d74202869440163cd350" alt="Custom code that is executed when the Web3 Action is triggered" width="924" height="516" data-path="images/web3-actions/web3-gateway-access-2.webp" />
</Frame>

* Set the **Trigger** by selecting the network. In our case, that is **Mainnet**.
* Also, set the **Block Period** to tell Tenderly how often to execute the Web3 Action function. For example, if you put 1, the Web3 Action will be executed once every block is mined.
* In the **Info** fields, **add a name** for the Web3 Action and an optional description.
* You can also set a **Destination** where you’ll [receive notifications](/monitoring/web3-actions/references/notifications) about failed executions of the Web3 Action.
* Lastly, **click Create** to deploy the Web3 Action.

From the **Execution History** page, we can see that the Web3 Action is being executed successfully.

<Frame caption="Web3 Action execution history">
  <img src="https://mintcdn.com/tenderly/XsEZlaGXYskrtN68/images/web3-actions/web3-gateway-access-3.webp?fit=max&auto=format&n=XsEZlaGXYskrtN68&q=85&s=6c237dfe44b6ec64d1f793d57b05d224" alt="Web3 Action execution history" width="924" height="516" data-path="images/web3-actions/web3-gateway-access-3.webp" />
</Frame>

You can click on the **Execution ID** to see details about the executed Web3 Action and the payload in JSON.

### Helpful resources

For more information on how to manage your Web3 Actions and monitor execution errors, read the following guides:

* [Managing Web3 Actions](/monitoring/web3-actions/references/lifecycle)
* [Error Reporting for Web3 Actions](/monitoring/web3-actions/references/error-reporting)
