4

我正在使用 tron web 查询地址的交易,但它不会返回发送到该地址的交易,其中令牌传输是 TRC20。

这不起作用。我想获取地址上的交易并获得 TRX、trc10 和 trc20 交易。

我做错了什么或怎么做?

这是我的代码块:

  tronWeb.setDefaultBlock("latest");
  var result = await tronGrid.account.getTransactions(address, {
    only_confirmed: true,
    only_to: true,
    limit: 10
  });
  console.log(JSON.stringify(result));
})();
4

2 回答 2

8

经过大量研究,我发现可以轻松地每隔一段时间查询合约事件以获取该合约地址上的交易,然后您可以将其过滤为您正在观看的地址,因为您无法通过您的 trongrid/tronweb 实现获得 webhook 或 websocket。

这是我用来实现此目的的示例文件,即使使用不同的合约地址,它也可以很好地监控许多地址。

注意:在我自己的实现中,这个节点文件是从另一个文件中调用的,其他物流在另一个文件中处理,但是下面你看我是如何查询指定合约发出的传输事件的

const TronWeb = require("tronweb");
const TronGrid = require("trongrid");

const tronWeb = new TronWeb({
  fullHost: "https://api.trongrid.io"
});
const tronGrid = new TronGrid(tronWeb);
const argv = require("minimist")(process.argv.slice(2));
var contractAddress = argv.address;
var min_timestamp = Number(argv.last_timestamp) + 1; //this is stored for the last time i ran the query
(async function() {
  tronWeb.setDefaultBlock("latest");
  tronWeb.setAddress("ANY TRON ADDRESS"); // maybe being the one making the query not necessarily the addresses for which you need the transactions

  var result = await tronGrid.contract.getEvents(contractAddress, {
    only_confirmed: true,
    event_name: "Transfer",
    limit: 100,
    min_timestamp: min_timestamp,
    order_by: "timestamp,asc"
  });
  result.data = result.data.map(tx => {
    tx.result.to_address = tronWeb.address.fromHex(tx.result.to); // this makes it easy for me to check the address at the other end
    return tx;
  });
  console.log(JSON.stringify(result));
})();

您可以自由自定义传递给该tronGrid.contract.getEvents方法的配置数据。根据您正在监控的合约上交易的频率,您应该 DYOR 知道什么时间间隔对您有利,以及您应该通过什么限制值。

有关详细信息,请参阅https://developers.tron.network/docs/trongridjs

我希望这可以帮助别人

于 2019-12-18T13:21:06.003 回答
0

I found a API that can take TRC20 transactions, but I haven't found an implementation in webtron.

https://api.shasta.trongrid.io/v1/accounts/address/transactions

Related document: https://developers.tron.network/reference#transaction-information-by-account-address

于 2021-09-05T18:51:45.943 回答