EatTheBlocks Forum

Getting error "Not A Function" even if the function is avalid function in the contract/

I am getting this error whenever I use the code …

Even though the ABI is correct, the address is correct and getGreeting is indeed a function…

Please help me out.

import React ,{Component}from ‘react’;
import Web3 from ‘web3’;
import {BOB_ABI, BOB_ADDRESS} from ‘./config’

import ‘./App.css’;

class App extends Component{
componentWillMount(){
this.detectMetamask()
this.loadBlockchain()
}
async detectMetamask(){
if(window.ethereum){
window.web3 = new Web3(window.ethereum)
await window.ethereum.enable()
}
// else if (window.web3) {
// window.web3 = new Web3(web3.currentProvider);
// // Acccounts always exposed
// }

else{
  window.alert("YOUR BROWSER HAS NO METAMASK EXTENSION")
}

}

async loadBlockchain(){
const url = “https://ropsten.infura.io/v3/d4de0da2227146e5836fbe0d55c017c7
const provider = new Web3.providers.HttpProvider(url);
// const web3=new Web3(Web3.givenProvider || “http://localhost:8545”)
const web3=new Web3(provider)

web3.eth.net.isListening()

.then(() => console.log(‘web3 is connected’))
.catch(e => console.log(‘Wow. Something went wrong’));
const network = await web3.eth.net.getNetworkType()
console.log(network)
const accounts = await web3.eth.getAccounts()

const bob_contract = new web3.eth.Contract(BOB_ABI, BOB_ADDRESS)

this.setState({
  contract:bob_contract
})

console.log(bob_contract)

const name = bob_contract.methods.getGreeting().call().then(console.log)

}

could be:

  • Contract not deployed to Blockchain
  • Contract not deployed to CORRECT Blockchain (i.e deployed on a testnet, but you are running the dapp on another…)
  • Old version of contract deployed, when the function did not exist yet
  • Frontend not reloaded properly