首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Trezor hardware wallet发送签名事务

从Trezor hardware wallet发送签名事务
EN

Stack Overflow用户
提问于 2020-08-27 11:24:58
回答 1查看 336关注 0票数 1

我一直在尝试编写一个简单的web3.py程序,以便从我的Trezor发送一个事务。我可以在Trezor上对事务进行签名,执行此操作的函数(ethereum.sign_tx())返回事务的V、R和S签名的元组,如下所示:

代码语言:javascript
复制
(42, b"\xa1\xd8blablablax883", b'<\x7f\xd0Eblablabla6\xe7\xe2Fc')

我的问题是,如何将这些签名转换为可以使用Web3.eth.sendRawTransaction()函数发送的序列化形式。完整的代码是:

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-27 20:54:09

您可以像trezorctl一样使用rlp.encode

代码语言:javascript
复制
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))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63608705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档