1

When I use remix to execute a function with a bool field and I put 0 into it (which I interpret as false), the remix console output tells me "bool myBool": true (what I don't understand). So I would like to know:

  1. How do I pass true or false in general via web3.js to a smart contract, as a string String(true)?
  2. Is true and false NOT the same as 1 and 0 for web3 and/or solidity?
sunwarr10r
  • 800
  • 12
  • 26

1 Answers1

4

How do I pass true or false in general via web3.js to a smart contract, as a string String(true)?

In web3 you can use booleans true and false to pass true or false values for arguments to a contract.

Is true and false NOT the same as 1 and 0 for web3 and/or solidity?

In solidity you can pass 1 or 0 to refer to true and false respectively. However, in javascript true is not equal to 1 and false is not equal to 0, that is, true===1 is a false statement same for false===0. One may get confused because the statement true==1 is true, but just because js converts between types to find the match, === does not do the conversion.

Hope this helps

Jaime
  • 8,340
  • 1
  • 12
  • 20