1

So basically I am just getting started with Truffle and I have created my first Solidity code, which looks like this:

pragma solidity ^0.4.4;
contract HelloWorld
{

function SayHello() internal pure returns (string)
{
    return ("Hello World!");
}

}

I then opened Powershell and ran the following command: testrpc Than I compiled and migrated my code using "truffle" compile and "truffle migrate"

The problems started occurring when I opened "truffle console" and did this, giving me an error at the end:

PS C:\Users\**\MetaCoin> truffle console

truffle(development)> var hw

undefined

truffle(development)> HelloWorld.deployed().then(function(deployed){hw=deployed});

undefined

truffle(development)> hw.SayHello.call()

**TypeError: Cannot read property 'call' of undefined**

truffle(development)>

Can someone help me with this? Thanks.

1 Answer 1

1

It's async.

Try

> var hw;
> var saidSomething;
> HelloWorld.deployed().then(... hw = instance; });
> hw.SayHello().then(function(response) { saidSomething = response; }); 
> saidSomething;
Hello World!    <=== worked?

Hope it helps.

9
  • Than you very much for the reply. I got an error when I reached this line: > HelloWorld.deployed().then(... hw = instance; }); which looked like this: Mar 12, 2018 at 22:42
  • evalmachine.<anonymous>:1 HelloWorld.deployed().then(... hw = instance;}); ^^^^^^^^ SyntaxError: missing ) after argument list at new Script (vm.js:51:7) at createScript (vm.js:136:10) at Object.runInContext (vm.js:181:10) at Console.interpret Mar 12, 2018 at 22:42
  • I managed to improve it so it became: HelloWorld.deployed().then(hw = instance); with this error: ReferenceError: instance is not defined Mar 12, 2018 at 22:43
  • HelloWorld.deployed().then(function(instance) { hw = instance; }); // instance is the name you give to the response from the deployed method. Mar 12, 2018 at 22:47
  • TypeError: hw.SayHello is not a function Mar 12, 2018 at 22:53

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.