<?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: say1j</title>
    <description>The latest articles on DEV Community by say1j (@say1j).</description>
    <link>https://dev.to/say1j</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%2F4254276%2F3f9e6580-78fc-4961-a771-d544cc205208.jpg</url>
      <title>DEV Community: say1j</title>
      <link>https://dev.to/say1j</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/say1j"/>
    <language>en</language>
    <item>
      <title>How an AI agent pays USDC on Base to rent TRON Energy (x402 in practice)</title>
      <dc:creator>say1j</dc:creator>
      <pubDate>Thu, 19 Nov 2026 17:22:34 +0000</pubDate>
      <link>https://dev.to/say1j/how-an-ai-agent-pays-usdc-on-base-to-rent-tron-energy-x402-in-practice-2dd7</link>
      <guid>https://dev.to/say1j/how-an-ai-agent-pays-usdc-on-base-to-rent-tron-energy-x402-in-practice-2dd7</guid>
      <description>&lt;p&gt;Sending USDT on TRON has a hidden cost. A USDT transfer is a smart-contract call, so it needs &lt;strong&gt;Energy&lt;/strong&gt;. If the sending wallet has none, the network burns TRX instead: about &lt;strong&gt;6.5 TRX&lt;/strong&gt; for a typical transfer, or about &lt;strong&gt;13 TRX&lt;/strong&gt; when the recipient has never held USDT.&lt;/p&gt;

&lt;p&gt;The usual way around that is to &lt;strong&gt;rent Energy&lt;/strong&gt; for an hour before you send. Today, 65,000 Energy for one hour rents for about 2.3 TRX, roughly a third of the burn. The catch is that rental sites are built for people: accounts, dashboards, top-ups.&lt;/p&gt;

&lt;p&gt;We run &lt;a href="https://tronenergyfrog.com/" rel="noopener noreferrer"&gt;TronEnergyFrog&lt;/a&gt;, which rents Energy through the website, the Telegram bot &lt;a href="https://t.me/tron_energy_frog_bot" rel="noopener noreferrer"&gt;@tron_energy_frog_bot&lt;/a&gt; and an API. We also wanted an AI agent to do the whole thing on its own, with no account and no API key. That's what &lt;strong&gt;x402&lt;/strong&gt; is for. This post walks through the actual flow, which is a little unusual because the agent pays on one chain (Base) for a resource on another (TRON).&lt;/p&gt;

&lt;h2&gt;
  
  
  What x402 is, in one paragraph
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.x402.org/" rel="noopener noreferrer"&gt;x402&lt;/a&gt; revives the HTTP &lt;code&gt;402 Payment Required&lt;/code&gt; status. A server answers a request with 402 and a &lt;code&gt;PAYMENT-REQUIRED&lt;/code&gt; header describing what it accepts (network, asset, amount, recipient). The client signs a payment and retries the same request with a &lt;code&gt;PAYMENT-SIGNATURE&lt;/code&gt; header. The server has a facilitator verify and settle it, then returns the resource with a &lt;code&gt;PAYMENT-RESPONSE&lt;/code&gt; header. Version 2 uses CAIP-2 network IDs such as &lt;code&gt;eip155:8453&lt;/code&gt; for Base.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: discover
&lt;/h2&gt;

&lt;p&gt;Everything an agent needs is in one public document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.tronenergyfrog.com/v1/x402
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;"registration_required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"x402_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"quote_endpoint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST /v1/x402/quotes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"payment_endpoint_template"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST /v1/x402/rentals/{quote_id}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"status_endpoint_template"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"GET /v1/x402/rentals/{quote_id}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"accepted"&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="nl"&gt;"network"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"eip155:8453"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"network_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Base"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"asset"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USDC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"preferred"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="nl"&gt;"network"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"network_name"&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;"asset"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USDC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"preferred"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;h2&gt;
  
  
  Step 2: get a free quote
&lt;/h2&gt;

&lt;p&gt;Energy prices move through the day, and the TRX/USD rate moves too. So the agent first asks for a quote, which locks both for 10 minutes. Creating one costs nothing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST https://api.tronenergyfrog.com/v1/x402/quotes \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"target_address":"T...sender","energy_amount":65000,"duration_seconds":3600}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response includes &lt;code&gt;quote_id&lt;/code&gt;, &lt;code&gt;price_trx&lt;/code&gt;, the exact USDC amount (&lt;code&gt;payment_amount_atomic&lt;/code&gt;, six decimals) and &lt;code&gt;valid_until&lt;/code&gt;. &lt;strong&gt;&lt;code&gt;target_address&lt;/code&gt; must be the wallet that will send the USDT&lt;/strong&gt;, because Energy is delegated to the sender, not the recipient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: pay the quote
&lt;/h2&gt;

&lt;p&gt;Now the agent POSTs to the quote's payment URL. The first request returns &lt;code&gt;402&lt;/code&gt; with the requirements. An x402 client signs a USDC transfer authorization and retries automatically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;wrapFetchWithPaymentFromConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@x402/fetch"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;ExactEvmScheme&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@x402/evm/exact/client"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;privateKeyToAccount&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"viem/accounts"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;privateKeyToAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BASE_PRIVATE_KEY&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="sb"&gt;`0x${string}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payingFetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wrapFetchWithPaymentFromConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;schemes&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;network&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"eip155:8453"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ExactEvmScheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&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="c1"&gt;// Refuse anything above $5 before signing.&lt;/span&gt;
  &lt;span class="n"&gt;spendControls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;maxAmountPerPayment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"$5"&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;payingFetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="sb"&gt;`https://api.tronenergyfrog.com/v1/x402/rentals/${quoteId}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&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;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 202 once the payment is verified&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use a dedicated wallet that holds only what the agent is allowed to spend, and keep the spend cap low. The SDK checks it before anything is signed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: poll until the Energy lands
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.tronenergyfrog.com/v1/x402/rentals/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;quote_id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The status moves from &lt;code&gt;settling&lt;/code&gt; to &lt;code&gt;fulfillment_pending&lt;/code&gt; and then to &lt;code&gt;succeeded&lt;/code&gt; once Energy is delegated on TRON. The agent can now send its USDT without burning TRX.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the server keeps this safe
&lt;/h2&gt;

&lt;p&gt;A few design choices matter once real money moves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Verify, record, then settle.&lt;/strong&gt; The payment is verified first and recorded in our database before settlement starts. If anything fails in between, nothing is charged twice and nothing is delivered unpaid. The x402 spec recommends this order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The quote is the source of truth.&lt;/strong&gt; The amount, asset and payee in the payment must match the quote exactly, and a payment can't be reused for another quote.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expired or unknown quotes are rejected before verification&lt;/strong&gt;, so a signature for a stale price is never settled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signed attempts are rate-limited per IP.&lt;/strong&gt; Each one costs a facilitator call, so forged signatures can't run up costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  An MCP server, so agents don't need to write any of this
&lt;/h2&gt;

&lt;p&gt;If your agent speaks MCP (Claude, Cursor, Windsurf and others), you can skip the code:&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;"tronenergyfrog"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tronenergyfrog-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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without any configuration it gives the agent live prices, free quotes and rental status. Add &lt;code&gt;TRONENERGYFROG_EVM_PRIVATE_KEY&lt;/code&gt; and &lt;code&gt;pay_x402_quote&lt;/code&gt; appears, capped by &lt;code&gt;TRONENERGYFROG_MAX_PAYMENT_USD&lt;/code&gt; (default $5). Tools that spend money are marked as destructive and tell the agent to confirm the address, amount and price with you first. The source is on &lt;a href="https://github.com/say1j/tron-energy-rental/tree/main/mcp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; under MIT, and it's listed in the official MCP Registry as &lt;code&gt;io.github.say1j/tronenergyfrog&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not an agent? The same rental works three other ways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Guest checkout&lt;/strong&gt; on the website, with no account. No fee is added when you pay in TRX; other coins go through Heleket, which adds its own fee.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Telegram bot &lt;a href="https://t.me/tron_energy_frog_bot" rel="noopener noreferrer"&gt;@tron_energy_frog_bot&lt;/a&gt;&lt;/strong&gt;: check how much Energy a transfer needs and rent it from your phone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Account API&lt;/strong&gt; with a key from the same bot, for apps that rent from a prepaid TRX balance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Prices are public: the &lt;a href="https://tronenergyfrog.com/tron-energy-price" rel="noopener noreferrer"&gt;price page&lt;/a&gt; shows the live rate, a 7-day hourly history and the cheapest hours, and the same data is available as JSON without a key at &lt;code&gt;https://api.tronenergyfrog.com/v1/rates/energy/default&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The x402 Foundation has an open draft for a TRON payment binding that would let agents pay in USDT on TRON itself (via Permit2). Once it's final, the whole flow can stay on one chain. Until then, Base USDC works today.&lt;/p&gt;

&lt;p&gt;If you're building agents that move USDT, I'd like to hear what's missing. Comments are open.&lt;/p&gt;

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