【问题标题】:web3.py - sending signed transaction issue (transaction type not supported)web3.py - 发送签名交易问题(不支持交易类型)
【发布时间】:2022-01-04 01:59:17
【问题描述】:

我试图在 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)

请帮我弄清楚我做错了什么

【问题讨论】:

    标签: python binance-smart-chain web3py


    【解决方案1】:

    好吧,我通过更改交易值解决了这个问题

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-29
      • 2021-10-22
      • 2023-01-13
      • 2018-11-04
      • 2022-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      相关资源
      最近更新 更多