3

I know there is a wallet called MyEtherWallet can sign with private key offline, and there seems to be javascript library that can also do this, but is there a python library or any code that can sign the raw transaction provided that I have private key string?

2 Answers 2

2

There are a few options. Account.signTransaction in web3.py is one such option: https://github.com/ethereum/web3.py/blob/master/docs/web3.eth.account.rst.

1
  • that's great help
    – xuanzhui
    Jan 22, 2018 at 14:16
5

is there a python library or any code that can sign the raw transaction provided that I have private key string?

There is module called Account in Web3.py. This module has signTransaction method, which can be used like that:

transaction = {
        'to': '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
        'value': 1000000000,
        'gas': 2000000,
        'gasPrice': 234567897654321,
        'nonce': 0,
        'chainId': 1
    }
key = '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
signed = w3.eth.account.signTransaction(transaction, key)

w3.eth.sendRawTransaction(signed.rawTransaction)
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.