Pre-alphaWork in progress
Skip to content

Using a managed gateway ​

A managed gateway gives your application an HTTPS RPC URL into the Direct RPC marketplace, with nothing to install or operate. Direct runs the gateway for you, and it reaches the same independent providers as a local gateway. Use it for browser applications, quick trials, and environments where you cannot run the Direct client.

Requests to a managed gateway pass through Direct's hosting infrastructure on their way to a provider. For direct peer-to-peer access with no centralized gateway in the request path, host a local gateway instead. Should I use a local or managed gateway? compares the two.

Create a gateway ​

Sign in to Direct and open Gateways. Select Create gateway, choose the blockchain network, and give the gateway a name you can recognize, such as my-app-development. You can also create a gateway from Account › Gateways in the Direct client.

Copy its gateway URL, including any access prefix containing the key. The base address ends before the network's service/<network> path.

Create a separate gateway for each application and environment, so you can manage each one's access independently, and replace one application's key without changing the others.

Build your RPC URL ​

Your RPC URL is the gateway URL you copied, including its access prefix, followed by the service URL of a chain. For Ethereum mainnet, the service URL is service/ethereum:

text
<gateway-url>/service/ethereum

If the interface displays a complete network endpoint, its gateway URL is the portion before /service/<network>; do not append that service path twice. For another network, append the service URL listed in Supported chains. If WebSocket access is enabled, the gateway lists its own wss:// address; use the same service path there.

Choose providers ​

Open the gateway's Provider selection settings to set your maximum request price and choose whether to favor price, latency, or a balance of both. Pricing explains how these settings affect provider choice.

Make a request ​

Check the chain ID to confirm that the gateway reaches a provider for the network:

sh
curl -s "<gateway-url>/service/ethereum" \
  -H 'Content-Type: application/json' \
  -d '{ "jsonrpc": "2.0", "id": 1, "method": "eth_chainId", "params": [] }'
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x1" }

0x1 is Ethereum mainnet's chain ID. If the request fails, check the gateway URL and the selected network. Troubleshooting requests walks through connection and provider errors.

Use it in your application ​

Set your library's RPC transport to the full <gateway-url>/service/ethereum URL, and keep the library's chain configuration aligned with the network in that URL.

viem

ts
import { createPublicClient, http } from "viem"
import { mainnet } from "viem/chains"

const client = createPublicClient({
  chain: mainnet,
  transport: http("<gateway-url>/service/ethereum"),
})

ethers

ts
import { JsonRpcProvider } from "ethers"

const provider = new JsonRpcProvider("<gateway-url>/service/ethereum")

Restrict access ​

A URL embedded in a web page is visible to its users, so treat a managed gateway's key as public in a browser. For each gateway:

  1. For a browser application, configure the allowed origins, including the development origin if needed.
  2. Test a request from the intended application.
  3. Test a request from a disallowed origin and confirm that access is rejected.
  4. If the key is exposed outside its intended use, replace it in the gateway settings and update the complete RPC URL wherever the old key is used.

Origin restrictions help control browser use, but they do not make an exposed key secret: non-browser callers can supply an Origin header themselves.

Managed access has its own request limits and a hosting fee in addition to provider charges; see Pricing.

Fund the gateway ​

A managed gateway's requests are paid from your account's balance on Base. Managing payments and spending covers adding funds and your devices.

Moving to a local gateway ​

A managed gateway and a local gateway take the same requests at the same service paths. To move, run a local gateway and change the gateway URL in your application; the providers and their checks stay the same. Hosting a local gateway covers running one in your own environment.

Unstoppable Infrastructure.