# Use blockchain RPC in Coinbase AgentKit agents with BlockVectra

> Original page: https://docs.blockvectra.com/en/guides/coinbase-agentkit/

Coinbase AgentKit sends its onchain actions through a wallet provider, and `ViemWalletProvider` accepts any viem `WalletClient`. Give that client `https://api.blockvectra.com/v1/base_mainnet/public` as its transport and AgentKit's RPC traffic uses BlockVectra without an API key. A key adds the rest; the Free Plan gives 30,000,000 CU per 30-day window. Checked 2026-10-10.

```typescript
import { AgentKit, ViemWalletProvider } from "@coinbase/agentkit";
import { getLangChainTools } from "@coinbase/agentkit-langchain";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";

const client = createWalletClient({
  account: privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as `0x${string}`),
  chain: base,
  transport: http("https://api.blockvectra.com/v1/base_mainnet/public"),
});

const agentKit = await AgentKit.from({ walletProvider: new ViemWalletProvider(client) });
const tools = await getLangChainTools(agentKit);
```

Install with `npm install @coinbase/agentkit @coinbase/agentkit-langchain viem`. `tools` is the list AgentKit's [LangChain integration](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/README.md) passes to `createAgent({ model, tools })`; the wallet key stays in your environment.

## Use an API key

The public endpoint serves only the methods in each chain's `public.methods`. For the others, send the key in the `x-api-key` header and keep it in the environment, so it never appears in the URL:

```typescript
const transport = http("https://api.blockvectra.com/v1/base_mainnet", {
  fetchOptions: { headers: { "x-api-key": process.env.BLOCKVECTRA_API_KEY! } },
});
```

If a client cannot set headers, the key can go in the URL path (`/v1/{chain}/{api_key}`) instead; URLs can end up in access logs, so prefer the header.

Create the key without a browser with the four steps in the [programmatic sign-up guide](https://docs.blockvectra.com/en/guides/programmatic-signup/): challenge, signature, login, then `POST /keys`. Developers can also [create a key in the console](https://console.blockvectra.com/login/?next=%2Fkeys%2F). One key works on every chain, so switching the agent to another network only changes the chain slug and the viem chain object.

## Combine AgentKit actions with the docs MCP server

AgentKit's TypeScript package exposes its actions as LangChain tools, so MCP tools from LangChain's adapter go into the same `tools` array. Follow the [LangChain guide](https://docs.blockvectra.com/en/guides/langchain/#add-the-docs-mcp-server) to load `https://docs.blockvectra.com/mcp`, then merge:

```typescript
const agent = createAgent({ model: "claude-sonnet-5", tools: [...tools, ...(await adapter.listTools())] });
```

The agent gets AgentKit's wallet actions plus BlockVectra's `list_chains`, `get_status`, `rpc_call` and `read_doc`, listed on the [MCP server page](https://docs.blockvectra.com/en/guides/mcp-server/). Connecting needs no key.

## Errors you may see

| Response                              | Meaning                                       | What to do                                                              |
| ------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------- |
| HTTP 401, `-32024`, `missing_api_key` | A keyed request was sent without a key        | Send the key in the `x-api-key` header (or the URL path)                |
| HTTP 401, `-32024`, `invalid_api_key` | Key unknown, disabled or revoked              | Check the key in the console; a new key takes a few seconds to activate |
| `-32601`, `method_not_public`         | Method is not in the chain's `public.methods` | Switch that transport from `/public` to the keyed URL                   |

Each BlockVectra error includes `data.reason` and a `docs_url`; the full list is on the [errors page](https://docs.blockvectra.com/en/errors/).

## Official documentation

* [coinbase/agentkit on GitHub](https://github.com/coinbase/agentkit)
* [viem HTTP transport](https://viem.sh/docs/clients/transports/http.html)

## Common questions

**Does BlockVectra see the wallet private key?** No. The viem account signs locally; the endpoint receives reads and signed raw transactions.

**Can the agent read logs through the public endpoint?** No. `eth_getLogs` and the Data API need an API key.

**Does the key go in the MCP tool arguments?** No. Keep it in the environment or the MCP client headers.

## Next steps

* [Agent framework overview](https://docs.blockvectra.com/en/guides/agent-frameworks/) for LangChain, ElizaOS, viem and wagmi.
* [Connect an AI agent](https://docs.blockvectra.com/en/guides/ai-agents/) to discover endpoints with MCP, llms.txt and OpenAPI.
* [Billing rules](https://docs.blockvectra.com/en/guides/billing-rules/) for CU metering, rate limits and non-billed errors.
