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:


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?


1 Answer 1


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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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