Search code examples
solidityweb3js

Solidity contract method not working on web3


I have a method on my contract:

function reservePlace(address _address, uint _place) public{
    require(places[_place] == 0, "Place is already reserved");
    userIds[_address] = lastUserId;
    places[_place] = lastUserId;
    lastUserId += 1;
  }

and it works perfectly on truffle, I can execute it and works well but when I use web3 and I pass:

      contract.methods
        .reservePlace("0x95f086ee384d54a056d87dC8A64E354cC55E2690", 1)
        .call();

it doesn't do anything, also it doesn't show any error. Other methods work fine when I use them with web3 so web3 setup is correct. How can I solve it?


Solution

  • This is because you are calling data from the blockchain instead of sending it. In order for it to work, you should call:

    contract.methods.reservePlace("0x95f086ee384d54a056d87dC8A64E354cC55E2690", 1).send({from:'your authorized address'});