2024-11-06 13:43:56 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
trc20token_info = {
|
|
|
|
"usdt": {"tokenId": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
|
|
"tokenAbbr": "USDT",
|
|
|
|
"tokenName": "Tether USD",
|
|
|
|
"tokenLogo": "https://static.tronscan.org/production/logo/usdtlogo.png",
|
|
|
|
"issuerAddr": "THPvaUhoh2Qn2y9THCZML3H815hhFhn5YC",
|
|
|
|
"vip": True}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Tronscan:
|
|
|
|
def __init__(self, api_key):
|
|
|
|
self.api_key = api_key
|
|
|
|
|
|
|
|
def accountv2(self, address):
|
|
|
|
"""
|
|
|
|
|
|
|
|
:param address:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
response = requests.get(f"https://apilist.tronscanapi.com/api/accountv2?address={address}",
|
|
|
|
headers={'TRON-PRO-API-KEY': self.api_key})
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
def approve_change(self, contract_address, from_address, to_address, start=0, limit=20, show=3):
|
|
|
|
"""
|
|
|
|
Returns account authorization change records.
|
|
|
|
:param contract_address: Contract address
|
|
|
|
:param from_address: Originator address
|
|
|
|
:param to_address: Recipient address
|
|
|
|
:param start: Start number. Default: 0
|
|
|
|
:param limit: Number of items per page. Default: 20
|
|
|
|
:param show: Token type. 1: TRC20 2: TRC721 3: ALL(default) 4: TRC1155
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
params = {
|
|
|
|
"contract_address": contract_address,
|
|
|
|
"from_address": from_address,
|
|
|
|
"to_address": to_address,
|
|
|
|
"start": start,
|
|
|
|
"limit": limit,
|
|
|
|
"show": show,
|
|
|
|
"type": "approve",
|
|
|
|
}
|
|
|
|
headers = {'TRON-PRO-API-KEY': self.api_key}
|
|
|
|
response = requests.get("https://apilist.tronscanapi.com/api/account/approve/change",
|
|
|
|
headers=headers, params=params)
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
def transfer_trx(self, address, start_timestamp=None, end_timestamp=None, start=0, limit=20, direction=1,
|
|
|
|
db_version=0,
|
|
|
|
reverse=True, fee=False):
|
|
|
|
"""
|
|
|
|
Returns the list of TRX transfers for a specific address.
|
|
|
|
Note : The value sum of start and limit must be less than or equal to 10000.
|
|
|
|
:param address: Query address
|
|
|
|
:param start_timestamp: Start timestamp
|
|
|
|
:param end_timestamp: End timestamp
|
|
|
|
:param start: Start number. Default: 0
|
|
|
|
:param limit: Number of items per page. Default: 20
|
|
|
|
:param direction: Default: 1. 1 represents inbound transfers, 2 represents outbound transfers, and 0 represents both.
|
|
|
|
:param db_version: Default: 0, which indicates to filter transfers with invalid “to” or “from” addresses out.
|
|
|
|
:param reverse: Sort the data in a descending order. Default: true
|
|
|
|
:param fee: Whether to return data of TRX burning for resource consumption. Default: false
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
params = {
|
|
|
|
"address": address,
|
|
|
|
"start_timestamp": start_timestamp,
|
|
|
|
"end_timestamp": end_timestamp,
|
|
|
|
"start": start,
|
|
|
|
"limit": limit,
|
|
|
|
"direction": direction,
|
|
|
|
"db_version": db_version,
|
|
|
|
"reverse": reverse,
|
|
|
|
"fee": fee,
|
|
|
|
}
|
|
|
|
headers = {'TRON-PRO-API-KEY': self.api_key}
|
|
|
|
response = requests.get("https://apilist.tronscanapi.com/api/transfer/trx",
|
|
|
|
headers=headers, params=params)
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
def transfer_token10(self, address, trc10Id, start_timestamp=None, end_timestamp=None, start=0, limit=20,
|
|
|
|
direction=1, db_version=0, reverse=True):
|
|
|
|
"""
|
|
|
|
Returns the transfer list of a TRC10 token for a specific account.
|
|
|
|
Note : The value sum of start and limit must be less than or equal to 10000.
|
|
|
|
:param address: Query address
|
|
|
|
:param trc10Id: TRC10 token ID
|
|
|
|
:param start_timestamp: Start timestamp
|
|
|
|
:param end_timestamp: End timestamp
|
|
|
|
:param start: Start number. Default: 0
|
|
|
|
:param limit: Number of items per page. Default: 20
|
|
|
|
:param direction: Default: 1. 1 represents inbound transfers, 2 represents outbound transfers, and 0 represents both.
|
|
|
|
:param db_version: Default: 0, which indicates to filter transfers with invalid “to” or “from” addresses out.
|
|
|
|
:param reverse: Sort the data in a descending order. Default: true
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
params = {
|
|
|
|
"address": address,
|
|
|
|
"trc10Id": trc10Id,
|
|
|
|
"start_timestamp": start_timestamp,
|
|
|
|
"end_timestamp": end_timestamp,
|
|
|
|
"start": start,
|
|
|
|
"limit": limit,
|
|
|
|
"direction": direction,
|
|
|
|
"db_version": db_version,
|
|
|
|
"reverse": reverse,
|
|
|
|
}
|
|
|
|
headers = {'TRON-PRO-API-KEY': self.api_key}
|
|
|
|
response = requests.get("https://apilist.tronscanapi.com/api/transfer/token10",
|
|
|
|
headers=headers, params=params)
|
|
|
|
return response.json()
|
|
|
|
|
|
|
|
def transfer_trc20(self, address, trc20Id, start_timestamp=None, end_timestamp=None, start=0, limit=20,
|
|
|
|
direction=1, db_version=0, reverse=True):
|
|
|
|
"""
|
|
|
|
Returns the transfer list of a TRC20 token for a specific account.
|
|
|
|
Note : The value sum of start and limit must be less than or equal to 10000.
|
|
|
|
:param address: Query address
|
|
|
|
:param trc20Id: TRC20 token ID
|
|
|
|
:param start_timestamp: Start timestamp
|
|
|
|
:param end_timestamp: End timestamp
|
|
|
|
:param start: Start number. Default: 0
|
|
|
|
:param limit: Number of items per page. Default: 20
|
|
|
|
:param direction: Default: 1. 1 represents inbound transfers, 2 represents outbound transfers, and 0 represents both.
|
|
|
|
:param db_version: Default: 0, which indicates to filter transfers with invalid “to” or “from” addresses out.
|
|
|
|
:param reverse: Sort the data in a descending order. Default: true
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
params = {
|
|
|
|
"address": address,
|
|
|
|
"trc20Id": trc20Id,
|
|
|
|
"start_timestamp": start_timestamp,
|
|
|
|
"end_timestamp": end_timestamp,
|
|
|
|
"start": start,
|
|
|
|
"limit": limit,
|
|
|
|
"direction": direction,
|
|
|
|
"db_version": db_version,
|
|
|
|
"reverse": reverse,
|
|
|
|
}
|
|
|
|
headers = {'TRON-PRO-API-KEY': self.api_key}
|
|
|
|
response = requests.get("https://apilist.tronscanapi.com/api/transfer/trc20",
|
|
|
|
headers=headers, params=params)
|
|
|
|
return response.json()
|