2

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?

1

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.

  • that's great help – xuanzhui Jan 22 '18 at 14:16
3

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)
  • using this, I get this error: raise TypeError("Transaction had invalid fields: %r" % invalid) – Federico Caccia Feb 8 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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