中间件未解决测试 binance 提供程序中的 ExtraDataLengthError,导致未知帐户

Posted

技术标签:

【中文标题】中间件未解决测试 binance 提供程序中的 ExtraDataLengthError,导致未知帐户【英文标题】:middleware dont solve ExtraDataLengthError in test binance provider, resulting in unknown account 【发布时间】:2021-10-28 21:02:11 【问题描述】:

这是币安上下文中的特定错误,如果您想在其中进行测试,请编写代码:

import web3
HTTPProvider = 'https://data-seed-prebsc-1-s1.binance.org:8545/'
w3 = web3.Web3(web3.Web3.HTTPProvider(HTTPProvider))
#middleware
#w3.middleware_onion.inject(web3.middleware.geth_poa_middleware, layer=0) #(change to other error)
#w3.eth.get_block('latest')
my_account = w3.eth.account.privateKeyToAccount('my_private_key_wallet')
abi = 'my_abi'
w3.eth.contract(contract_address1,abi=abi).functions.transfer(wallet_address2, 1).transact('from': my_account._address)

如果在没有中间件的情况下运行:

  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/contract.py", line 997, in transact
    return transact_with_contract_function(
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/contract.py", line 1590, in transact_with_contract_function
    txn_hash = web3.eth.send_transaction(transact_transaction)
...
  File "/home/ubuntu/env/lib/python3.8/site-packages/eth_utils/applicators.py", line 84, in apply_formatters_to_dict
    yield key, formatters[key](item)
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/middleware/validation.py", line 71, in check_extradata_length
    raise ExtraDataLengthError(
web3.exceptions.ExtraDataLengthError: The field extraData is 97 bytes, but should be 32. It is quite likely that you are connected to a POA chain. Refer to http://web3py.readthedocs.io/en/stable/middleware.html#geth-style-proof-of-authority for more details. The full extraData is: HexBytes('0x...')

如果使用中间件解决方案运行(在互联网上的其他问题中有解释):

  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/contract.py", line 997, in transact
    return transact_with_contract_function(
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/contract.py", line 1590, in transact_with_contract_function
    txn_hash = web3.eth.send_transaction(transact_transaction)
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/eth.py", line 686, in send_transaction
    return self._send_transaction(transaction)
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/manager.py", line 187, in request_blocking
    return self.formatted_response(response,
  File "/home/ubuntu/env/lib/python3.8/site-packages/web3/manager.py", line 168, in formatted_response
    raise ValueError(response["error"])
ValueError: 'code': -32000, 'message': 'unknown account'

钱包(如余额)和合约(如总供应)的功能在 web3py 中工作。

通过 Metamask 发送令牌有效,但我需要通过 web3py 发送令牌:(

【问题讨论】:

【参考方案1】:

已解决,我使用 buildTransaction、sign_transaction 和 send_raw_transaction。 并以纯形式(0x ...)键入:)

【讨论】:

请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。

以上是关于中间件未解决测试 binance 提供程序中的 ExtraDataLengthError,导致未知帐户的主要内容,如果未能解决你的问题,请参考以下文章

Binance Smart Chain - 将合约从测试网迁移到主网

Advanced Installer 中测试数据库连接提示“未发现数据源名称并且未指定默认驱动程序”的解决办法

[Blockchain] (Binance Smart Chain) BSC 测试网 BNB 水龙头

预加载程序未捕获的错误“e.indexOf - 不是函数”。

自定义凭据提供程序未加载

oracle 问题 ORA-00933: SQL 命令未正确结束 如何解决?