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
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 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?
@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.
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
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
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
Hi @ChrisPap
What were you doing before turning off your laptop?
Which commands are not recognised anymore?
Regards,
Dani
Hello @dan-i,
The last think i did was to succesfully get the getter function.
instance.getMessage()
After that when i turn on my laptop, i tried to continue to the course but unfortunately nothing was applicable any more.
Even my contracts on GANACHE was deleted.
I strongly believe that i need to do everthing from the beggining which is fine cause i will refresh what i have learnt, but do you know what should i do or how to save the progress?
In the future it will be really incovinient to do the entire course from scratch.
Thank you
Hi @ChrisPap
After that when i turn on my laptop, i tried to continue to the course but unfortunately nothing was applicable any more.
Even my contracts on GANACHE was deleted.
This is Ganache normal behaviour, it is indeed a local blockchains that does not save data once it’s shut off.
Nothing to be afraid here
Cheers,
Dani
Note that with truffle 5.1.60 the console.log doesn’t work when its inside the setMessage like so:
instance.setMessage("Hello Again!").then(function(){
instance.getMessage().then(function(message){
console.log("Current message: " + message);
});
});
it does work and returns the right value if I put the instance.getMessage outside of the instance.setMessage but this is probably not a good practice since those are async functions and theres no ways to be sure they will always perfom in the proper order. Is that right? @filip
I downgraded to 5.0.42 and it now works like it should. Do they often break things in newer versions? is that why you are recommending to use version 5.0.42? is there a general rule or a way of knowing which versions work best as we move through time?
Hey @badtoken
Because these tools continuously improve, sometimes happens that we need to adapt and update with them
I would use async functions there anyway, the compiler will execute them from top to bottom and they will be executed in order.
Try this one
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)
};
Happy learning,
Dani