I'm building a DApp and i'm trying to use a function in my smart contract to get the actual ethereum value, and then use it to convert a certain amount of dollars into its Ethereum value. When trying to do so, i'm getting "Internal JSON-RPC error" and i can't understand why. The contract has been correctly compiled and migrated.
This is the js code to call the function:
App.contracts.TravelCoin.deployed().then(function(instance) {
flightsInstance = instance;
return flightsInstance.GetValueInEth(dollarPrice);
}).then(function(value) {
console.log("inside function");
cell2.innerHTML = value;
}).catch(function(err) {
console.log(err.message);
});
This is the Solidity smart contract code:
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract TravelCoin{
AggregatorV3Interface internal priceFeed;
constructor() {
priceFeed = AggregatorV3Interface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e);
}
function getLatestPrice() public view returns (uint) {
(, int price,,,) = priceFeed.latestRoundData();
return uint (price*1e18);
}
function GetValueInEth(uint dollarsAmount) public view returns (uint) {
uint valuePrice = uint(getLatestPrice());
uint ethAmount = (dollarsAmount*1e18)/valuePrice;
return ethAmount;
}
}
If you want to reproduce the issue, here it is the repository link: https://github.com/CicaMatt/TravelCoin.git
I really don't know what causes this issues, as i call the other function the same way but i'm not getting any problem.