bundler-relay

Overview

The Bundler Relay is a secure proxy service that protects the ERC-4337 bundler API key from public exposure while enabling open-source AI agents to submit UserOperations. It acts as an authentication layer between public clients (like the OpenClaw agent) and the private Alchemy bundler infrastructure.

In the Owl Smart Wallet architecture, AI agents cannot directly access the bundler because doing so would require embedding the API key in open-source code. The relay solves this by:

  1. Accepting authenticated requests from verified OpenClaw clients

  2. Injecting the bundler API key from GCP Secret Manager

  3. Forwarding the request to the private bundler endpoint

  4. Returning the response to the client

This architecture enables autonomous agent operation without compromising bundler credentials.


Architecture

┌─────────────────┐      ┌──────────────────┐      ┌─────────────────┐
│  OpenClaw Agent │─────▶│  Bundler Relay   │─────▶│ Alchemy Bundler │
│  (Public Code)  │      │ (API Key Shield) │      │ (Private)       │
└─────────────────┘      └──────────────────┘      └─────────────────┘


                         GCP Secret Manager
                         (owl-bundler-api-key)

Components:

  • Public Agent — OpenClaw agent or owl-wallet MCP server with no embedded secrets

  • Bundler Relay — This service, deployed on Google Cloud Run

  • Private Bundler — Alchemy ERC-4337 bundler with API key authentication

  • Secret Manager — GCP service storing the bundler API key


Security Features

The relay implements multiple layers of protection:

Feature
Description

API Key Protection

Bundler API key stored in GCP Secret Manager, never in code or environment

Client Authentication

Requires x-openclaw-client header with valid client identifier

Method Whitelisting

Only ERC-4337 JSON-RPC methods allowed (eth_sendUserOperation, eth_estimateUserOperationGas, etc.)

Rate Limiting

60 requests/minute per IP address to prevent abuse

Request Validation

Full JSON-RPC 2.0 structure validation before forwarding

Timeout & Retry

30-second timeout with automatic retry on 5xx errors

HTTPS Only

TLS termination at Cloud Run ingress

Threat Model:

  • Prevents: API key exposure in public repositories, unauthorized bundler access, method injection attacks

  • Assumes: GCP infrastructure security, Cloud Run service account permissions properly scoped

  • Does not protect against: DoS via rate limit exhaustion (mitigated by per-IP limiting)


Endpoints

Health Check

Returns service health status. Used by Cloud Run for readiness probes.

Response:


Version

Returns service version and build information.

Response:


JSON-RPC Relay

Forwards ERC-4337 JSON-RPC requests to the bundler with API key injection.

Required Headers:

Header
Required
Description

x-openclaw-client

Yes

Client identifier: owl-agent, owl-wallet, openclaw-sdk

x-openclaw-version

No

Client version in semver format (e.g., 1.0.0)

Content-Type

Yes

Must be application/json

Request Body (JSON-RPC 2.0):

Allowed Methods:

  • eth_sendUserOperation

  • eth_estimateUserOperationGas

  • eth_getUserOperationByHash

  • eth_getUserOperationReceipt

  • eth_supportedEntryPoints

Response:

Proxied response from the bundler, unchanged.

Error Responses:

Status
Condition

400

Missing x-openclaw-client header

400

Invalid JSON-RPC structure

403

Method not whitelisted

429

Rate limit exceeded (60 req/min)

500

Bundler communication error

503

Secret Manager unavailable


Local Development

Prerequisites

  • Node.js 18+

  • Bundler endpoint (Alchemy or local bundler)

  • Bundler API key

Setup

Edit .env:

Note: In local development, the API key is read from .env. In production, it's fetched from GCP Secret Manager.

Run

Test


Production Deployment

Prerequisites

  • GCP project with billing enabled

  • Cloud Run and Secret Manager APIs enabled

  • Bundler API key stored in Secret Manager

Create Secret

Deploy to Cloud Run

Environment Variables:

Variable
Description
Example

BUNDLER_URL

Base URL of the bundler endpoint

https://eth-mainnet.g.alchemy.com/v2

GOOGLE_CLOUD_PROJECT

GCP project ID for Secret Manager

owl-production

PORT

HTTP port (auto-set by Cloud Run)

8080

Verify Deployment


Integration with OpenClaw Agent

The OpenClaw agent's owl-wallet MCP server uses the relay for all bundler interactions:

Key Points:

  • No API key in agent code — The relay injects it server-side

  • Automatic retry — The relay handles transient bundler failures

  • Rate limiting awareness — Agents should implement exponential backoff on 429 responses

  • Client header required — All requests must identify themselves via x-openclaw-client


Monitoring and Operations

Cloud Run Metrics

Monitor these metrics in GCP Console:

  • Request count — Track relay usage

  • Request latency — P50/P95/P99 latencies to bundler

  • Error rate — 4xx/5xx responses

  • Instance count — Autoscaling behavior

Secret Rotation

To rotate the bundler API key:

The relay fetches the latest secret version on startup and caches it in memory.

Rate Limit Tuning

To adjust rate limits, modify the RATE_LIMIT_PER_MINUTE environment variable:

Default is 60 requests/minute per IP.


Troubleshooting

400: Missing x-openclaw-client header

Cause: Request missing required authentication header

Solution: Add header to all /rpc requests:


403: Method not allowed

Cause: Attempting to call a non-whitelisted JSON-RPC method

Solution: Only use ERC-4337 bundler methods:

  • eth_sendUserOperation

  • eth_estimateUserOperationGas

  • eth_getUserOperationByHash

  • eth_getUserOperationReceipt

  • eth_supportedEntryPoints


429: Rate limit exceeded

Cause: More than 60 requests/minute from the same IP

Solution: Implement exponential backoff in client code:


503: Secret unavailable

Cause: Cloud Run cannot access GCP Secret Manager

Solution: Verify service account permissions:

If missing, grant access:

Last updated