Search code examples
soliditysmartcontractsweb3js

can not use web3js send() or call() function


I have a smart contract addOwner function that accepts some param :

// add owner to the contract
    function addOwner(string[] memory _name, address[] memory _owner_address,uint _confirmationOfOwner)
     public
     onlyOwner 
     {
        require(_owner_address.length > 0,"Owner is required");
        require(_name.length > 0,"Owner's name is required");
        require(_owner_address.length == _name.length,"Each owner mush have name");
        require(_confirmationOfOwner > 0 && _confirmationOfOwner <= _owner_address.length + owners.length,"Confirmation of the owner is invalid");
        for(uint i = 0; i <_owner_address.length; i++ ){
            
            require(_owner_address[i] != address(0), "invalid owner");
            require(!isOwner[_owner_address[i]], "owner not unique");

            isOwner[_owner_address[i]] = true;
            owners.push(Owner({name:_name[i],owner_address:_owner_address[i]}));
        }
        confirmationOfOwner = _confirmationOfOwner;
    }

but when I use send() or call() function it always error with send() and get Result {} with call:

with function send():

await contract.methods.addOwner(["owner_02"],["0x5B38Da6a701c568545dCfcB03FcB875f56beddC4"],2).send({from:accounts[0]});

error:

Error: Transaction has been reverted by the EVM:
{
  "transactionHash": "0x1462de5cbae11d1de0138866ea7c2a08059bca310808cbc95277bca73235dbff",
  "transactionIndex": 0,
  "blockNumber": 19,
  "blockHash": "0xde2f833416671491c78bac4d3ae102f31e3bb89ff09a3387eee095382e6da4b6",
  "from": "0xd520cc14ef05eadc4eebe1312cdb22e2cdd03018",
  "to": "0x1d1ddaa523196d8a2b4690449626fba81e2bbcd3",
  "cumulativeGasUsed": 90000,
  "gasUsed": 90000,
  "contractAddress": null,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "effectiveGasPrice": 2612896633,
  "type": "0x2",
  "events": {}
}
    at Object.TransactionError (/Users/pon.dara/Desktop/sabay-workspace/PD/multi_sign_wallet_solidity/node_modules/web3-core-helpers/lib/errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (/Users/pon.dara/Desktop/sabay-workspace/PD/multi_sign_wallet_solidity/node_modules/web3-core-helpers/lib/errors.js:98:21)
    at /Users/pon.dara/Desktop/sabay-workspace/PD/multi_sign_wallet_solidity/node_modules/web3-core-method/lib/index.js:396:57
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  receipt: {
    transactionHash: '0x1462de5cbae11d1de0138866ea7c2a08059bca310808cbc95277bca73235dbff',
    transactionIndex: 0,
    blockNumber: 19,
    blockHash: '0xde2f833416671491c78bac4d3ae102f31e3bb89ff09a3387eee095382e6da4b6',
    from: '0xd520cc14ef05eadc4eebe1312cdb22e2cdd03018',
    to: '0x1d1ddaa523196d8a2b4690449626fba81e2bbcd3',
    cumulativeGasUsed: 90000,
    gasUsed: 90000,
    contractAddress: null,
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    effectiveGasPrice: 2612896633,
    type: '0x2',
    events: {}
  }
}

with function call():

await contract.methods.addOwner(["owner_02"],["0x5B38Da6a701c568545dCfcB03FcB875f56beddC4"],2).call({from:accounts[0]});

response:

Result {}

How to solve this or call the contract properly?


Solution

  • for this problem, I have manually set the gas fee and it is working.

    Example:

    await contract.methods.addOwner(['owner_03'],[accounts[2]],2).send({from:accounts[0],gas:700000});