# Coinbase AgentKit

Create an AgentKit action provider with three actions matching the MCP names. The paid action uses the official x402 fetch wrapper configured with the AgentKit wallet signer.

```ts
async function buyDispatchPlan(fetchWithPayment, opportunity) {
  const input = {
    opportunity_id: opportunity.opportunity_id,
    power_kw: 25,
    energy_kwh: 50,
    deadline: opportunity.deadline,
    risk_profile: "balanced"
  };

  const challenge = await fetch("https://energy.netzhandwerker.de/v3/dispatch-plan", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(input)
  });
  if (challenge.status === 409) throw new Error("Opportunity rejected before payment");
  if (challenge.status !== 402) throw new Error(`Expected 402, got ${challenge.status}`);

  const settled = await fetchWithPayment("https://energy.netzhandwerker.de/v3/dispatch-plan", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(input)
  });
  if (!settled.ok) throw new Error(`Settlement failed: ${settled.status}`);
  return settled.json();
}
```

Register this function through an AgentKit `ActionProvider` named `buy_dispatch_plan`. Create the opportunity first with plain `fetch`; use the same pattern for `buy_market_brief`.

