0

ERR: 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.

abi: https://github.com/creed-victor/frontend-test/blob/main/WeenusTokenABI.json

    const tokenAddress = "0x101848D5C5bBca18E6b4431eEdF6B95E9ADF82FA";
    
    const web3Context = useWeb3(`wss://mainnet.infura.io/ws/v3/${infuraProjectId}`);
    
    const { networkId, networkName, accounts, providerName, lib  } = web3Context;
    
    const web3 = new Web3(`wss://mainnet.infura.io/ws/v3/${infuraProjectId}`)
    
    const weenusContract = new web3.eth.Contract(abi, tokenAddress);
    const getTokenBalance = useCallback(async () => {
        let tokenBalance = accounts && accounts.length > 0 ? await contract.methods.balanceOf(accounts[0]).call().then(receipt=> {return receipt}) : 'unknown';
        setTokenBalance(tokenBalance);
      }, [accounts])
    
      useEffect(()=>{
        getTokenBalance();
      }, [accounts, getTokenBalance])

Contract isn't responding to the function call. Is it the abi? Is there a way I could substitute the abi or improve upon it?

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

I changed

const web3 = new Web3(`wss://mainnet.infura.io/ws/v3/${infuraProjectId}`)

to const web3 = new Web3(window.ethereum)

TylerH
  • 20,799
  • 66
  • 75
  • 101