'Error 'rlp: expected List' when calling a smart contract function using web3py
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kratatomi |
