Solidity 合约方法不适用于 web3

Solidity contract method not working on web3

我的合同上有一个方法:

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

它在 truffle 上完美运行,我可以执行它并且运行良好 但是当我使用 web3 并通过时:

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

它什么也没做,也没有显示任何错误。当我将它们与 web3 一起使用时,其他方法工作正常,因此 web3 设置是正确的。我该如何解决?

这是因为您是从区块链调用数据而不是发送数据。为了让它工作,你应该调用:

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