I have used remix and I can see that whenever I create a public variable, it also creates a function for the variable and when you press it, it shows the variable value but, when I want to call a variable using web3.js the function should have been written from solidity that returns the variable value, in order to call it from contract.methods.<function>.

My question is: is there a way to call any variable inside a smart contract, without actually writing the function that returns the value in solidity?

  • Yes u can, every variable (private or public) is sorted publicly but u just need to find it
    – Majd TL
    Sep 19 at 20:10
  • If the variable is public it will have automatically a get method. use the variable name after .methods
    – Majd TL
    Sep 19 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.