1

Image from Gyazo

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');
    _;
  }
}

4
  • 3
    There is some issue with your code or you're trying to use call() on a method that is updating the state of contract. Attach your code so we can check. – Miroslav Nedelchev Feb 23 at 6:47
  • I've updated the question with contact code. I definitely made a mistake and used a Kovan address for AggregatorV3Interface, when I should have used a Mainnet address. But, even calls to methods like dapp_name are failing with insufficient gas errors. @MiroslavNedelchev – GN. Feb 23 at 22:55
  • try -> c.dapp_name.call({from:account}), i think without "call" you are trying to send a transaction instead of reading the data – Majd TL Feb 26 at 10:56
  • What is the address of your contract on Kovan and Main Network? – Markus Sprunck Feb 28 at 1:14
0

Actually, the call does not use gas. However, it seems to be calculating gas in the truffle console. In truffle-config.js, set a larger number in networks.kovan.gas as in the example below.

ropsten example)

networks: { ... ropsten: { ... gas: 5500000,
... } },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.