dxy
December 1, 2021, 12:31am
1
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).
opened 05:48PM - 18 Oct 21 UTC
closed 10:12AM - 30 Nov 21 UTC
# Lib version:
`668d7ef756e4fefe4621f435bb9a3e37cbeb82d9`
# The problem:
I am… trying to issue a simple fund-transferring transaction. The code, according to the project's `README` should look like this:
```python
import pyhmy.transaction as t
import pyhmy.signing as s
bobPub = "one1mfzkvvtsjzagnkxc3ad4lndnfk92hpla70nf24"
# Bob is a testing acc with only testnet ONEs
bobPriv = "c07bfdf4819946009c06bfee12f9ef2d37c1a216600961460121f1c085d16316"
magniffPub = "one10glu5d2sxyn5gcg0e6yd7v7ty4vptjs3pr0spc"
testNetAddress = "https://api.s0.b.hmny.io"
tx = {
'chainId': 2,
'from': bobPub,
'gas': 6721900,
'gasPrice': 1000000000,
'nonce': 10101,
'shardID': 0,
'to': magniffPub,
'toShardID': 0,
'value': 10 ** 15,
}
print(t.send_raw_transaction(
s.sign_transaction(tx, bobPriv).rawTransaction.hex(), testNetAddress
))
```
It actually gives me back the transaction id, yet it could not be found on explorer, nor funds are transferred.
get_account_nonce
1 Like
Maffaz
December 1, 2021, 9:59am
3
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.
dxy
December 1, 2021, 2:25pm
5
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
dxy
December 1, 2021, 2:28pm
6
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…
dxy
December 1, 2021, 3:00pm
7
Alright, the pending transactions are now going through… i guess that was a network congestion problem. Thanks everyone!
Maffaz
December 1, 2021, 3:00pm
8
No it just keeps checking getTransaction
until it finds it… A bit Crude but there you go lol
1 Like
dxy
December 1, 2021, 3:01pm
9
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
Maffaz
December 1, 2021, 3:01pm
10
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