0

I created a simple contract and try to run it on Remix. It worked fine. However, when I deployed and excuted in a private ethereum, I got the error "Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from"

I tried to update the web3 and solc, but it still got the error.

Contract code

pragma solidity ^0.5.15;                                         
    contract ExternalData {
    string public ETHUSD='7';

    constructor () payable public {
      ETHUSD = '1';
    }
       function getETHUSD () public pure returns (string memory usd) {
            return '7';
       }
}

Compile Code

const solc = require('solc');
const path = require('path');
const fs = require('fs');

const externalData = path.resolve(__dirname, 'contracts', 'ExternalData.sol');
const source = fs.readFileSync(externalData, 'utf8');

const provableAPI = path.resolve(__dirname, 'contracts', 'provableAPI_0.5.sol');
const src_provableAPI = fs.readFileSync(provableAPI, 'utf8');

var input = {
  language: 'Solidity',
  sources: {
    'ExternalData.sol': {
      content: source
    }
  },
  settings: {
    outputSelection: {
      '*': {
        '*': ['*']
      }
    }
  }
};

function findImports(path) {
  if (path === 'provableAPI_0.5.sol')
    return {
      contents:
        src_provableAPI
    };
  else return { error: 'File not found' };
}
var output = JSON.parse(
  solc.compile(JSON.stringify(input), { import: findImports })
);


var output_compiled = {
  interface : output.contracts['ExternalData.sol']['ExternalData'].abi
  , bytecode : output.contracts['ExternalData.sol']['ExternalData'].evm.bytecode.object
};

module.exports = (output_compiled);

Deploy Code

const Web3 = require('web3');
const { interface, bytecode } = require('./compile1');

const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8541"));

const deploy = async () => {
    const accounts = await web3.eth.getAccounts();
    console.log('Attempting to deploy from account', accounts[0]);

    await web3.eth.personal.unlockAccount(accounts[0], '123456');

    let _txHash;
    let _err;

    const result = await new web3.eth.Contract(interface)
    .deploy({ data: '0x' + bytecode})
    .send({ gas: '2000000', from: accounts[0] },  (err, txHash) => {_txHash = txHash; _err = err;});

    var externalData = new web3.eth.Contract(interface, result.options.address);
    var ethusd = await externalData.methods.getETHUSD().call();

    console.log(JSON.stringify(interface));

    console.log('Transaction hashId is ', _txHash);

    console.log('Contract deploy to', result.options.address);
};

deploy();
  • This error message is misleading, and it typically implies that you are trying to call a function which is not implemented in the contract. – goodvibration Feb 5 at 8:51
  • So my guess is that there is no ExternalData contract deployed at address when you try to execute dieselprice.methods.ETHUSD. – goodvibration Feb 5 at 8:57
  • Try to execute it inside your deploy function (after deploying the contract). If it works there, then it means that it doesn't work outside this function, because you are not awaiting for this function to complete (i.e., you are doing deploy() instead of await deploy()). – goodvibration Feb 5 at 8:59
  • 1
    Does this answer your question? How to setup constantinople fork for private ethereum chain – Ismael Feb 6 at 14:01
  • 1
    @Ismael Yes thank for your help. – Pakorn K Feb 11 at 6:25
1

The rather unfortunate Returned values aren't valid, did it run Out of Gas error message is usually misleading, and it typically implies that you are trying to execute a function which is not implemented in the contract.

You say that your execution code is:

dieselprice = new web3.eth.Contract(abi, address);
const price = await dieselprice.methods.ETHUSD().call();

But you do not say when you are executing it.

If there is no ExternalData contract deployed at address when you try to execute this code, then await dieselprice.methods.ETHUSD().call() would throw this exact error.

Are you sure that you are executing it after executing your deployment code?

If yes, then are you sure that you are waiting for this code (async function deploy) to complete?

Try to place your execution code inside function deploy (after deploying the contract). If it works there, then it means that it doesn't work outside this function because you are not awaiting for this function to complete.


A clarification on the statement:

If there is no ExternalData contract deployed at address when you try to execute this code, then await dieselprice.methods.ETHUSD().call() would throw this exact error.

More generally, "no ExternalData contract" should be replaced with "no contract which implements a public or external function named ETHUSD which takes no input arguments (either explicitly or by declaring a public variable of the same name)".

| improve this answer | |
  • I edit the code to make it less confused by adding calling method after finishing deployment, but I still get the same error. Do you have a way to make sure if my contract get deploy properly? – Pakorn K Feb 5 at 10:24
  • @PakornKulsirimongkol: My guess would be that bytecode is not what you think it is (i.e., it is not the compiled code of the ExternalData contract). – goodvibration Feb 5 at 10:44
  • I looked into the output. there are 2 bytecode that are evm.bytecode.object and evn.deployedbytecode.object. When using the frist one, I can deploy the code but can't call a method. For the second one, it got an error of the gas limit "The contract code couldn't be stored, please check your gas limit" – Pakorn K Feb 6 at 2:25
  • I used the same code, but tried to deploy the contract to the public testnet. It worked fine. is The problem is the private ethereum? – Pakorn K Feb 6 at 6:39
1

I can make it work by include these in the genesis file.

    "byzantiumBlock": 5,
    "constantinopleBlock": 10,
    "constantinopleFixBlock": 20  
| improve this answer | |

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.