Getting Transaction status via Moralis endpoint

Hello, thanks for your help. I’m trying to get the confirmation status for transactions in python and I’m not sure which endpoint to use. I tried the /{address} endpoint while calling “receipt_status” and it doesn’t work. Bscscan api works but it keeps confirming failed transactions as though they were successful. Idk if I’m missing something here…pls advise… code and error below.

txHash = "Insert any txn hash"
chain = "bsc"

checkStatus = '' + txHash + '?chain=' + chain

statusResponse = requests.request("GET", checkStatus, headers=config.moralisAPI)

txStatus = statusResponse.json()['result']['receipt_status']
print(txStatus) ```


C:/Users/Owner/Documents/BlockchainPy/Scripts/python.exe c:/Users/Owner/Documents/BlockchainPy/MyCodes/
Traceback (most recent call last):
File “c:/Users/Owner/Documents/BlockchainPy/MyCodes/”, line 27, in
statusResponse = requests.request(“GET”, checkStatus, headers=config.moralisAPI)
File “C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\requests\”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\requests\”, line 528, in request
prep = self.prepare_request(req)
File “C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\requests\”, line 456, in prepare_request
File “C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\requests\”, line 317, in prepare
File “C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\requests\”, line 449, in prepare_headers
for header in headers.items():
AttributeError: ‘set’ object has no attribute ‘items’

Thanks in advance!

Can you also provide the transaction ids that you tried?

Hello there, I just picked random txn hash to test it out. Here’s one 0xfb4b9200a7f3faf717db5cdb137acc66f94023bb2b8ef5e2b96799b09d7761d2

Here’s a failed txn as well…

you can use speedy nodes for that, for example:

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xf10d04c6ea144fe60347c5bea2cb6aa32db8bc39e6d14ff051a84225af513178"],"id":1}'<your_speedy_node_id_here>/bsc/mainnet/archive


note that you’ll have you use your specific speedy node where I added<your_speedy_node_id_here>/bsc/mainnet/archive

Nice! I just pasted it in my editor (see screenshot). What steps do I need to take to get rid of the undefined variables (noob question here lol)?

I don’t understand your question.
Here is a python example for what you want to do:

import requests

post_data = '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xf10d04c6ea144fe60347c5bea2cb6aa32db8bc39e6d14ff051a84225af513178"],"id":1}'
speedy_node = '<!!!!!!your_id_here>/bsc/mainnet/archive'

headers = {
    "Content-Type": "application/json"
statusResponse = requests.request("POST", speedy_node, headers=headers, data=post_data)

data = statusResponse.json()
print("result=", data['result']['status'])

1 Like

Great! this is exactly what I need. Sorry for the confusion, I’m fairly new to coding and wasn’t sure on how to apply it. Thanks for help sir.

So I applied it as suggested and I’m getting a Keyerror: ‘result’ below. Any ideas what could be wrong?


from web3 import Web3
import requests
import json

wss = 'wss://'
web3 = Web3(Web3.WebsocketProvider(wss))

txHash = "0xf10d04c6ea144fe60347c5bea2cb6aa32db8bc39e6d14ff051a84225af513178"

chain = "bsc"

speedy_node = '' + chain + '/mainnet/archive'

post_data = '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":[txHash],"id":1}'

headers = {
    "Content-Type": "application/json"
statusResponse = requests.request("POST", speedy_node, headers=headers, data=post_data)

data = statusResponse.json()

print("result=", data['result']['status'])


[email protected] MINGW64 ~/Documents/BlockchainPy
$ C:/Users/Owner/Documents/BlockchainPy/Scripts/python.exe c:/Users/Owner/Documents/BlockchainPy/MyCodes/
{'jsonrpc': '2.0', 'id': None, 'error': {'code': -32700, 'message': 'parse error'}}
Traceback (most recent call last):
  File "c:/Users/Owner/Documents/BlockchainPy/MyCodes/", line 27, in <module>
    print("result=", data['result']['status'])
KeyError: 'result'

you need to insert there that txHash value

Yes!!! that worked. Thank you so much! Just one last set of questions pls…

So this script is just a piece of a larger script where multiple transactions will run. Is there a way to get around not having to hardcode the ‘txHash’ like we just did so that it can freely be interchangeable?

Second question: Is there a difference in the router ABIs across chains (bsc, eth and polygon) ? I was wondering if I can just use one of them and reference other chains to it.

Thanks again

for first question:

you could use:
post_data = '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":[%s],"id":1}' % txHash

for second question: I don’t understand what you mean by router ABIs.

I had the same format for the first suggestion earlier. That’s what returned the KeyError: ‘result’ initially. The second suggestion returned same KeyError: ‘result’. Are they working on your end?

Sorry, I was referring to the corresponding ABIs of Uniswap, PancakeSwap and QuickSwap router addresses. These guys…

uniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
pancakeswapRouterAddress = "0x10ED43C718714eb63d5aA57B78B54704E256024E" 
quickswapRouterAddress = "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff"

I was wondering if their corresponding ABIs are similar or the same? That way I can just use one of them and don’t have to reference each one specifically.

In python if you have

a = "5";
b = "34%s6" % a;

then you will get 3456 printed

Related to those ABIs, I don’t know if they are identical, but you can check if they are identical or not, you save each one in a file and then you compare the contents of the files to see if are identical or not.
You can compute the md5 hash of each file to do the comparison for example.

Oh I see, the problem was, I had [%s] instead of ["%s"] . Now it works. Thank you!

Great suggestion, I’ll try that and that should suffice. Thanks again.

1 Like