1

I'm a beginner, just recently started reading the docs for Solidity.
I can't seem to find this anywhere on google. What does the underscore mean when placed with the indexed keyword? Examples:
_from
_id
_amount
_account
How are these different from other variables, and how are they used in events?

  • Nothing special, just a coding convention. For example, you can decide to use it for every local local variable in your code. BTW, it is not recommended anywhere in the Solidity Style Guide. – goodvibration Aug 13 '18 at 16:43
3

There's no meaning as far as Solidity is concerned.

Some programmers choose to use a leading underscore for all function parameters, just as a convention to indicate that they're function parameters.

They're also often used so as to avoid collisions, e.g.:

uint256 totalSupply;

constructor(uint256 _totalSupply) public {
    totalSupply = _totalSupply;
}

There, calling the parameter totalSupply would shadow the existing state variable totalSupply, so the leading underscore is used to avoid the naming collision.

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.