5

I didn't find a way to have optional arguments in the solidity docs so i'm wondering if anyone has found a working around to this ?

All i can think of are internal functions with " empty " params but that's going to be ugly very fast.

As anyone found a working around to this ?

  • Just to clarify, what are you trying to do? Optional based on what conditions? Do you mean being able to feed in a parameter into a function which isn't used within the function? – Physes Jul 3 '16 at 21:12
  • no, i mean function x(params1,--optionalparams2,--optionalparams3,-optionalparams4) where --optionalparams is as the name says optional – solinooby Jul 6 '16 at 18:57
  • @solinooby Did you find an answer to your question bellow? If yes, please mark as answer and vote up. thanks, – Muhammad Altabba Jan 15 '18 at 11:01
5

Unfortunately solidity does not have the ability to add variable/ optional params. Strange enough there is away to add anonymous params, i.e. with no name.

4

Till now, this is no optional parameters in Solidity.

However, they plan to include this. You can check the discussion at GitHub: https://github.com/ethereum/solidity/issues/232

2

As mentioned by @roland-kofler and @muhammad-altabba , Solidity does not provide for optional parameters. Though such functionality can be achieved by using function overloading : http://solidity.readthedocs.io/en/v0.4.21/contracts.html#function-overloading
or a hack could be sending 0x0 as the argument when not present and accounting for that within the function.
I hope this is helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.