1

I have a smart contract whose function calls works fine when called locally using javascript and ganache. But when I deploy to ropsten and others, the calls to its functions fail with

Error: Returned values aren't valid, did it run Out of Gas?

Since I was calling Orfeed's getExchangeRate function, I initially thought it was Orfeed that was acting up. But then I added a simple function like this:

    // SPDX-License-Identifier: GPL-3.0
    pragma solidity ^0.6.0;
    contract HelloThere  {
    
    function hallo() external pure returns(string memory){
        return "Hallo!!!";
    }
    
    }

and called the function from javascript like this:

  contractObj.methods.hallo().call().then((result) => {
            console.log("za-then construct -->>",result);
        }).catch(function(err){
            console.log('err...\n'+err);
        });

This works fine when deploying locally to ganache.

But once I deploy to ropsten, I get the errors:

error Error: Returned values aren't valid, did it run Out of Gas?
    at ABICoder.decodeParameters (/Users/gbemirojiboye/node_modules/web3-eth-abi/src/index.js:226:15)
    at Contract._decodeMethodReturn (/Users/gbemirojiboye/node_modules/web3-eth-contract/src/index.js:465:22)
    at Method.outputFormatter (/Users/gbemirojiboye/node_modules/web3-eth-contract/src/index.js:818:46)
    at Method.formatOutput (/Users/gbemirojiboye/node_modules/web3-core-method/src/index.js:163:54)
    at sendTxCallback (/Users/gbemirojiboye/node_modules/web3-core-method/src/index.js:473:33)
    at /Users/gbemirojiboye/node_modules/web3-core-requestmanager/src/index.js:147:9
    at XMLHttpRequest.request.onreadystatechange (/Users/gbemirojiboye/node_modules/web3-providers-http/src/index.js:96:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpResponseEnd (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:345:8)
    at IncomingMessage.<anonymous> (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:311:39)
    at IncomingMessage.emit (events.js:327:22)
    at IncomingMessage.EventEmitter.emit (domain.js:505:15)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Here is my truffle-config.js:

const dotenv = require('dotenv');
const fs = require('fs');
 
const envConfig = dotenv.config({silent: true});



 const HDWalletProvider = require('@truffle/hdwallet-provider');
 const infuraKey = process.env.INFURA_API_KEY;

const ethPubAddr = process.env.ETH_PUBLIC_ADDRESS;
 const mnemonic = process.env.METAMASK_PVT_KEY;//fs.readFileSync(".secret").toString().trim();
 

 console.log("mnemonic -->" , mnemonic);

module.exports = {

  networks: {
   
    mainnet: {
      provider: function() {
        return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/"+infuraKey);
      },
      network_id: '1',
      from: ethPubAddr,

    },
    ropsten: {
      provider: function() {
        return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/v3/"+infuraKey);
      },
      network_id: '3',
      from: ethPubAddr,   
      gas: 5500000, 

    },
     
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    },

   
  },

 
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.6.10",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
     settings: {          // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: true,
          runs: 200
        },
      //  evmVersion: "byzantium"
       }
    }

  }
}

What could cause this failure? and I have enough gas in my Metamask account...(8.7 Eth)

Thanks

UPDATE

Migrations dry-run (simulation)
===============================
> Network name:    'ropsten-fork'
> Network id:      3
> Block gas limit: 8000029 (0x7a121d)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > block number:        8119069
   > block timestamp:     1592470990
   > account:             0xdABB407d281d5d586fB4B68CcFD2EA4a0878Ff90
   > balance:             8.7232663532
   > gas used:            114186 (0x1be0a)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00228372 ETH

   -------------------------------------
   > Total cost:          0.00228372 ETH


2_deploy_contracts.js
=====================


   Deploying 'MyApp'
   ----------------
   > block number:        8119071
   > block timestamp:     1592471050
   > account:             0xdEBB407d28.......
   > balance:             8.6793118932
   > gas used:            2170457 (0x211e59)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.04340914 ETH


Starting
Listening on 5000
   -------------------------------------
   > Total cost:          0.04340914 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.04569286 ETH


Contract Address =  0x4cd65b9662A...



Error: Returned values aren't valid, did it run Out of Gas?
    at ABICoder.decodeParameters (/Users/gbemirojiboye/node_modules/web3-eth-abi/src/index.js:226:15)
    at Contract._decodeMethodReturn (/Users/gbemirojiboye/node_modules/web3-eth-contract/src/index.js:465:22)
    at Method.outputFormatter (/Users/gbemirojiboye/node_modules/web3-eth-contract/src/index.js:818:46)
    at Method.formatOutput (/Users/gbemirojiboye/node_modules/web3-core-method/src/index.js:163:54)
    at sendTxCallback (/Users/gbemirojiboye/node_modules/web3-core-method/src/index.js:473:33)
    at /Users/gbemirojiboye/node_modules/web3-core-requestmanager/src/index.js:147:9
    at XMLHttpRequest.request.onreadystatechange (/Users/gbemirojiboye/node_modules/web3-providers-http/src/index.js:96:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpResponseEnd (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:345:8)
    at IncomingMessage.<anonymous> (/Users/gbemirojiboye/node_modules/xhr2-cookies/xml-http-request.ts:311:39)
    at IncomingMessage.emit (events.js:327:22)
    at IncomingMessage.EventEmitter.emit (domain.js:505:15)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
17

Your Answer

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

Browse other questions tagged or ask your own question.