I am currently working on coding an crowdsale contract that take an WeiAmount and and rate to give the user an amount of Coin from another contract.
Originally the rate variable is an argument we manually put while deploying the contract. But i want that rate variable to always change while the Function is called. I want the rate variable to be the result of ETH/USD provided by Chainlink Feed price contract
here how my code go
Original code =
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount*rate;
}
My change =
function _getTokenAmount(
uint256 _weiAmount
) internal view returns (uint256) {
int256 answer = getChainlinkDataFeedLatestAnswer();
return _weiAmount * uint256(answer);
}
The getChainlinkDataFeedLatestAnswer function =
function getChainlinkDataFeedLatestAnswer() public view returns (int) {
// prettier-ignore
(
/* uint80 roundID */,
int answer,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = dataFeed.latestRoundData();
return answer / (10 ** 8);
}
The crowdsale contract deploy correctly and i have no error but here what i get when i try to launch the function =
"0x0 Transaction mined but execution failed" I know its coming from that particular code but im not sure what to do
Any idea please ?