0

//solidity code

function addCandidate(string memory _name)  public 
        {
        candidatesCount++;
        candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);
        }

//App.js

async loadBlockchainData()
   {
     const web3 = new Web3("http://localhost:7545")

     const accounts =await web3.eth.getAccounts() 

     this.setState({account: accounts[0]})

     var Election = new web3.eth.Contract(election_abi,election_add)

    const elect = await Election.methods.returnCandidateCount().call()

 await 

Election.methods.addCandidate('Candidate').send({from:this.state.account}).then(

(receipt) => {
  console.log(receipt);
   });
}

I want to add candidate and insert transaction via .send({from:account}) but compiler throws error that addCandidate is not function. I used await before calling method. here I am getting an output of returnCandidateCount().call() but there is error in addCandidate() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.