[英]Error 'rlp: expected List' when calling a smart contract function using web3py
我正在嘗試調用部署在 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 解碼器的說法,這個原始交易是不正確的,所以可能有些東西的格式不正確。
這是解決方案:
stake_cly_tx = contract.functions.startStake().buildTransaction(
{'chainId': 10000,
'gas': 108287,
'gasPrice': w3.toWei('1.05', 'gwei'),
'nonce': nonce})
問題來自“maxFeePerGas”和“maxPriorityFeePerGas”參數。 這些已經過時了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.