尝试阅读智能合约。错误:返回值无效,是不是没油了?

问题描述 投票:0回答:0

你能解释一下我的代码有什么问题吗?为什么我会收到错误:返回值无效,是不是没油了?

import React, { useState, useEffect, useMemo, useCallback } from 'react'
import { injected } from '../components/wallet/connectors'
import { useWeb3React } from '@web3-react/core';
import swampSmartContractABI from '../swamp-smart-contract.json'

export const MetaMaskProvider = ({ children }) => {
   const Web3 = require('web3')
   const rpcURL = 'https://mainnet.infura.io/v3/35abf203633a4f06b46753c7f8ac8717'
   const web3rpc = new Web3(rpcURL)
   let contractAddress = "0xc5A49b4CBe004b6FD55B30Ba1dE6AC360FF9765d";
   let walletAddress = "0xF83aa70700Cea9Ee7B30CeD448Be4dC510f6D1C6";

   let contract = new web3rpc.eth.Contract(swampSmartContractABI,contractAddress);

   async function getBalance() {
     let balance = await contract.methods.balanceOf(walletAddress).call();
     return balance;
   }
   
   getBalance().then(function (result) {
     console.log(result);
   });
}

我的控制台的错误代码:

index.js:303 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 f.decodeParametersWith (index.js:303:1)
    at f.decodeParameters (index.js:291:1)
    at y._decodeMethodReturn (index.js:494:1)
    at m.outputFormatter (index.js:801:1)
    at m.formatOutput (index.js:145:1)
    at a (index.js:538:1)
    at index.js:293:1
    at index.js:127:1
reactjs blockchain cryptocurrency web3
© www.soinside.com 2019 - 2024. All rights reserved.