1

它是 binance 上下文中的一个特定错误,如果您想在以下位置进行测试,请编写代码:

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 发送令牌 :(

4

1 回答 1

0

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

于 2021-08-30T12:30:38.480 回答