【问题标题】:Error 'rlp: expected List' when calling a smart contract function using web3py使用 web3py 调用智能合约函数时出现错误“rlp:预期列表”
【发布时间】:2022-07-08 05:55:01
【问题描述】:

我正在尝试调用部署在 SmartBCH 上的智能合约的函数。

这是函数 ABI:

{
        "inputs": [],
        "name": "startStake",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    }

这是 Python 代码:

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://smartbch.greyh.at'))
if not w3.isConnected():
    w3 = Web3(Web3.HTTPProvider('https://smartbch.fountainhead.cash/mainnet'))

def start_celery_stake():
    import server_settings
    ABI = open("ABIs/CLY-ABI.json", "r")  # ABI for CLY token
    abi = json.loads(ABI.read())
    contract = w3.eth.contract(address="0x7642Df81b5BEAeEb331cc5A104bd13Ba68c34B91", abi=abi)
    nonce = w3.eth.get_transaction_count(portfolio_address)
    stake_cly_tx = contract.functions.startStake().buildTransaction({'chainId': 10000, 'gas': 64243, 'maxFeePerGas': w3.toWei('2', 'gwei'), 'maxPriorityFeePerGas': w3.toWei('2', 'gwei'), 'nonce': nonce})
    private_key = server_settings.PORTFOLIO_PRIV_KEY
    signed_txn = w3.eth.account.sign_transaction(stake_cly_tx, private_key=private_key)
    signed_txn.rawTransaction
    w3.eth.send_raw_transaction(signed_txn.rawTransaction)

私钥以字符串形式存储在 server_settings.PORTFOLIO_PRIV_KEY 中。 我得到的错误是:

Traceback (most recent call last):
  File "/usr/lib/python3.8/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 13, in <module>
  File "/home/administrador/Descargas/BCH/transparency_portal/venv/lib/python3.8/site-packages/web3/eth.py", line 722, in send_raw_transaction
    return self._send_raw_transaction(transaction)
  File "/home/administrador/Descargas/BCH/transparency_portal/venv/lib/python3.8/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/home/administrador/Descargas/BCH/transparency_portal/venv/lib/python3.8/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/home/administrador/Descargas/BCH/transparency_portal/venv/lib/python3.8/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'rlp: expected List'}

这是我在调用 signed_txn.rawTransaction 时得到的原始交易:

HexBytes('0x02f87182271081fa8477359400847735940082faf3947642df81b5beaeeb331cc5a104bd13ba68c34b91808428e9d35bc080a0c5570eba5692b8beb1e1dd58907ab709f35409f95daddc8bf568fcfcbf1a4320a02250b01810c2f801fb7afec9ca3f24ffea84869f42c3c91e2c8df245af8bc2b7')

根据以太坊 tx 解码器,此原始交易不正确,因此可能某些内容的格式不正确。

【问题讨论】:

    标签: python web3py


    【解决方案1】:

    这是解决方案:

    stake_cly_tx = contract.functions.startStake().buildTransaction(
        {'chainId': 10000,
         'gas': 108287,
         'gasPrice': w3.toWei('1.05', 'gwei'),
         'nonce': nonce})
    

    问题来自“maxFeePerGas”和“maxPriorityFeePerGas”参数。这些已经过时了。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 2022-01-24
      • 2017-08-07
      • 2019-01-24
      • 2017-11-07
      • 2022-06-15
      • 2021-10-09
      • 1970-01-01
      • 2023-01-30
      相关资源
      最近更新 更多