TypeError: Member "push" not found or

TypeError: Member “push” not found or not visible after argument-dependent lookup in address.

Practicing ‘De-Fi tutorial’ from DappUniversity. Facing the above mentioned “push” issue. Stackoveflow guys mention that this problem occurs in Solidity 0.8 only but I use Solidity 0.5.

Would like to provide more details but without clue what the problem is as I’m a newbie in smart contracts. Any help would be appreciated.

You should provide more context. What is the stakers variable? Where is it defined?

Sure! stakers is an address type variable mentioned within the TokenFarm contract (TokenFarm.sol).

Attached the screenshot below. Let me know if you need more context.

Thanks for your attempt to help. Appreciate that.

From how it’s used, I suspect that stakers was meant to be address[] rather than address. State variables of dynamic array types have .push() and .pop() methods for adding and removing elements.

If that’s not it, I see two other, less likely possibilities:

  • push() might be a function from some library and you’re missing a using <name of the library> for address; declaration in your contract.
    • Note that since Solidity 0.7.0 using for declarations are not inherited from base contracts. This might be why people are saying the problem only occurs on 0.8.0, though I can’t say for sure since I have no idea which StackOverflow post you’re talking about.
  • stakers might also be supposed to be of a contract type with a public or external push() function.

If neither of these solves your problem I could try to compile it and see what’s wrong if you can provide a minimal self-contained example that reproduces this error.

1 Like

Awesome, Cameel! Changing address into address [] solved the issue! Huge thanks!