[英]Connection reset by peer when sending from hardware (GPRS module) but fine when send from PC
[英]Send signed transaction from Trezor hardware wallet
我一直在嘗試編寫一個簡單的 web3.py 程序來從我的 Trezor 發送交易。 我能夠在我的 Trezor 上簽署交易,並且執行該操作的函數 (ethereum.sign_tx()) 返回交易的 V、R 和 S 簽名的元組,如下所示:
(42, b"\xa1\xd8blablablax883", b'<\x7f\xd0Eblablabla6\xe7\xe2Fc')
我的問題是如何將這些簽名轉換為可以使用 Web3.eth.sendRawTransaction() 函數發送的序列化形式。 完整代碼為:
from trezorlib.client import get_default_client
from trezorlib.tools import parse_path
from trezorlib import ethereum
from web3 import Web3
def main():
# Use first connected device
client = get_default_client()
ropsten = Web3(Web3.HTTPProvider("https://ropsten.infura.io/v3/7xxxxxxxxx23dee70e4aa"))
# Get the first address of first BIP44 account
# (should be the same address as shown in wallet.trezor.io)
bip32_path = parse_path("44'/60'/0'/0/0")
address = ethereum.get_address(client, bip32_path)
nonce = ropsten.eth.getTransactionCount(address)
tx = ethereum.sign_tx(client, bip32_path, nonce, Web3.toWei(1, 'gwei'), 21000, "0x7ccc4a67eB76b5B1C8Efc62672A6884A9B7bFDb7", Web3.toWei(1, 'ether'), chain_id=3)
#sent = ropsten.eth.sendRawTransaction(tx)
if __name__ == "__main__":
main()
你可以做trezorctl
做的事情並使用rlp.encode
:
import rlp
gas_price = Web3.toWei(1, 'gwei')
gas_limit = 21000
to_addr = "0x7ccc4a67eB76b5B1C8Efc62672A6884A9B7bFDb7"
amount = Web3.toWei(1, 'ether')
data = b""
rlp_prefix = (nonce, gas_price, gas_limit, to_addr, amount, data)
sent = ropsten.eth.sendRawTransaction(rlp.encode(rlp_prefix + tx))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.