0

I try to develop a simple app with meteor and metamask. I'm trying to change the state of the "name" variable of this contract throught my app :

contract demo{
    string public name = 'Etienne';

    function changeName(string _newName){
        name = _newName;
    }
}

I can read and display the name variable and use it in a helper with

const myContract = web3.eth.contract(AbiArray).at(contractAddress);

Template.home.helpers({
  name () {
    const template = Template.instance();

    myContract.name(function(err,res){
      TemplateVar.set(template, "name", res);
    })

But how do I use my changeName function ? Something like this nothing happens (change-name is linked to a button):

Template.home.events({
  'click .change-name'(){
    myContract.changeName('Pitouf');
},
})

If I exlpicitely say it is transaction, not a call, I get a transaction in metamask, but the name still reads the same :

Template.home.events({
  'click .change-name'(){
    myContract.changeName('Pitouf').sendTransaction();
},
})

I am pretty sure I am using the wrong arguments… but how?

1 Answer 1

2

Found the answer: everything Metamask is asynchronous, so I need a callback function :

  'click .change-name'(){
    myContract.changeName('Pitouf', {gas: 300000},function(){});
},

And it's working !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.