13

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 ?

3
  • 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
    Commented Jul 3, 2016 at 21:12
  • no, i mean function x(params1,--optionalparams2,--optionalparams3,-optionalparams4) where --optionalparams is as the name says optional
    – solinooby
    Commented Jul 6, 2016 at 18:57
  • @solinooby Did you find an answer to your question bellow? If yes, please mark as answer and vote up. thanks, Commented Jan 15, 2018 at 11:01

3 Answers 3

8

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.

5

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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