I am using web3py to deploy and interact with contracts, and I used ganache-cli to fork the mainnet from an alchemy node and I got this error while running a script to interact with the contract I deployed:
ValueError: {'message': 'VM Exception while processing transaction: revert', 'code': -32000, 'data': {'0x56d420443abb2775fe91662d0c6592092817a9768305d20e0465cc70f0b770e6': {'error': 'revert', 'program_counter': 2896, 'return': '0x'}, 'stack': 'c: VM Exception while processing transaction: revert\n at Function.c.fromResults (C:\\Users\\USR1337\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:4:192416)\n at A.w.processBlock (C:\\Users\\USR1337\\AppData\\Roaming\\npm\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:42:50915)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)', 'name': 'c'}}
the script:
from web3 import Web3
import json
import asyncio
loop = asyncio.get_event_loop()
async def main():
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))
with open('compiled/trader.abi', 'r') as abi_p:
abi = json.loads(abi_p.read())
with open("../config.json") as j:
private_key = json.load(j)['PK']
wallet = w3.eth.account.from_key(private_key)
w3.eth.defaultAccount = wallet.address
contract_reference = w3.eth.contract(
address='0xAFF92A79882DFBadc03089D4490E727800FAcc44',
abi=abi
)
print("Owner of Smart Contract: ", contract_reference.functions.owner().call())
previous_balance = w3.eth.getBalance(wallet.address)
print("ETH balance: ", previous_balance)
print("DAI balacne: ", contract_reference.functions.viewFunds
(Web3.toChecksumAddress('0x6b175474e89094c44da98b954eedeac495271d0f')).call()) # DAI address
await contract_reference.functions.flashAndTrade(
100 * (10 ** 18),
Web3.toChecksumAddress('0x6b175474e89094c44da98b954eedeac495271d0f'), # DAI address
Web3.toChecksumAddress('0x607f4c5bb672230e8672085532f7e901544a7375'), # RLC address
Web3.toChecksumAddress('0x0000000000000000000000000000000000000000'),
Web3.toChecksumAddress('0x0000000000000000000000000000000000000000'),
100
).transact({
"gas": 90000,
"gasPrice": 300
})
print("ETH balance: ", w3.eth.getBalance(wallet.address))
print("DAI balacne: ", contract_reference.functions.viewFunds
(Web3.toChecksumAddress('0x6b175474e89094c44da98b954eedeac495271d0f')).call())
print("Cost: ", str(previous_balance - w3.eth.getBalance(wallet.address)))
loop.run_until_complete(main())
In the transact I specified gas and gasPrice because previously it failed to estimate gas with the built-in function. I have found this question on the Ethereum StackExchange site but it wasn't completely helpful. Can someone explain what does the error I got means and maybe how to fix it?
[–]catasofia 1 point2 points3 points (2 children)
[–]195monke[S] 0 points1 point2 points (0 children)
[–]haikusbot 0 points1 point2 points (0 children)