Truffle Introduction

Hello there, @filip

I was wondering if anyone else has had issues with this and knows how they may have fixed it. I’m getting this error and have had a difficult time trying to figure out why.

I’ve already tried uninstalling and reinstalling Truffle and Ganache. The first time I truffle compile & truffle migrate it seems to work with no issues. But anytime I try to migrate after I get this error.

I’m not sure of it’s an issue with the module.exports or the networks in the truffle.config.js file? I left it the way it was commented out so I would have guess that it would have just worked out fine.

I was also trying to figure out where those file locations were and couldn’t find any files past webpack location (I’m guessing there’s a reason for that that I’m not knowledgeable of).

Thank you for the help!

ExtendableError: Unknown network "ganache". See your Truffle configuration file for available networks.
    at Object.validateNetworkConfig (/home/paulrmunley/.npm-global/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:110:1)
    at Object.detect (/home/paulrmunley/.npm-global/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:16:1)
    at /home/paulrmunley/.npm-global/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:206:1
2 Likes

I fixed this by adjusting the “truffle-config.js” file. Within that file you’ll see a “networks’ section with some commented out lines. Remove the comments and adjust the setting to what Ganache shows in the header (the RCP server, Network ID”). Mine looks like

    development: {
      host: "127.0.0.1",    
      port: 7545,            
      network_id: 5777,  
},
4 Likes

I was able to fix the issue I was having with the getMessage() function not firing, I had to take it out of the setMessage function (basically move the curly brackets). In the video Setter Function @filip has it within the function and it works fine so I’m confused as to why I had to make these adjustments.

`module.exports = function (deployer) {
  deployer.deploy(HelloWorld).then(function(instance){
    instance.setMessage("Hello Again!").then(function(){});
    instance.getMessage().then(function(message){
      console.log("Current message: " + message);
    });
  });
};`
1 Like

Thank you so much for this. I changed everything but the network_id: 5777, myself. I thought the star would make it use whatever network ID as it said but for some reason that wasn’t working. I appreciate the help on this! :+1:

1 Like

I actually noticed this on my end as well. When I followed the example it wasn’t showing the current message at all. I tried changing things around in the HelloWorld migration file and had no luck getting the same response. I did use the syntax that you had and it did end up working.

Hey @Paul_Kwok

The withdraw function does not need to be payable because you are not sending ether to it.
Remove also require (msg.value > 0) as you do not have to send ether to that function.

thanks,
Dani

I am stuck at setMessage. I cannot find my error.

I did the usual; restart of CMD and I’ll be damned, it works, but why?

Hello @BERGLUND

Difficult to say why worked after restarting the terminal, maybe some changes were not saved?

1 Like

@filip
At “Building our First Test Part 1” 5:55 I do not get the correct result. I get

I cannot see what is wrong, nor where to find the error.
image


image

Hello @BERGLUND

That’s a bug in the node js version you are using.
Follow this faq to downgrade node: FAQ - How to downgrade Node.Js

1 Like

@filip

It might be a good idea to give these instructions when installing in the first place, saving a lot of cursing! Being a teacher I always warn my students if they are about to find solutions by them selves, when I know the task ahead is dependent of them finding fundamental tools to complete the assignment.

@filip the Ganache2.1.1 has issues for Mac installation I am receiving following error as soon as I launch it. Is it ok to just get the latest version?

Error: Hardfork muirGlacier not set as supported in supportedHardforks
at Common.setHardfork (/node_modules/ganache-core/node_modules/ethereumjs-common/src/index.ts:112:13)
at new Common (/node_modules/ganache-core/node_modules/ethereumjs-common/src/index.ts:79:12)
at new VM (/node_modules/ganache-core/node_modules/ethereumjs-vm/dist/index.js:62:21)
at BlockchainDouble.createVMFromStateTrie (/node_modules/ganache-core/lib/blockchain_double.js:130:14)
at /node_modules/ganache-core/lib/blockchain_double.js:85:36
at /node_modules/ganache-core/lib/blockchain_double.js:191:5
at /node_modules/ganache-core/lib/database/leveluparrayadapter.js:129:14
at /node_modules/ganache-core/lib/database/leveluparrayadapter.js:24:16
at /node_modules/ganache-core/node_modules/level-sublevel/shell.js:101:15
at /node_modules/ganache-core/node_modules/level-sublevel/nut.js:121:19
at /node_modules/ganache-core/node_modules/encoding-down/index.js:51:21
at /node_modules/ganache-core/node_modules/cachedown/index.js:58:21
at ReadFileContext.callback (/node_modules/ganache-core/lib/database/filedown.js:26:14)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)

I could be wrong, but I believe taking getMessage out of the setMessage function causes the program to not wait for the success of setMessage, thus breaking the promise chain. This file almost reminds me of the callback hell. That being said, I also had no luck having the truffle console log the message using the code Filip posted.

Hey @kHarsh

Can you please provide a screenshot of your terminal where we can verify the command you are trying to run?

Thanks,
Dani

Hey @EdwardSantos

Is better to use async functions instead of callbacks indeed.

Take a look at this other solution :slight_smile:

module.exports = async function (deployer) {
  await deployer.deploy(Testing)
  const instance = await Testing.deployed();
  await instance.setMessage('Hello');
  const result = await instance.getMessage();
  console.log(result)
};

I did not type any command just dowonload and install, Ganache-2.1.1-mac.dmg, tried to start Ganache and it throws this error.

I am trying out to console log the set message, I can see the updated message on Ganache Contracts prompt however the console.log() statement is not showing anything on terminal. Following is the code, (not any way different than in lesson)

const Helloworld = artifacts.require(“Helloworld”)

module.exports = function(deployer) {
deployer.deploy(Helloworld).then(function(instance) {
instance.setMessage(“Message - 38”).then(function() {
instance.getMessage().then(function(_message) {
console.log(“check me”);
console.log("Current message " + _message);
});
});
});
};

Hey @kHarsh

Regarding the Ganache error reported, I googled it and seems like a bug.
Make sure to run the latest Ganache version.

If running the latest ganache does not fix the issue, you can try to look for an old release and test with that one, or just use Ganache-cli.

You can use Ganache-cli by opening the console and type:

truffle develop

this command spins up a local blockchain in your terminal that you can use to deploy smart contracts.

Regarding the console.log not working, you can check my previous post (2 days ago) where I suggest to use async functions instead as they make the code much more readable.

Other colleagues discussed it in this topic so feel free to investigate and find the way that suits you the best.

Happy coding,
Dani

Hey everybody!

Everything run smoothly until i turn off my laptop.
I believe everything on my cmd were lost.

Whenever i write a command its not been recognized by the system.
Should i repeat the same proccess over and over again when i shut down my laptop?
Any tips on this would be very helpful.

Thank you in advance @filip