最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to correctly get transaction status via tonapi.io webhooks? - Stack Overflow

programmeradmin2浏览0评论

I'm integrating TON API and trying to set up receiving transaction notifications via webhooks. However, I'm facing an issue where TON API returns 401 Unauthorized or illegal base32 data at input byte 2.

Here is an example of the webhook request body I receive:

{
   "event_type": "account_tx",
   "account_id": "0:add4bfa3b10899fe5a53f8f5585705156feac70ee25df9b08de867596cbd7fab",
   "lt": 53812960000003,
   "tx_hash": "6ddd3abd23caacc8186c075a9e69a942a206caaf532f90f6e0cca5b52029609d"
}

I am passing account_id as a query parameter, but the API returns an illegal base32 data error. I am also passing my API key in the "Authorization": "Bearer <TON_API_KEY>" header.

How should I correctly process this webhook and fetch the transaction status? Should I convert account_id to another format?

I have tried the following approaches:

Passing account_id as HEX (as received in the webhook) → API returns 401 Unauthorized or illegal base32 data. Converting account_id to base64url before making a request to TON API → API still returns 401. Sending account_id without the 0: prefix → Error still persists. I expect the API to correctly return the transaction status, but I can't figure out the correct format for account_id. I would appreciate any help or a working example!

Here is my current webhook handler code:

import { checkTransactionStatus } from "../utils/ton.js"; 

export default async function handler(req, res) {
    if (req.method !== "POST") {
    return res.status(405).json({ error: "Method not allowed" });
    }

    try {
    const { tx_hash, account_id } = req.body;

    if (!tx_hash || !account_id) {
      return res.status(400).json({ error: "Invalid request body: missing tx_hash or        account_id" });
     }

    // API key in the Authorization header
    const authHeader = req.headers.authorization || `Bearer ${process.env.TON_API_KEY}`;

    // Check transaction status
    const status = await checkTransactionStatus(tx_hash, account_id, authHeader);

    return res.status(200).json({ status, transaction: tx_hash, account: account_id });
  } catch (error) {
    return res.status(500).json({ error: "Internal server error", details: error.message });
  }
}
发布评论

评论列表(0)

  1. 暂无评论