<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eric Johnson</title>
    <description>The latest articles on DEV Community by Eric Johnson (@eric_johnson).</description>
    <link>https://dev.to/eric_johnson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263627%2F8afe6879-589e-492c-b1ec-cb39f6dfcf22.png</url>
      <title>DEV Community: Eric Johnson</title>
      <link>https://dev.to/eric_johnson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eric_johnson"/>
    <language>en</language>
    <item>
      <title>Your agent got an HTTP 402, but its money is on the wrong chain. Here's the fix.</title>
      <dc:creator>Eric Johnson</dc:creator>
      <pubDate>Wed, 25 Nov 2026 01:15:34 +0000</pubDate>
      <link>https://dev.to/eric_johnson/your-agent-got-an-http-402-but-its-money-is-on-the-wrong-chain-heres-the-fix-3j26</link>
      <guid>https://dev.to/eric_johnson/your-agent-got-an-http-402-but-its-money-is-on-the-wrong-chain-heres-the-fix-3j26</guid>
      <description>&lt;p&gt;x402 is quickly becoming the way AI agents pay for APIs. The server answers with &lt;code&gt;402 Payment Required&lt;/code&gt; and a small invoice. The agent's x402 client signs a payment and retries, and the data comes back. There are no accounts and no API keys.&lt;/p&gt;

&lt;p&gt;There's a catch that almost every agent builder runs into:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The invoice says "pay 0.01 USDC &lt;strong&gt;on Base&lt;/strong&gt;." Your agent's wallet holds SOL on Solana, or USDC on Ethereum, or some BTC.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The x402 client can't fix that. It signs a payment from a wallet on the invoice's network. If that wallet is empty, the agent is stuck. Bridging by hand works once, but it's not something an autonomous agent can do in the middle of a task.&lt;/p&gt;

&lt;p&gt;This post shows a small, non-custodial way to close that gap with one tool call.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: fund the wallet, not the merchant
&lt;/h2&gt;

&lt;p&gt;You can't just "send money to the merchant from another chain." x402's &lt;code&gt;exact&lt;/code&gt; scheme expects a payment signed by the payer's own wallet on the invoice's network, so a raw transfer from somewhere else wouldn't count.&lt;/p&gt;

&lt;p&gt;What you &lt;em&gt;can&lt;/em&gt; do is make sure the agent's own wallet on that network has enough of the right token. Then the normal x402 flow just works.&lt;/p&gt;

&lt;p&gt;So the steps are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Agent calls an API and gets a &lt;code&gt;402&lt;/code&gt; with an &lt;code&gt;accepts&lt;/code&gt; list.&lt;/li&gt;
&lt;li&gt;Agent hands that 402 body to a funding tool.&lt;/li&gt;
&lt;li&gt;The tool reads the invoice and works out the network and token, for example USDC on Base (&lt;code&gt;eip155:8453&lt;/code&gt;). It then tops up &lt;strong&gt;the agent's own wallet&lt;/strong&gt; there with an exact amount, paid from whatever token the agent holds on any chain.&lt;/li&gt;
&lt;li&gt;Once the funds land, the agent retries the request and its x402 client pays as usual.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since one payment is usually a fraction of a cent, it makes sense to top up a small balance once (say $5). The next few hundred 402s then need no swap at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing it with Swap Ripper
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/swapripper/swap-ripper" rel="noopener noreferrer"&gt;Swap Ripper&lt;/a&gt; is a free-to-connect MCP server (and REST API) that does exactly this. Its &lt;code&gt;fund_x402&lt;/code&gt; tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;accepts x402 &lt;strong&gt;v1 or v2&lt;/strong&gt;, either the JSON body or the base64 &lt;code&gt;PAYMENT-REQUIRED&lt;/code&gt; header&lt;/li&gt;
&lt;li&gt;picks a payment option it can fund, and flags testnet options (testnet tokens come from faucets, not swaps)&lt;/li&gt;
&lt;li&gt;pays from &lt;strong&gt;25+ chains&lt;/strong&gt; (Solana, Ethereum, Bitcoin, Base, Arbitrum, BNB, Tron, NEAR, and more) through the NEAR Intents solver network&lt;/li&gt;
&lt;li&gt;delivers an &lt;strong&gt;exact&lt;/strong&gt; amount to your wallet, with an automatic refund if anything fails&lt;/li&gt;
&lt;li&gt;never holds your funds. It returns a one-time deposit address, and your agent sends the payment itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: decode the invoice (no commitment)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -X POST https://swap-ripper.szydlow45.workers.dev/api/x402 \
  -H &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{
    "payment_required": {
      "x402Version": 2,
      "accepts": [{
        "scheme": "exact",
        "network": "eip155:8453",
        "amount": "10000",
        "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        "payTo": "0xMerchant..."
      }]
    },
    "pay_with_token": "SOL",
    "pay_with_chain": "solana"
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response tells you what the invoice is for, which chain and token it needs, the per-call price (0.01 USDC here), how many calls the top-up covers, and roughly how much SOL it costs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: get a deposit address
&lt;/h3&gt;

&lt;p&gt;Call it again with your wallet details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"payment_required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="err"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"pay_with_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SOL"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"pay_with_chain"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"solana"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"wallet"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0xYourBaseWallet"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"refund_address"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"YourSolanaAddress"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get back &lt;code&gt;deposit_address&lt;/code&gt;, &lt;code&gt;send_exactly&lt;/code&gt;, and a &lt;code&gt;deadline&lt;/code&gt;. For EVM sources you also get a ready-to-sign &lt;code&gt;deposit_tx&lt;/code&gt;. Send the amount, then poll &lt;code&gt;get_swap_status&lt;/code&gt; (it supports &lt;code&gt;wait_seconds&lt;/code&gt; long-polling) until it reports &lt;code&gt;SUCCESS&lt;/code&gt;. Your Base wallet now holds the USDC, and your x402 client can pay.&lt;/p&gt;

&lt;p&gt;If your agent already holds the right token on the right chain, the tool says so and tells you to pay directly. No swap, no fee.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plugging it into your agent
&lt;/h2&gt;

&lt;p&gt;It's a standard remote MCP server (Streamable HTTP, no auth): &lt;code&gt;https://swap-ripper.szydlow45.workers.dev/mcp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Claude Desktop / Cursor&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"swap-ripper"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://swap-ripper.szydlow45.workers.dev/mcp"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ElizaOS&lt;/strong&gt; (with &lt;code&gt;@elizaos/plugin-mcp&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"plugins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"@elizaos/plugin-mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"settings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"mcp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"servers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"swap-ripper"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"streamable-http"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://swap-ripper.szydlow45.workers.dev/mcp"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;LangChain / LangGraph&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain_mcp_adapters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;MultiServerMCPClient&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MultiServerMCPClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"swap-ripper"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://swap-ripper.szydlow45.workers.dev/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"transport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"streamable_http"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_tools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;OpenAI Agents SDK&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agents&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;MCPServerStreamableHttp&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;MCPServerStreamableHttp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://swap-ripper.szydlow45.workers.dev/mcp"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"payer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mcp_servers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Agents that can't use MCP can read the &lt;a href="https://swap-ripper.szydlow45.workers.dev/llms.txt" rel="noopener noreferrer"&gt;llms.txt&lt;/a&gt; or the &lt;a href="https://swap-ripper.szydlow45.workers.dev/openapi.json" rel="noopener noreferrer"&gt;OpenAPI spec&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A good pattern for agent builders
&lt;/h2&gt;

&lt;p&gt;Put this in your agent's instructions:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When an HTTP request returns 402 and your wallet on the invoice's network lacks funds, call &lt;code&gt;fund_x402&lt;/code&gt; with the 402 body, send the deposit, wait for success, then retry the request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That one rule turns "stuck on the wrong chain" into a short detour.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other tools
&lt;/h2&gt;

&lt;p&gt;The same server also does plain cross-chain swaps with a fair-price check against market rates. It can pay an exact amount to someone using any token, and refuel gas (a few dollars of ETH, SOL, BNB and so on on 13 chains). It can also create "pay me in any crypto" links for agents that sell services.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclosure
&lt;/h2&gt;

&lt;p&gt;I built Swap Ripper. It's MIT-licensed and listed in the &lt;a href="https://registry.modelcontextprotocol.io/v0/servers?search=swap-ripper" rel="noopener noreferrer"&gt;official MCP Registry&lt;/a&gt;. It charges a 0.3% fee on swaps, built into the quote (lower for large swaps). If you route swaps through it from your own agent or product, pass &lt;code&gt;referrer: "yourname.near"&lt;/code&gt; and you earn a third of that fee.&lt;/p&gt;

&lt;p&gt;Questions or feature requests are welcome in the &lt;a href="https://github.com/swapripper/swap-ripper" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>mcp</category>
      <category>x402</category>
      <category>crypto</category>
    </item>
  </channel>
</rss>
