# Question about signing module within pyhmy

**URL:** <https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388>\
**Category:** Developers\
**Created:** [May 18, 2021, 1:37am UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388 "2021-05-18T01:37:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tabasco\_ow](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/tabasco_ow/32/12757_2.png) [@tabasco\_ow](https://talk.harmony.one/u/tabasco_ow)\
**Post date:** [May 18, 2021, 1:37am UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/1 "2021-05-18T01:37:20Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![ganesha](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/ganesha/32/549_2.png) [@ganesha](https://talk.harmony.one/u/ganesha)\
**Post date:** [June 1, 2021, 5:19am UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/2 "2021-06-01T05:19:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adamwojt](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/adamwojt/32/769_2.png) [@adamwojt](https://talk.harmony.one/u/adamwojt)\
**Post date:** [June 3, 2021, 10:40pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/3 "2021-06-03T22:40:14Z")

</div>

I can add that you would essentially follow this: [web3.eth API — Web3.py 5.19.0 documentation](https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.send_raw_transaction)

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

Also you initiate class with:

```python
from web3 import Web3
my_provider = Web3.HTTPProvider('https://api.s0.t.hmny.io')

# 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 🙂

---

<div class="post-metadata">

**Author:** ![ganesha](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/ganesha/32/549_2.png) [@ganesha](https://talk.harmony.one/u/ganesha)\
**Post date:** [June 4, 2021, 6:49am UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/4 "2021-06-04T06:49:07Z")

</div>

> [@adamwojt](#):
>
> ```auto
> from web3 import Web3
> my_provider = Web3.HTTPProvider('https://api.s0.t.hmny.io')
> 
> ```

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.

```auto
from web3 import Web3
w3 = Web3.HTTPProvider('https://api.s0.b.hmny.io')
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)
  print(w3.eth.get_transaction(t_hash))

```

---

<div class="post-metadata">

**Author:** ![adamwojt](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/adamwojt/32/769_2.png) [@adamwojt](https://talk.harmony.one/u/adamwojt)\
**Post date:** [June 4, 2021, 8:30am UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/5 "2021-06-04T08:30:07Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![ganesha](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/ganesha/32/549_2.png) [@ganesha](https://talk.harmony.one/u/ganesha)\
**Post date:** [June 4, 2021, 8:11pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/6 "2021-06-04T20:11:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adamwojt](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/adamwojt/32/769_2.png) [@adamwojt](https://talk.harmony.one/u/adamwojt)\
**Post date:** [June 4, 2021, 11:56pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/7 "2021-06-04T23:56:04Z")

</div>

@ganesha [API - Harmony](https://docs.harmony.one/home/developers/api#key-differences-between-harmony-and-ethereum)

---

<div class="post-metadata">

**Author:** ![theo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@theo](https://talk.harmony.one/u/theo)\
**Post date:** [July 1, 2021, 9:47pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/8 "2021-07-01T21:47:07Z")

</div>

Hey, I am new to harmony but using your code I get the following error:

ValueError: {‘code’: -32000, ‘message’: ‘shard do not match, txShard: 2628267298, nodeShard: 0’}

When I try to include an additional field (shardID) in the transaction, I get:

TypeError: Transaction must not include unrecognized fields: {‘shardID’}

Any ideas what’s going wrong? Thanks

---

<div class="post-metadata">

**Author:** ![theo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@theo](https://talk.harmony.one/u/theo)\
**Post date:** [July 1, 2021, 9:58pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/9 "2021-07-01T21:58:05Z")

</div>

Well this is weird…  
I was using:

‘chainId’: 0

and changed it to:

‘chainId’: w3.eth.chainId

and now everything seems to be working…

---

<div class="post-metadata">

**Author:** ![ganesha](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/ganesha/32/549_2.png) [@ganesha](https://talk.harmony.one/u/ganesha)\
**Post date:** [July 1, 2021, 11:52pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/10 "2021-07-01T23:52:10Z")

</div>

when using web3.py you cannot use the harmony default chain ids like 0 for mainnet and 1 for testnet. Those only work for harmony specific libraries. For all ethereum libraries, best to query the chainId like w3.eth.chainId which fetches the ethereum compatible chain ids like 1666600000 for mainnet and 1666700000 for testnet.

---

<div class="post-metadata">

**Author:** ![theo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@theo](https://talk.harmony.one/u/theo)\
**Post date:** [July 2, 2021, 3:08pm UTC](https://talk.harmony.one/t/question-about-signing-module-within-pyhmy/1388/11 "2021-07-02T15:08:52Z")

</div>

That makes sense, thanks for the clarification
