I have a simple contract like below. I was able to successfully compile and migrate the same.

pragma solidity ^0.4.8;

contract A {

    function A() payable {

    function getBal() returns(uint a){
        return (10);


Now I am using truffle console and trying to invoke getBal() function of my contract.

A.deployed().then(function(instance) { test = instance; return test.getBal();}).then(function(result){});

I am not getting the new version 3 way of calling the functions.

Could you help me out and point what I am missing?

console window


Try this.

function getBal() 
  constant   <--- Important
  returns(uint a)
  return (10);

$ truffle console

   > A.deployed()
    .then(function(instance) {
      return instance.getBal();
    .then(function(balance) {
      console.log("got balance", balance.toString(10));

I'm not fully acquainted with Truffle 0.3 myself, but it seems to work :-)

enter image description here

enter image description here

Hope it helps.

  • Thank you Rob. I tried the above way but I am not getting the output. I am attaching the screen shot of the result – sun Mar 4 '17 at 8:32

in truffle develop you can use a contract function, on a contract that has been deployed, by:



truffle(develop)> A.at("0x842c27notcopyablescreenshot4bf7dd").getBal()

this will give you something like

{ [String: '10'] s: 1, e: 0, c: [ 10 ] }

you can find the address by going up to when the contract was first deployed


By running the command ContractName.address at truffle console.

Example output:

truffle(development)> Migrations.address '0x0045b992bafe7362e65c34ad5153fad4a2695c1f' truffle(development)>


by opening up a 2nd terminal in the same place and typing.

$ truffle networks

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.