0

How do I change a variable in a smartcontract (bool)

As requested, a new followup question from the above^ about ethereum smart contracts (solidity)

If I have, early in the contract:


bool public myVariable = false;


and then later on:


function set_myVariable(bool newVal) public{ require(msg.sender == 0x..myaddress); myVariable = newVal; }


How do I go about triggering that function in the published contract, and will it "permanently" toggle the true/false state of myVariable, despite the hard-coded =false part at the beginning?

  • This depends on what programming language you're using. If JavaScript, take a look at programtheblockchain.com/posts/2017/12/13/…. I think it will help explain the basics. – smarx Mar 13 '18 at 18:25
  • Sorry - it's solidity, I should clarify. I was hoping to interact with the contract through something like MEW's "Interact with Contract" facility, rather than making an app to do it? I suspect I will just need a few lines of code and message them to the contract? – John Mar 13 '18 at 20:48
  • MEW should just work. Are you having trouble with it? – smarx Mar 13 '18 at 21:22
  • Well, I literally don't know what to type in, you see. Like, what do I write in order to achieve this - I don't know where to begin. See the final paragraph of my question, basically - really need introducing to how such things work. – John Mar 13 '18 at 22:05
  • Have you compiled and deployed your contract? If so, you should have an address and the ABI JSON. Put those things into MEW's "Interact with Contract" feature. If not, then start by learning how to compile and deploy contracts. programtheblockchain.com/posts/2017/12/19/… might help. – smarx Mar 13 '18 at 23:08

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.