How can I check whether a transaction hash is valid or not using Python [web3.py
]?
The answers I found was in javascript, related:
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityHow can I check whether a transaction hash is valid or not using Python [web3.py
]?
The answers I found was in javascript, related:
With the help of regex
at https://ethereum.stackexchange.com/a/34286/4575:
/^0x([A-Fa-f0-9]{64})$/
import re
def is_transaction_valid(tx_hash) -> bool:
pattern = re.compile(r"^0x[a-fA-F0-9]{64}")
return bool(re.fullmatch(pattern, tx_hash))
tx_hash = "0xd65dc6bf6dcc111237f9acfbfa6003ea4a4d88f2e071f4307d3af81ae877f7be"
if is_transaction_valid(tx_hash):
print(f"{tx_hash} is an valid transaction.")
else:
print(f"{tx_hash} is NOT a valid transaction.")