I’ve been developing a smart contract on Kovan with no issue.
I’ve deployed to Mainnet and the call methods (with ‘external view’) are returning insufficient funds for gas
errors.
I thought that call methods do not cost any gas? Is this correct?
If so, what would cause call function to return an error like that?
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
contract Contract {
address payable public owner;
string public dapp_name = "Eth Text";
uint public messagesSentCount = 0;
uint decimals = 8;
uint scale = 10**decimals;
uint public txtPriceUSD = 1.70 * 10**8;
uint public txtPriceEth;
using SafeMath for uint;
AggregatorV3Interface internal priceFeed;
event Spend(
string textMsg,
string recipient
);
event TextMsgError(
string reason
);
constructor() {
owner = msg.sender;
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
}
function sendTextMessage(
string calldata textMsg,
string calldata recipient
) external payable returns(bool) {
(uint newTxtPriceEth,,) = this.pollTxtPrices();
require(
msg.value > newTxtPriceEth,
'Please send the correct amount of ETH to make send a message'
);
emit Spend(textMsg, recipient);
messagesSentCount += 1;
return true;
}
function setTxtPrices(uint _txtPriceUSD) external ownerOnly() {
(int price,) = getLatestPrice();
uint ethPriceUSD = uint(price);
txtPriceEth = scale.mul(_txtPriceUSD).div(ethPriceUSD);
txtPriceUSD = _txtPriceUSD;
}
function pollTxtPrices() external view returns(uint, uint, uint) {
(int price,) = getLatestPrice();
uint newTxtPriceEth = scale.mul(txtPriceUSD).div(uint(price));
return (newTxtPriceEth, txtPriceUSD, decimals);
}
function totalBalance() external view returns(uint) {
return payable(address(this)).balance;
}
function withdrawFunds() external ownerOnly() {
msg.sender.transfer(this.totalBalance());
}
function destroy() external ownerOnly() {
selfdestruct(owner);
}
function getLatestPrice() public view returns (int, uint) {
(
,int price,,,
) = priceFeed.latestRoundData();
return (price, decimals);
}
function uintToWei(uint unum) private pure returns(uint p) {
return unum * (1 wei);
}
modifier ownerOnly() {
require(msg.sender == owner, 'only owner can call this');
_;
}
}