0

Say I have a smart contract such as:

contact Rabbit {
    string public name;

    function setName(string n) returns (bool) {
        name = n;
        return true;
    }
}

How can I get the value of name after having set it? I'm using Truffle. I've tried (where rabbit is a handle of Rabbit:

rabbit.name();

This just returns ''.

Also, how can I get the return value? If I execute setName I just see the transaction, not the return value. I read somewhere I can use call(), such as: rabbit.setName.call("barry"), though it wont save the transaction so it needs ot be call again, without call(). Have I got this wrong?

Thanks.

0

Insertion can be done using sendTransaction function.

 Rabbit.deployed().then(function(contract) {contract.createProperty("Hello",{from: web3.eth.accounts[0]}).then(function(v) {console.log(v)})})

You can use call method to get the value of public variable.Try the below command in truffle console.

 Rabbit.deployed().then(function(contract)  {contract.name.call().then(function(v) {console.log(v)})})

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.