[英]web3.py - sending signed transaction issue (transaction type not supported)
我正在尝试在 Binance Smart Chain 中将交易从一个帐户发送到另一个帐户,但出现错误ValueError: {'code': -32000, 'message': 'transaction type not supported'}
这是我的代码
from web3 import Web3
REF_ADDRESS = '0x5...'
MY_ADDRESS = '0xe...'
MY_PKEY = 'd...'
MAX_GAS_ETHER = 0.0005
web3 = Web3(Web3.HTTPProvider('https://bsc-dataseed.binance.org/'))
balance = web3.eth.get_balance(MY_ADDRESS)
gas_price = float(web3.fromWei(web3.eth.gas_price, 'ether'))
allowed_gas = int(MAX_GAS_ETHER/gas_price)
print(web3.fromWei(balance, 'ether'))
tx = {
'from': MY_ADDRESS,
'to': REF_ADDRESS,
'value': web3.toWei(0.0001, 'ether'),
'gas': allowed_gas,
'type': 2,
'chainId': web3.eth.chain_id,
'maxFeePerGas': web3.toWei(5, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(2, 'gwei'),
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
}
tx_signed = web3.eth.account.sign_transaction(tx, MY_PKEY)
tx_hash = web3.eth.send_raw_transaction(tx_signed.rawTransaction)
tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
请帮我弄清楚我做错了什么
好吧,我通过改变交易价值解决了这个问题
tx = {
'from': MY_ADDRESS,
'to': REF_ADDRESS,
'value': web3.toWei(0.0001, 'ether'),
'gas': allowed_gas,
'type': 2,
'chainId': web3.eth.chain_id,
'maxFeePerGas': web3.toWei(250, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(2, 'gwei'),
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
}
至
tx = {
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
'to': REF_ADDRESS,
'value': web3.toWei(0.001, 'ether'),
'gas': allowed_gas,
'gasPrice': web3.eth.gas_price
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.