Unable to send false boolean value as an argument for smart contract function

Hello Forum Gurus,

This might be a very naive question, but since I have no idea how to tackle this I must ask. I have following options object:

options = {
contractAddress: g.address,
functionName: “addToBeet”,
abi: a.abi,
params: {
_beetKey: beetKey,
_betFor: betFor,
_amount: amount,
},
msgValue: amount,
};

and I try to execute this like this:

const receipt = await Moralis.executeFunction(options);

Now, _betFor is a boolean. When it’s set to true everything goes well. If it’s set to false though I get:
['_betFor is required']

When I convert betFor to string then it gets evaluated to true…
Do you know how could I send false value?

This question is very specific to your contract, It’s hard to say without you showing what the contract function looks like there :raised_hands:

Hi, thanks for the reply. I can paste abi here, though it will only prove that _betFor is a bool. The issue is that when betFor is false it doesn’t even get to the execution of contract function. It fails before that.

{
“inputs”: [
{
“internalType”: “bytes32”,
“name”: “_beetKey”,
“type”: “bytes32”
},
{
“internalType”: “bool”,
“name”: “_betFor”,
“type”: “bool”
},
{
“internalType”: “uint256”,
“name”: “_amount”,
“type”: “uint256”
}
],
“name”: “addToBeet”,
“outputs”: [],
“stateMutability”: “payable”,
“type”: “function”
}

So you mean by fail like is it that the transaction revert or metmask doesn’t give any prompt? I might have misunderstood

When betFor is set to true then Metamask pops-out, transaction takes place and everything is ok. When it’s set to false then there is no transaction, no Metamask pop-up. The error appears in the browser console:

image

It looks like setting _betFor to false it ‘unsets’ this parameter and it is not being passed along and since it is is mentioned in abi, it’s presence is required and that’s why there is this error…

I was having similar thing when passing 0 as a parameter to some other contract function, but then I could pass “0” and everything went fine. This time I can’t do that as sending “false” will be interpreted as a boolean true value.
I know that I could change contract’s function parameter type from boolean to something else, but I’m trying to find a proper solution.

you are using latest Moralis SDK version now?

npm -v moralis shows 6.14.11, the same output is for react-moralis.

I mean Moralis SDK version, that should be 1.0.0 or 0.0.184

Thank you, thank you! I had a very antiquated version. After upgrading moralis and react-moralis packages everything works fine!

1 Like