[Ethereum] Compile error – Warning: Unused local variable

compilationcontract-debuggingcontract-developmentremixsolidity

I am getting warning errors on a few variables such as
deposit, totalpayment and duration which are necessary for taking payments from users.

The error I am receiving is:

Warning: Unused local variable.

Questions:

  • What does this mean?
  • And how come that payment or charges are not coming out of the user
    balance?

Screenshots:
enter image description here
enter image description here

Best Answer

Waring: This declaration shadows ...

This is happening because you declared uint duration variable at the starting of your contract (ref: Untitled.sol:27), then using same variable names as arguments in your function. If your only purpose is to use them within that function, then you don't need to declare them outside of the function. Otherwise just add underscore inside function variables i.e Untitled.sol file linenumber 152 change variable name as _duration

Warning: Unused local variable.

I hope you know EVM takes gas for execute your (op)code. If you write one line extra it will EVM will consume some gas to execute that statements. And you need to be very careful while creating variables, because it will be cost gas based on data type. Solidity compiler is giving warring for unused variables to delete. Because when you execute contract method it will cost. In near feature cost of the gas will be more. So please delete unused variables so it will reduce final opcodes i.e gas consumption of your method will be low.

Related Topic