0

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

1

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.

0

What does this mean:

This declaration shadows ...

You have already declared variable named duration outside of your function. The first declaration is storage and you might want just to declare new variable with a different name to use it during function execution.

Unused local variable ...

If you are declaring variable which you don't use nor store it in storage of the contract then you are getting warning from remix. If you really need this local variables just use them inside of the function or if you want to use them later just change the state by pushing these variables to some kind of array or mapping.

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.