I have a view function I'm trying to call on the kovan network with the following code. (You'll need an RPC_URL for the kovan network.)
The function is the Chainlink historical price view function. I should be able to pass it a roundId
and get back the price data from the round. I am able to do this in solidity, but for some reason I'm having a hard time in web3.py
import os
from web3 import Web3
web3 = Web3(Web3.HTTPProvider(os.getenv('RPC_URL')))
address = '0x396c5E36DD0a0F5a5D33dae44368D4193f69a1F0'
abi = '[{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]'
price_feed_contract = web3.eth.contract(address=address, abi=abi)
price_feed_contract.functions.getRoundData(1).call()
This is not a payable function, so I should not have to use send()
as deemed by this similar question.
Error: Node error: {"code":-32015,"data":"Reverted 0x","message":"VM execution error."}
I end up getting this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/web3/contract.py", line 964, in call
**self.kwargs
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/web3/contract.py", line 1499, in call_contract_function
return_data = web3.eth.call(call_transaction, block_identifier=block_id)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/eth_utils/functional.py", line 45, in inner
return callback(fn(*args, **kwargs))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/web3/eth.py", line 434, in call
[transaction, block_identifier],
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/web3/manager.py", line 153, in request_blocking
raise ValueError(response["error"])
ValueError: {'code': -32015, 'data': 'Reverted 0x', 'message': 'VM execution error.'}
Any thoughts?