0
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.
    at ABICoder.push.../node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParametersWith (index.js:297)
    at ABICoder.push.../node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParameters (index.js:284)
    at Contract.push.../node_modules/web3-eth-contract/lib/index.js.Contract._decodeMethodReturn (index.js:469)
    at Method.outputFormatter (index.js:759)
    at Method.push.../node_modules/web3-core-method/lib/index.js.Method.formatOutput (index.js:146)
    at sendTxCallback (index.js:522)
    at cb (util.js:689)
    at Item.push../node_modules/process/browser.js.Item.run (browser.js:153)
    at drainQueue (browser.js:123)

I keep getting this error when calling a function from my smart contract.

export const viewGreeting = async () => {
    if (!isInitialized) {
        await activateWeb3();
    }

    const res = await greeterContract.methods.getGreeting().call();
    // console.log(res);
}

code:

import Web3 from 'web3';
import Greeter from '../Greeter.json';

let selectedAccount;
let greeterContract;
let isInitialized = false;

export const providerDetails = () => {
    let provider = window.ethereum;

    if (provider) {
        provider
            .request({
                method: 'eth_requestAccounts',
            })
            .then(accounts => {
                selectedAccount = accounts[0];
                // console.log("selected account is", selectedAccount);
            })
            .catch(error => {
                console.log(error);
                return;
            });
        
        window.ethereum.on('accountsChanged', function(accounts) {
            selectedAccount = accounts[0];
            // console.log("selected account is", selectedAccount);
        });
    }

    return provider;
}

export const activateWeb3 = async () => {
    let provider = providerDetails();

    const web3 = new Web3(provider);

    greeterContract = new web3.eth.Contract(
        Greeter.abi,
        Greeter.address
    );

    isInitialized = true;

    return selectedAccount;
}

export const viewGreeting = async () => {
    if (!isInitialized) {
        await activateWeb3();
    }

    const res = await greeterContract.methods.getGreeting().call();
    // console.log(res);
}

The contract is deployed on the rinkeby testnet and I'm using hardhat. Someone suggested to verify the contract but i'm unsure how to verify it using hardhat on the rinkeby testnet. Any help would be appreciated.

deployed url: https://rinkeby.etherscan.io/tx/0x286c79f0dd7982e9ca2a75b1d6b7a4e62625d921a92692bc26b83a5d1bcadfa3

code to connect to contract: https://github.com/gumdropsteve/Chainlink-Fall2021/blob/api-dev/frontend/src/components/web3Client.js

abi file: https://github.com/gumdropsteve/Chainlink-Fall2021/blob/api-dev/frontend/src/Greeter.json

2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Nov 25 at 10:58
  • Sure, updated with the exact code! Nov 25 at 14:29
0

I realized my metamask was not on the rinkeby chain but another chain since the contract is deployed on the rinkeby chain.

New contributor
Apinan Yogaratnam is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.