sendRawTransaction is not sending any transaction

Until now i used sendRawTransaction to send transaction to the Harmony chain using Python without any issues. The problem is that all of a sudden my transactions won’t appear on the explorer even though sendRawTransaction gave me a transaction hash back. Another big problem is that there is no way for me if these transactions are still pending.

I’m using web3py and the public harmony node.

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://rpc.s0.t.hmny.io'))

gas_amount = 590000
nonce = w3.eth.getTransactionCount('my-address')

tx = {	
		'chainId': 1666600000,
		'nonce': nonce,
		'value': 0,
		'gas': gas_amount,
		'gasPrice': w3.toWei('10050', 'gwei'),
		'data': '',
		'to': Web3.toChecksumAddress('some-address'),
	}

signed_tx = w3.eth.account.signTransaction(tx, p_key)

t_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)

This code works, it doesn’t give any problem, in fact i will get back a transaction hash that i cannot find on the explorer, for example: 0xbd932e5384897a11152aec58231c7b669fff81509074f2770f997e545dd876df. Please, the harmony api is giving me a really hard time on this one, any kind of help is appreciated

There was this issue and @Maffaz pointed out you need to get the ounce programatically (what you did, but he used a different function).

get_account_nonce

1 Like

The issue above is using PyHmy Repo to Tx…

There is issue with the explorer updating I guess, not your code.

This Tx I did just now also does not show on the explorer but I get info back from the RPC…

Use getTransaction to check programmatically

I put in a while loop that will check until found as there must be some congestion.

from web3 import Web3

# main_net = 'https://rpc.s0.t.hmny.io'
# w3 = Web3(Web3.HTTPProvider(main_net))

wss_url = 'wss://ws.s0.t.hmny.io'
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

nonce = w3.eth.getTransactionCount(address)

tx = {	
		'chainId': chain_id,
		'nonce': nonce,
		'value': 0,
		'gas': gas,
		'gasPrice': gas_price,
		'data': '',
		'to': Web3.toChecksumAddress(send_to_address),
	}

signed_tx = w3.eth.account.signTransaction(tx, p_key)

t_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
print(t_hash.hex())

# Uncomment to check a single hash
# t_hash = '0x4b30b099149d6ac33b7a86ccbcdf08fe69dbf7a26bb64c145c5d1287db6fb941'
while 1:
    try:
        hash_info = w3.eth.getTransaction(t_hash)
        print(hash_info)
        break
    except exceptions.TransactionNotFound:
        pass
1 Like

In my case, all transactions were pending and I could check them with the ‘getPendingTransactions’ call. But they were never processed.

Thanks a lot! The big problem about using getTransaction is that for now it doesn’t work with pending transactions (but it will in the future, there is an issue on github about that), so it doesn’t solve my problem because even transactions that i tried to send 24 hours ago can’t be found. It looks like they are just stuck there, i have no idea why

How did you check them? Did you loop through pending transactions and search for the address you used? Because i tried that but that didn’t find my transactions either, even though i have the tx hash…

Alright, the pending transactions are now going through… i guess that was a network congestion problem. Thanks everyone!

No it just keeps checking getTransaction until it finds it… A bit Crude but there you go lol

1 Like

This is the same thing i’m doing. Fortunately, it looks like getTransaction will be able to find pending transaction soon Regression on GetTransactionByHash · Issue #3893 · harmony-one/harmony · GitHub

You can do the same with getTransactionReceipt

while 1:
    try:
        # hash_info = w3.eth.getTransaction(t_hash)
        # print(hash_info)
        sent = w3.eth.getTransactionReceipt(t_hash)
        print(sent)
        break
    except exceptions.TransactionNotFound:
        pass
1 Like