0

I am getting the below error trying to call an existing smart contract I found on Etherscan.io function using call().

Error: 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, requesting data from a block number that does not exist, or querying a node which is not fully synced.

The contract, which isn't deployed by me, can be found here on etherscan.io:

Below is how I have configured my web3.0 and integrated the smart contract into my Dapp:

if(typeof web3 !== 'undefined'){
    web3 = new Web3(ethereum);
  }
else
  {
    web3 = new Web3(new Web3.provider.HttpProviders("HTTP://127.0.0.1:7545")); 
    alert("web3 is now: " +web3);
  }

web3.eth.defaultAccount  = web3.eth.accounts[0];

//##### The smart contract from Etherscan.io #####
//################################################ 
var DateTimeContractAbi = [{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getHour","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getWeekday","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint16"},{"name":"month","type":"uint8"},{"name":"day","type":"uint8"},{"name":"hour","type":"uint8"},{"name":"minute","type":"uint8"}],"name":"toTimestamp","outputs":[{"name":"timestamp","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getDay","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint16"},{"name":"month","type":"uint8"},{"name":"day","type":"uint8"},{"name":"hour","type":"uint8"}],"name":"toTimestamp","outputs":[{"name":"timestamp","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getSecond","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint16"},{"name":"month","type":"uint8"},{"name":"day","type":"uint8"}],"name":"toTimestamp","outputs":[{"name":"timestamp","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint16"},{"name":"month","type":"uint8"},{"name":"day","type":"uint8"},{"name":"hour","type":"uint8"},{"name":"minute","type":"uint8"},{"name":"second","type":"uint8"}],"name":"toTimestamp","outputs":[{"name":"timestamp","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getYear","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getMonth","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint16"}],"name":"isLeapYear","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"year","type":"uint256"}],"name":"leapYearsBefore","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"month","type":"uint8"},{"name":"year","type":"uint16"}],"name":"getDaysInMonth","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"timestamp","type":"uint256"}],"name":"getMinute","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"}];
var DateTimeContractAddress = '0x2929E21109901461659C0F26aD7f0e7633Ea6539';
var DateTimeContract = new web3.eth.Contract(DateTimeContractAbi, DateTimeContractAddress);
var DateTimeMethods = DateTimeContract.methods;

console.log ("DateTimeMethods: ", DateTimeMethods);

//##### My smart contract from Remix IDE #####
//############################################
var cryptpGiftContractAbi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_messageToRecipient","type":"string"}],"name":"editMyGifts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_extendTimeBy","type":"uint256"}],"name":"extendTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"mintNFTtoken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_giftOwnersAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"processGifting","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"string","name":"_tokenName","type":"string"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_messageToRecipient","type":"string"}],"name":"setGiftRecipient","outputs":[],"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftStatus","outputs":[{"internalType":"enum etherGifter.Status","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"giftCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"gifts","outputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"tokenName","type":"string"},{"internalType":"string","name":"messageToRecipient","type":"string"},{"internalType":"enum etherGifter.Status","name":"GiftStatus","type":"uint8"},{"internalType":"uint256","name":"createdAt","type":"uint256"},{"internalType":"uint256","name":"firstReminderAt","type":"uint256"},{"internalType":"uint256","name":"transferDate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"giftsByToken","outputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"tokenName","type":"string"},{"internalType":"string","name":"messageToRecipient","type":"string"},{"internalType":"enum etherGifter.Status","name":"GiftStatus","type":"uint8"},{"internalType":"uint256","name":"createdAt","type":"uint256"},{"internalType":"uint256","name":"firstReminderAt","type":"uint256"},{"internalType":"uint256","name":"transferDate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_giftOwnersAddress","type":"address"}],"name":"recieveAddress","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view..."}];
var cryptpGiftContractAddress = '0xA90551f8684B4a5C10648141528A12287c59f03E'; 
var cryptpGiftContract = new web3.eth.Contract(cryptpGiftContractAbi, cryptpGiftContractAddress);
var cryptpGiftMethods = cryptpGiftContract.methods;

Kindly NOTE that in reference to the code above, I have connected two different smart contracts to my Dapp, one of them, namely the **cryptpGiftContract** is my own and works perfectly. It lives on the Remix IDE, under Environment Web3 Provider, which also means am connected to the Ganache and not the mainnet. I am able to successfully call all the methods on my smart contract, so the issue here isnt my smart contract, rather > why I am NOT able to connect to the DateTimeContract contract.

At this point, I am certain that my integration is successful because the console.log ("DateTimeMethods: ", DateTimeMethods); yeilds:

the yeilds of console.log ("DateTimeMethods: ", DateTimeMethods);

Which reflect all smart contract methods at: all the smart contracts

However when I call the getDay() method, as illustrated below:

await DateTimeMethods.getDay("1652443717").call( ({from: ethAddresss}), (error, result)=> {
    console.log("Your in DateTimeMethods"); 
    console.log("Result: " +result);
    console.log("Error: " +error);
    if(!error){ }
    else{}
});

...this is the result I get:

Your in DateTimeMethods

ethAddresss: 0xbcc3594a11a7fd838b34bab789d246d918f2dab2

Result: undefined

Error: 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, requesting data from a block number that does not exist, or querying a node which is not fully synced.

Also web3.min.js:22 errors out the below in the console.

web3.min.js:22 Uncaught (in promise) 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, requesting data from a block number that does not exist, or querying a node which is not fully synced.

Kindly help me understand what the issue might be.

1 Answer 1

1

That's because nothing is deployed in your Ganache's address 0x2929E21109901461659C0F26aD7f0e7633Ea6539.

You need to execute this on mainnet, to receive an answer from that contract.

5
  • In an attempt to fork it as you suggested, my personal smart contract was compiled using the version: 0.8.13+commit.abaa5c0e, while the DateTimeContract contract am trying to fork was compiled using compiler version: 0.4.26+commit.4563c3fc. Wouldn't this create a version conflict?
    – SirBT
    May 16 at 11:38
  • If it's already compiled, there shouldn't be an issue. Feel free to accept the answer if it helped.
    – Kof
    May 16 at 17:25
  • There is an issue though, after I forked it, am not able to use the Date time functions.
    – SirBT
    May 16 at 20:40
  • That's a different issue, start a new question with details relevant to that new issue.
    – Kof
    May 17 at 6:18
  • sure thing. Do you have time to chat a little?
    – SirBT
    May 17 at 6:56

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.