Setting bool value in mapping not working with web3 but works on remix

Hello everyone,
Sorry this issue is not very much related to OpenZippelin but I’m stuck on this and can’t seem to understand the behaviour.
I have a simple function in my smart contract:

mapping(bytes32 => bool ) isAvailable;
event SLOT(bytes32 id, bool value);
    modifier onlyIfExists(bytes32 id)
        {
            require(
                isAvailable[id] == false,
                "ALREADY EXIST"
            );
            _;
        }
      function test (bytes32 id) public  onlyIfExists(id) {
        emit SLOT(id, isAvailable[id]);      
        isAvailable[id] = true;
      }

Calling test fct on remix works fine but in my application it reverts, the problem seem to be on this line

isAvailable[id] = true; 

When i comment it i get the receipt of the tx, tried same thing with uint type , i set =1 and its not working , here is my the fct i call to test it,

const Web3EthContract = require('web3-eth-contract');
Web3EthContract.setProvider(provider);
const newIDSLOT= web3.utils.asciiToHex("momo").padEnd(66, "0")
    async initContract() {
        const instance = new Web3EthContract(ABI, ADDRESS);
        let accounts = await web3.eth.getAccounts()
        try{       
            instance.methods.test(newIDSLOT).send({ from: accounts[0],  gas: "220000" })
                .on('receipt', function(receipt){
                    console.log("receipt here !!", receipt)
                })
                .on('error', function(error, receipt) {
                    console.log('error')
                    console.log(error.data)
                });
        }catch(err){
            console.log(err)
        }
        return instance
    } 

i use “web3”: “^1.3.4”, “web3-eth-contract”: “^1.3.5”, Ganache CLI v6.12.2 (ganache-core: 2.13.2)
I would really appreciate if anyone has any idea what am i doing wrong,
Thank you!

Hey!
Is there any error message or the failed transaction hash?

1 Like

Hi, thnx for the reply!

{
  '0x6d5bf30e6349fb8911061cb3a64a33a8948f3b6ea5fe686f37b60471301a6278': {
    error: 'revert',
    program_counter: 597,
    return: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d414c524541445920455849535400000000000000000000000000000000000000',
    reason: 'ALREADY EXIST'
  },
  stack: 'c: VM Exception while processing transaction: revert ALREADY EXIST\n' +
    '    at Function.c.fromResults (/usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n' +
    '    at w.processBlock (/usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:50915)\n' +
    '    at runMicrotasks (<anonymous>)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)',
  name: 'c'
}

here its the modifier that is failing ( though i deploy a new contract before testing)