Question about signing module within pyhmy

Hi! Noob here, wasn’t sure where the signing module went on pyhmy.

Trying to sign and send transactions over the harmony blockchain through python, pyhmy seemed like the easiest way to do this although the signing module seems to be missing.

I’m sure there is a different way to send transactions over pyhmy now, just not sure where to find that information.

Any help would be great, thanks :slight_smile:

After we merge this PR: Resolve Bounty 7 (improve Harmony Python SDK) by MaxMustermann2 · Pull Request #20 · harmony-one/pyhmy · GitHub signing should be available in pyhmy. meanwhile, you could use as we are fully ethereum tooling compatible.

1 Like

I can add that you would essentially follow this: web3.eth API — 5.19.0 documentation

With one caviat that you need to add two new fields shardID and toShardID to the tx dict.

Also you initiate class with:

from web3 import Web3
my_provider = Web3.HTTPProvider('')

# Then you are ready to initialize your Web3 instance, like so:

w3 = Web3(my_provider)

I didn’t have time to test this yet so let me know how it goes :slight_smile:


you don’t need to explicitly add the shardID and toShardID. Those are not needed while using the web3 libraries. Based on the endpoint you are using the shardIDs are automatically recognized. If you want to send cross-shard, then this won’t work and you must use pyhmy.

from web3 import Web3
w3 = Web3.HTTPProvider('')
tx = {
    'chainId': w3.eth.chainId,
    'nonce': w3.eth.getTransactionCount(sender_address),
    'to': receiver_address,
    'value': w3.toWei(2, "ether"),
    'gas': 21000,
    'gasPrice': w3.toWei('1', 'gwei')
send(address, tx, p_key)

def send(address, tx, p_key):
  signed_tx = w3.eth.account.signTransaction(tx, p_key)
  t_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)

Thanks @ganesha for clarifying that. As I said this was not tested yet and I was following API docs which say:

Transaction uses RLP, but adds two fields, one is shardID and the other is toShardID.

Maybe it would be worth to clarify in docs that these would be pre-populated automatically based on RPC endpoint ?

1 Like

thanks @adamwojt. can you point me to the doc that says above? will fix.

1 Like

@ganesha API - Harmony