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!