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
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.
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) Feb 8, 2019 at 15:12
-
@FedericoCaccia This appears to be an issue with addresses that are not checksummed github.com/ethereum/eth-account/issues/211– RonJul 18 at 21:18