Skip to content

Commit

Permalink
[EASY] Web3 API update: Get block number from tx hash (#78)
Browse files Browse the repository at this point in the history
This PR adds a very simple function in the web3, where one can provide a
tx hash and gets back the block number where the tx took place.

(Context: I would like to fetch the block number so that I can then
search for MEV Blocker kickbacks within that block)
  • Loading branch information
harisang authored Oct 23, 2023
1 parent 432e18d commit f704c39
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/apis/web3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def get_transaction(self, tx_hash: str) -> Optional[TxData]:

return transaction

def get_tx_block_number(self, tx_hash: str) -> Optional[int]:
"""
Takes tx hash as input, returns block number where tx took place.
"""
transaction = self.get_transaction(tx_hash)
if transaction is None:
return None
return transaction["blockNumber"]

def get_receipt(self, tx_hash: str) -> Optional[TxReceipt]:
"""
Get the receipt of a transaction from the transaction hash.
Expand Down

0 comments on commit f704c39

Please sign in to comment.