The call function for getTokensForUSD works perfectly on testnet and hardforks but doesn't work on mainnet... Here's the function code :-
function getTokenForUSD(uint256 _usdAmount) public view returns(uint256 , uint256 tokenAmountRequired) {
// Calculate the token amount required for the given USD amount at the current price
tokenAmountRequired = (_usdAmount * 1 ether) /getCurrentPrice();
// Calculate the tokens available in the current phase
uint256 tokensAvailable = phaseLimit[currentPhase] - tokenSold;
// If the required tokens can be fulfilled from the current phasse, return the required token amount
if (tokenAmountRequired < tokensAvailable ) {
return(_usdAmount, tokenAmountRequired ); // Return token amount in whole units (tokens, not wei)
}else if (currentPhase == 2 ){
uint256 remainingTokens = tokenAmountRequired - tokensAvailable;
// Calculate the remaining USD equivalent to cover the remaining tokens
uint256 remUSD = (remainingTokens * getCurrentPrice())/1 ether ;
return(_usdAmount-remUSD, tokensAvailable);
}else{
uint256 remainingTokens = tokenAmountRequired - tokensAvailable;
// Calculate the remaining USD equivalent to cover the remaining tokens
uint256 remUSD = (remainingTokens * getCurrentPrice())/ 1 ether ;
// Calculate the tokens needed from the next phase
uint256 tokensNeededFromNextPhase = (remUSD * 1 ether)/ phasePrice[currentPhase + 1];
// Calculate the total tokens receivable by combining tokens from the current and next phases
tokenAmountRequired = tokensAvailable + tokensNeededFromNextPhase;
return (_usdAmount, tokenAmountRequired ); // Return token amount in whole units (tokens, not wei)
}
}`
Here are both testnet and mainnet links. Mainnet : - text Testnet: -text
I was trying to get transaction values on frontend on mainnet, on testnet i can get values and even reacd the function on explorer.