Telegram bot USDC payments
Telegram sellers often can't use Stripe. Here's a minimal flow where the bot quotes a price, the user pays USDC and sends the tx hash, and the bot verifies it and delivers.
Flow
- User sends
/buy. The bot replies with your address, the price and a payment link frompaymentURI(). - User pays from their wallet and sends the tx hash to the bot.
- The bot calls
verifyPayment(). On success it sends the invite link or file and records the tx so it can't be reused.
Code (grammY, Node)
import { Bot } from "grammy";
import { verifyPayment, paymentURI } from "paidonchain";
const bot = new Bot(process.env.BOT_TOKEN);
const PAY_TO = process.env.PAY_TO, PRICE = "10";
const used = new Set(); // use a real database in production
bot.command("buy", ctx => ctx.reply(
`Send ${PRICE} USDC on Base to:\n${PAY_TO}\n\nWallet link: ${paymentURI({ to: PAY_TO, amount: PRICE })}\n\nThen paste your transaction hash here.`));
bot.hears(/^0x[0-9a-fA-F]{64}$/, async ctx => {
const tx = ctx.message.text.toLowerCase();
if (used.has(tx)) return ctx.reply("That transaction was already used.");
const r = await verifyPayment({ chain: "base", tx, to: PAY_TO, minAmount: PRICE });
if (r.code === "PENDING") return ctx.reply("Almost there. Send the hash again in ~10 seconds.");
if (!r.ok) return ctx.reply("Payment not verified: " + r.reason);
used.add(tx);
await ctx.reply("Paid ✓ Here's your access: " + process.env.INVITE_LINK);
});
bot.start();
Notes
- Persist
usedin a database. An in-memory Set is lost on restart. - Generate a single-use invite link per buyer if you're selling group access.
- Running many bots? The hosted API saves you running RPC infrastructure.