Truffle Introduction


pragma solidity 0.5.12;

contract HelloWorld {
  string message = "HelloWorld";

  function getMessage() public view returns(string memory){
    return message;

  function setMessage(string memory newMessage) public payable {
    require(msg.value >= 1 ether);
    message = newMessage;

Migration File

const helloWorld = artifacts.require("HelloWorld");

module.exports = function (deployer, network, accounts) {
    instance.setMessage("Hello Dude!", {value: 1000000, from: accounts[0]}).then(function(){
      console.log("Error: " + err);
    console.log("Error: " + err);

Hey @RCV

You require (msg.value >= 1 ether); but you are sending value: 1000000.
Send at 1 ether or more and it will work.


1 Like

I’ve use Visual Studio Code before, really liked it - I don’t understand why is not mentioned here

1 Like

Hi filip
I was able to successfully compile everything, when you did the HelloWorld version 0.5.12 last year. No issues at all. I went back again using different version. Here is what I did. I downloaded ganache v2.5.2, uninstalled old truffle version and I did only npm install -g truffle.
I entered the source code in Atom below but using pragma solidity 0.7.5;
Also I changed truffle-config.js’s version: “0.7.5”
Now when I issued the truffle compile from the terminal, I got this error:

TypeError: Cannot read property ‘imports’ of undefined
at Object. (C:\Users\jojop\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at ()
at fulfilled (C:\Users\jojop\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)
Truffle v5.1.66 (core: 5.1.66)
Node v12.18.2
Any help would be greatly appreciated.

I was able to solve it. I changed everything to 0.7.4 including the migration.
I opened it using Visual Studio instead of Atom. VS will give you a clue on what the issue is.

Can you check your Migrations.sol? Try to change it to 0.5.12 as well.
I have the same problem but Im using 0.7.4.
I matched them all after changing the truffle-config.js

I started using VS Code but when I compiled it, Ganache did not accept it. Also, it created a bin file. I think on Philips video, a different type of folder is created…?

I could not get Cmder to load Truffle, did it work on your end?

Hey @padlanau

Regarding this error TypeError: Cannot read property ‘imports’ of undefined follow this FAQ:

Let me know,

1 Like

Thanks @dan-i this one works for me :slight_smile:

1 Like

I found some error message after I send the console message like this

truffle(ganache)> instance.getMessage()

Uncaught ReferenceError: instance is not defined
    at evalmachine.<anonymous>:0:1
    at sigintHandlersWrap (vm.js:272:15)
    at Script.runInContext (vm.js:127:14)
    at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:213:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:228:1)
    at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/repl.js:123:1)
    at bound (domain.js:427:14)
    at REPLServer.runBound [as eval] (domain.js:440:12)
    at REPLServer.onLine (repl.js:760:10)
    at REPLServer.emit (events.js:315:20)

but the await HelloWorld.deployed() successful to compile

I found what my mistake I don’t declare new variable to call the await function.

can fixed it by use this command

let instance = await HelloWorld.deployed()
1 Like

Hello All,

At the video with title “Setter Function” at minute 2:28, when executing the command:
let instance = await Helloworld.deployed()

you may get an error like (if you already declared the instance variable before):

let instance = global.__await_outside_result; void delete global.__await_outside_result;

Uncaught SyntaxError: Identifier 'instance' has already been declared

in this case just repeat the same command without the let.

Have fun,

Edit: I just saw that @filip talks about it in minute 6:02.
I run into that problem because I had already initialised the `instance`` variable from the previous video.

1 Like

i wasn’t able to install truffle with the power shell or cmder
can some one help me out

Hi @beloved

Can you elaborate your question and include the error message and a screenshot of your power shell?


here wat occur in my window powershell when I try to install truffle

If you want to install a pkg globally, you should try to open PowerShell as administrator.
Keep me posted.

Hello @filip,

Why do I keep getting this message when I try to migrate from the Truffle console, but not from the Terminal? I also get the same message when I try to run test command for unit test from the Truffle console and then nothing happens. Mt Truffle configuration file is the same as yours. I clone your repo from GitHub so the code is exactly the same as yours, but I cannot successfully complete the exercises from the Truffle console because of this.

Unknown network "ganache". See your Truffle configuration file for available networks.

after i run mine as administrator this wat saw

I found the solution to this problem. It seems like I had to explicitly define a network named ganache in the truffle-config.js file. In my case, as follows:

ganache: {
      host: "",   
      port: 7545,           
      network_id: "5777",