【发布时间】:2018-09-19 13:01:07
【问题描述】:
我正在使用下面的 web.py 代码尝试通过本地 geth 节点在 Rinkeby 测试网上发送 1 ETH 的交易。我可以看到在实时本地以太坊节点日志流中提交的交易,但它们似乎从未被广播到网络(我永远无法在 rinkeby.io 区块浏览器上看到它们)。我每次都手动设置随机数,但我读到如果使用了以前的随机数并且它没有广播它可能会卡住?作为答案的一部分,如果可以解释 nonce 的目的/用法,那就太好了。
import web3, json, requests
from web3 import Web3, HTTPProvider
provider = HTTPProvider( 'http://localhost:8545' )
web3 = Web3(provider)
web3.eth.enable_unaudited_features()
with open('/Users/.../Library/Ethereum/rinkeby/keystore/UTC...') as keyfile:
encrypted_key = keyfile.read()
private_key = web3.eth.account.decrypt(encrypted_key, 'password')
nonce = web3.eth.getTransactionCount('<public_address_of_sending_account>')
tx = {'value': 1000000000000000000, 'to': '0xBa4DE7E3Fd62995ee0e1929Efaf7a19b73df028f', 'nonce': nonce, 'chainId': 4, 'gasLimit': 6994000, 'gasPrice': 1000000000 }
tx['gas'] = web3.eth.estimateGas(tx)
signed = web3.eth.account.signTransaction(tx, private_key)
web3.eth.sendRawTransaction(signed.rawTransaction)
【问题讨论】:
标签: python ethereum web3 go-ethereum