Try this… It uses the pending filter to find the hash. . It is the ETH_HASH we needed to check…
This script will create a TX and then find it in the Pending TX’s list.
from web3 import Web3, exceptions
from requests import post
main_net = 'https://rpc.s0.t.hmny.io'
wss_url = 'wss://ws.s0.t.hmny.io'
# w3 = Web3(Web3.HTTPProvider(main_net))
w3 = Web3(Web3.WebsocketProvider(wss_url))
p_key = ''
address = w3.eth.account.privateKeyToAccount(p_key).address
print(address)
send_to_address = ''
chain_id = 1666600000
gas_price = 1000000000
gas = 25000
min_gas = 0.000025
def call_rpc_single_page(
method: str,
rpc_endpoint: str,
params: list = [],
_id: int = 1,
) -> None:
headers = {
'Content-Type': 'application/json'
}
d = {"jsonrpc": "2.0", "method": method, "params": params, "id": str(_id)}
data = post(rpc_endpoint, json=d, headers=headers).json()
return data
def create_filter() -> str:
create_filter = call_rpc_single_page(
"eth_newPendingTransactionFilter",
main_net,
[],
_id = 73,
)
print(create_filter)
if create_filter.get('result'):
pending_filter = create_filter['result']
return pending_filter
def send_tx(address: str) -> str:
nonce = w3.eth.getTransactionCount(address)
tx = {
'chainId': chain_id,
'nonce': nonce,
'value': 1,
'gas': gas,
'gasPrice': gas_price,
'data': '',
'to': Web3.toChecksumAddress(send_to_address),
}
signed_tx = w3.eth.account.signTransaction(tx, p_key)
t_hash = str(w3.eth.sendRawTransaction(signed_tx.rawTransaction).hex())
return t_hash
def find_pending_tx(t_hash: str) -> dict:
retry = []
while True:
data = call_rpc_single_page(
"eth_getFilterChanges",
main_net,
[pending_filter],
)
# print(data)
if data.get('result'):
# print(data['result'])
data = data['result']
data += retry
retry = []
for x in data:
# print(x)
try:
hash_info = w3.eth.getTransaction(x)
tx_data = dict(hash_info)
eth_hash = tx_data['hash'].hex()
if t_hash == eth_hash:
print(f'Found TX :: {t_hash}')
return tx_data
except exceptions.TransactionNotFound:
retry += [x]
pending_filter = create_filter()
t_hash = send_tx(address)
found = find_pending_tx(t_hash)
for k, v in found.items():
try:
print(f'{k} : {v.hex()}')
except AttributeError:
print(f'{k} : {v}')
IT will print the following and as you can see thet blockHash
, blockNumber
and transactionIndex
are returning None
blockHash : None
blockNumber : None
from : 0xF88b361E05a504D9ef34FFeE0E6A5137eba219ca
gas : 25000
gasPrice : 1000000000
hash : 0x6092b0291ef99ba28d7a039f2e0ef48dbf2244c656c510057a870ea2e8d70f02
input : 0x
nonce : 3405
r : 0x11c3bf4a05d04d49ebd8c4a804aedb15301395f72faba631c3d4e096fcaadddc
s : 0x205dcb70567bea76c4f89b95719e6293e0aa8aa43aa5b8bc8832741ea206d431
timestamp : 0x0
to : 0xfAFfb33B924C33381dee35D445013D3200249572
transactionIndex : None
v : 3333200036
value : 1
Waiting a little longer and we can query the Hash as normal
t = '0x6092b0291ef99ba28d7a039f2e0ef48dbf2244c656c510057a870ea2e8d70f02'
hash_info = w3.eth.getTransaction(t)
found = dict(hash_info)
for k, v in found.items():
try:
print(f'{k} : {v.hex()}')
except AttributeError:
print(f'{k} : {v}')
And we see the None
fields are completed with Data now that the Transaction has gone through.
blockHash : 0x2f39ecc7bea2ae39172e24a10f55dcf64c3d700fcc380aaf7c8539c7a9e9d360
blockNumber : 19988163
from : 0xF88b361E05a504D9ef34FFeE0E6A5137eba219ca
gas : 25000
gasPrice : 1000000000
hash : 0x6092b0291ef99ba28d7a039f2e0ef48dbf2244c656c510057a870ea2e8d70f02
input : 0x
nonce : 3405
r : 0x11c3bf4a05d04d49ebd8c4a804aedb15301395f72faba631c3d4e096fcaadddc
s : 0x205dcb70567bea76c4f89b95719e6293e0aa8aa43aa5b8bc8832741ea206d431
timestamp : 0x61a8844d
to : 0xfAFfb33B924C33381dee35D445013D3200249572
transactionIndex : 76
v : 3333200036
value : 1
I hope this helps…