<?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: a2taka</title>
    <description>The latest articles on DEV Community by a2taka (@a2taka-sourse).</description>
    <link>https://dev.to/a2taka-sourse</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%2F4264564%2F262034f1-6d1e-4663-a636-e6decbc534e8.jpg</url>
      <title>DEV Community: a2taka</title>
      <link>https://dev.to/a2taka-sourse</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/a2taka-sourse"/>
    <language>en</language>
    <item>
      <title>Pay for a Telegraph ask from escrow, then prove the charge in the ledger (testnet, Node.js)</title>
      <dc:creator>a2taka</dc:creator>
      <pubDate>Wed, 25 Nov 2026 11:01:52 +0000</pubDate>
      <link>https://dev.to/a2taka-sourse/pay-for-a-telegraph-ask-from-escrow-then-prove-the-charge-in-the-ledger-testnet-nodejs-9i3</link>
      <guid>https://dev.to/a2taka-sourse/pay-for-a-telegraph-ask-from-escrow-then-prove-the-charge-in-the-ledger-testnet-nodejs-9i3</guid>
      <description>&lt;p&gt;An agent that buys data needs two things: a payment path that works, and a way to check afterwards that it was charged what it should have been. &lt;a href="https://docs.telegraphprotocol.com" rel="noopener noreferrer"&gt;Telegraph&lt;/a&gt; gives you both on testnet: you deposit once into an escrow, pay each ask with a signature, and every charge later appears in a public epoch ledger block. This tutorial walks through that loop in about 15 minutes (plus a wait for the next ledger root, see step 3). No real money.&lt;/p&gt;

&lt;p&gt;Why escrow and not only x402 &lt;code&gt;exact&lt;/code&gt;? On the devnode I hit &lt;code&gt;settlement failed&lt;/code&gt; and facilitator timeouts on the per-request rails (&lt;a href="https://github.com/telegraphprotocol/bounties/issues/214" rel="noopener noreferrer"&gt;#214&lt;/a&gt;, &lt;a href="https://github.com/telegraphprotocol/bounties/issues/215" rel="noopener noreferrer"&gt;#215&lt;/a&gt;), and failed asks on those rails can still settle (&lt;a href="https://github.com/telegraphprotocol/bounties/issues/228" rel="noopener noreferrer"&gt;#228&lt;/a&gt;). On the escrow rail a failed ask was not charged in my runs. The catch is that the signature has to be exactly right, so I packaged that part: &lt;a href="https://github.com/a2taka-sourse/telegraph-escrow" rel="noopener noreferrer"&gt;telegraph-escrow&lt;/a&gt; (MIT, one dependency: &lt;code&gt;viem&lt;/code&gt;). It was extracted from &lt;a href="https://github.com/a2taka-sourse/escalation-ledger" rel="noopener noreferrer"&gt;Escalation Ledger&lt;/a&gt;, my entry for mission 05 (Conflict Intelligence).&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Node.js 20+&lt;/li&gt;
&lt;li&gt;A throwaway wallet with about 0.0005 Sepolia ETH (any Sepolia faucet) for the deposit gas&lt;/li&gt;
&lt;li&gt;Never a key that holds real funds&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Install and set a throwaway key
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/a2taka-sourse/telegraph-escrow &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; telegraph-escrow &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm install
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"EVM_PRIVATE_KEY=0x&amp;lt;a throwaway testnet key&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .env     &lt;span class="c"&gt;# .env is already in .gitignore&lt;/span&gt;
npm &lt;span class="nb"&gt;test&lt;/span&gt;                                                         &lt;span class="c"&gt;# 7 offline checks, no network&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Look before you pay (free)
&lt;/h2&gt;

&lt;p&gt;Discovery costs nothing, and an unpaid ask returns &lt;code&gt;402 Payment Required&lt;/code&gt;, which is the price list.&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://devnode.telegraphprotocol.com/engine/v1/intents/NEWS_SEARCH_GENERAL
curl -X POST https://devnode.telegraphprotocol.com/engine/v1/ask -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"intent":"NEWS_SEARCH_GENERAL","params":{"query":"Telegraph protocol testnet"}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 402 lists several ways to pay, including &lt;code&gt;escrow&lt;/code&gt; on Ethereum Sepolia at $0.01.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Fund the escrow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node bin/cli.mjs fund 5        &lt;span class="c"&gt;# mints 5 test USDC, approves, deposits to the escrow Diamond on Ethereum Sepolia&lt;/span&gt;
node bin/cli.mjs balance       &lt;span class="c"&gt;# wait until deposit_not_yet_in_root is false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new deposit can show as &lt;code&gt;available&lt;/code&gt; while asks are still refused, until the next ledger root is published (about 1.5 hours in my case, &lt;a href="https://github.com/telegraphprotocol/bounties/issues/232" rel="noopener noreferrer"&gt;#232&lt;/a&gt;). Do this step first and come back later.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Ask, with a ceiling
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node bin/cli.mjs ask &lt;span class="s1"&gt;'{"intent":"NEWS_SEARCH_GENERAL","params":{"query":"Telegraph protocol testnet"}}'&lt;/span&gt; 30000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;30000&lt;/code&gt; is &lt;code&gt;max_budget_usdc&lt;/code&gt; in micro-USDC: the most you authorise. The node may route to several ranked miners and bills one row per answer used. My real run on 2026-11-24 authorised 30,000 and was charged 10,000:&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;"ok"&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="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"authorized_uusdc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"charged_uusdc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"verify"&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;"epoch_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"receipt_hash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0x2c71…d992"&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;The client also refuses to sign anything above &lt;code&gt;maxPerCallUusdc&lt;/code&gt; (default 50,000 = $0.05): your first guard rail. In code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;ask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verifyDelivery&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;"./src/index.mjs"&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;r&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;ask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"NEWS_SEARCH_GENERAL"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;query&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_budget_usdc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30000&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;privateKey&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;EVM_PRIVATE_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxPerCallUusdc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50000&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&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="s2"&gt;"not charged:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// never throws on network or payment failure&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. What the signature must look like
&lt;/h2&gt;

&lt;p&gt;This is the part that costs hours by hand; the package does it for you.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ask once without payment; the 402's &lt;code&gt;escrow&lt;/code&gt; option has an &lt;code&gt;extra.message&lt;/code&gt; template.&lt;/li&gt;
&lt;li&gt;Fill &lt;code&gt;{from}&lt;/code&gt; with your address &lt;strong&gt;in lowercase&lt;/strong&gt;, a &lt;strong&gt;fresh nonce&lt;/strong&gt;, and a validity window &lt;strong&gt;under 2 minutes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Sign the filled text with &lt;code&gt;personal_sign&lt;/code&gt; (EIP-191), not EIP-712.&lt;/li&gt;
&lt;li&gt;Send &lt;code&gt;X-PAYMENT: base64({ x402Version: 2, scheme: "escrow", network, payload: { signature, authorization } })&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  6. Verify the charge in the ledger
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node bin/cli.mjs verify &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;epoch_id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;receipt_hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;     &lt;span class="c"&gt;# "pending" until the epoch block is recorded&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reads &lt;code&gt;/v1/blocks/{epoch}/deliveries/{receipt_hash}&lt;/code&gt; and checks that the recorded row matches your purchase (payer, intent, amount, miner). Limits: the Merkle leaf encoding is not published, so the proof is returned but not recomputed locally (&lt;a href="https://github.com/telegraphprotocol/bounties/issues/231" rel="noopener noreferrer"&gt;#231&lt;/a&gt;). Also check the answer itself: answers from the generic LLM fallback and empty verdicts can still be charged (&lt;a href="https://github.com/telegraphprotocol/bounties/issues/233" rel="noopener noreferrer"&gt;#233&lt;/a&gt;, &lt;a href="https://github.com/telegraphprotocol/bounties/issues/234" rel="noopener noreferrer"&gt;#234&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Package: &lt;a href="https://github.com/a2taka-sourse/telegraph-escrow" rel="noopener noreferrer"&gt;https://github.com/a2taka-sourse/telegraph-escrow&lt;/a&gt; — issues welcome, especially "it didn't work for me"&lt;/li&gt;
&lt;li&gt;Live demo (testnet; first load can take a minute): &lt;a href="https://escalation-ledger.onrender.com" rel="noopener noreferrer"&gt;https://escalation-ledger.onrender.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;App code and write-up: &lt;a href="https://github.com/a2taka-sourse/escalation-ledger" rel="noopener noreferrer"&gt;https://github.com/a2taka-sourse/escalation-ledger&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Telegraph docs: &lt;a href="https://docs.telegraphprotocol.com" rel="noopener noreferrer"&gt;https://docs.telegraphprotocol.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Disclosure: this tutorial is part of my entry to Telegraph Hackathon Season II, which has cash prizes.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>web3</category>
      <category>javascript</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
