[*]
Ich erhalte die Liste der kürzlich erstellten Verträge mit BNB
Code: Select all
eth_getBlockByNumber
2.2. Überprüfen Sie, ob Transaktionen ['to'] das Feld keine ist, unter Berücksichtigung von Transaktionen ['blockhash'] als Token -Adresse. /> < /ol>
< /li>
< /ul>
Hier ist mein Code: < /p>
import requests
if __name__ == '__main__':
get_latest_tokens_on_BNB()
def get_latest_tokens_on_BNB ():
API_KEY = "my_api_key"
latest_block_url = f'https://api.etherscan.io/v2/api?chainid ... y={API_KEY}'
response = requests.get(latest_block_url)
latest_block_data = response.json()
transactions = latest_block_data['result']['transactions']
for tx in transactions:
# step 2: approach 1
transaction_receipt_url = f'https://api.etherscan.io/v2/api?chainid ... t&hash={tx["blockHash"]}&apikey={API_KEY}'
transaction_response = requests.get(transaction_receipt_url)
transaction_data = transaction_response.json()
contractAddress = transaction_data['result']['contractAddress']
if contractAddress != None : # Contract creation
token_id = get_token_id(contractAddress)
if token_id:
token_data = get_token_data(token_id)
print(token_data)
else:
print("Token not found.")
# # step 2: approach 2 (approach 1 and appproach 2 can't be activated in the same time!)
# if tx['to'] is None: # Contract creation (Does this really show contract creation?)
# contractAddress = tx['blockHash'] # Replace with your token address (I don't know why in the provided example blockHash was given as contract address!)
# token_id = get_token_id(contractAddress)
# # step 3: Use coingecko API to get more details about obtained address
# if token_id:
# token_data = get_token_data(token_id)
# print(token_data)
# else:
# print("Token not found.")
# else:
# print('tx[to] is not None!')
def get_token_id(token_address):
url = 'https://api.coingecko.com/api/v3/coins/markets'
params = {
'vs_currency': 'usd',
'order': 'market_cap_desc',
'per_page': 100,
'page': 1,
'sparkline': 'false'
}
response = requests.get(url, params=params)
tokens = response.json()
# Search for the token by address in returned tokens
for token in tokens:
if token['id'] == token_address:
return token['id']
return None
def get_token_data(token_id):
url = f'https://api.coingecko.com/api/v3/coins/{token_id}'
response = requests.get(url)
return response.json()
< /code>
Wenn ich im zweiten Schritt den ersten Ansatz (Standardversion des Code) verwende, erhalte ich: < /p>
{'jsonrpc': '2.0', 'id': 1, 'error': {'code': -32602, 'message': 'invalid argument 0: hex string has length 0, want 64 for common.Hash'}}
Traceback (most recent call last):
... in get_latest_tokens_on_BNB
contractAddress = transaction_data['result']['contractAddress']
KeyError: 'result'
< /code>
Und wenn ich im zweiten Schritt den zweiten Ansatz verwende, erhalte ich: < /p>
tx[to] is not None!
< /code>
Meine erste Frage ist also, dass dies eine gute Idee ist, die neuesten Token mit Mittagessen zu erhalten, oder es gibt bessere Wege? Vielen Dank im Voraus.