如果特定地址上有新交易,我想扫描 tron 网络的最新区 block https://trx.tokenview.com/en/blocklist
。
我设法获得了最新的区 block 和地址的余额,但我不知道如何扫描最新的区 block 并寻找该地址的任何新交易。任何想法都会非常有帮助。
from tronpy import Tron
client = Tron()
#-- Get the latest block
latestBlock = client.get_latest_block_number()
print (latestBlock)
#-- Get the balance
accountBalance = client.get_account_balance('TTzPiwbBedv7E8p4FkyPyeqq4RVoqRL3TW')
print (accountBalance)
#-- if the address has new transaction in the latest block at the time of the scan:
#-- display all the data (receiver, sender and amount, etc)
最佳答案
所以我尝试并为我工作的一件事如下: 我达到了两个终点: trc20url = f"https://api.trongrid.io/v1/accounts/{address}/transactions/trc20?&contract_address={contract_add}&min_timestamp={getminTime}&max_timestamp={maxTime}" trxurl = f"https://api.trongrid.io/v1/accounts/{地址}/transactions"
对于 trc20 端点,请检查:https://stackoverflow.com/a/72162936/17474386
现在对于 trx 或 trc10 也有: 我所做的我调用的获取请求如下:
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
trxresponse = requests.get(trxurl, headers = headers)
trxdicResponse = trxresponse.json()
然后我遍历结果:
for tx in trxdicResponse['data']:
if (tx["raw_data"]["contract"][0]['type']) ==
'TransferContract':
# this means this is a trx tx , (transferAssetContract for trc10, and triggersmartcontract for trc20)
从那里你可以建立一个交易列表并做任何你想做的事情,如果你想让这个过程自动化,你可以做以下事情:
trxblock = client.get_block()
lastBlockNum = trxblock['block_header']['raw_data']['number']
maxTime = trxblock['block_header']['raw_data']['timestamp']
getuserBlock = get from DB
getfirstBlock = getuserBlock.trxLastBlock
getminTime = client.get_block(getfirstBlock)['block_header']['raw_data']['timestamp']
所以你要做的是获取最新的 block 并获取其时间戳,然后获取你从数据库循环过来的最后一个 block 并获取其时间戳,然后你只需将它们提供给请求参数,然后更新最后扫描的 block 在您的数据库中然后重复。
关于python - 如何扫描最新的 TRX 区 block 以获取转账事件以检查地址是否有新交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72655194/