错误“rlp:预期列表”使用 web3py 调用智能合约函数时

发布于 2025-01-10 03:24:00 字数 2638 浏览 2 评论 0原文

我正在尝试调用部署在 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解码器,这个原始交易不正确,所以也许有些东西的格式不正确。

I'm trying to call a function on a smart contract deployed on SmartBCH.

This is the function ABI:

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

This is the Python code:

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)

The private key is stored as a string in server_settings.PORTFOLIO_PRIV_KEY.
The error I got is:

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'}

This is the raw transaction, which I got when calling signed_txn.rawTransaction:

HexBytes('0x02f87182271081fa8477359400847735940082faf3947642df81b5beaeeb331cc5a104bd13ba68c34b91808428e9d35bc080a0c5570eba5692b8beb1e1dd58907ab709f35409f95daddc8bf568fcfcbf1a4320a02250b01810c2f801fb7afec9ca3f24ffea84869f42c3c91e2c8df245af8bc2b7')

According to a Ethereum tx decoder, this raw transaction is not correct, so perhaps something isn't formatted properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2025-01-17 03:24:00

这就是解决方案:

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

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

This is the solution:

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

The problem came from 'maxFeePerGas' and 'maxPriorityFeePerGas' parameters. These are obsolete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文