0

I have a function called

function addUser(address pubkey) public {

  }

However when calling this function in the node backend

            contract.methods.addUser(address).call().then(function(result){}

Im getting an error saying function does not exist.

This is how the contract is being initialised:

const contract =  new web3.eth.Contract(abi, '0xb226be108ef6fc6c60d6702ae149b290f5956377');

Thanks in advance

0

You are trying to call a function which is not view or pure. Calling a method can not alter the contract´s state and your method probably wants to alter the state (I assume you just left out the implementation details). Also calling a method gives you the results directly and you can´t use a promise (then).

So you should change your call into send and add some options for the send (such as originating address). Also note that you will get back only a transaction hash instead of the actual results because the block hasn't been mined yet - but you can use the other provided events for getting the actual result. More details at: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12

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.