Truffle Introduction

Hi @filip I keep getting this message and I can’t figure out where my error is. chhers
Kim

truffle(ganache)> instance.getMessage()
‘helloWorld’
truffle(ganache)> instance.setMessage(“kim”)
Thrown:
evalmachine.:0
instance.setMessage(“kim”)
^

TypeError: instance.setMessage is not a function
at evalmachine.:0:10
at sigintHandlersWrap (vm.js:269:15)
at Script.runInContext (vm.js:124:14)
at runScript (C:\Users\dread\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:213:1)
at Console.interpret (C:\Users\dread\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:228:1)
at ReplManager.interpret (C:\Users\dread\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\repl.js:123:1)
at bound (domain.js:419:14)
at REPLServer.runBound [as eval] (domain.js:432:12)
at REPLServer.onLine (repl.js:716:10)
at REPLServer.emit (events.js:223:5)

here is my code…

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 {
message = newMessage;
}
}

1 Like

Did you compile and deploy after you added the setmessage function? If you run migrate --reset in the console it should deploy the new one. After that your code should work fine.

2 Likes

Hi all,

for Windows 10 you should simply switch from power shell to CMD…and do the same steps in cmd to init truffle like filip does.
It works for me so
Hope it helps.

2 Likes

hi all,
I found a solution for installing truffle on windows .
on youtube I have found a good how to video for installing solidity on windows:


remember: you have to install the solidity settings on atom -> settings.
also like filip said, change the truffle-config.js file in atom!

hope it helps

3 Likes

Hi everyone,

I’ve tried installing Truffle on my MacBook Air, but I ran into many errors. Here is the screenshot of the errors.
truffle_error

It seems like there are some “access denied” types of errors, which I don’t understand, as my account is already admin. I don’t think I can elevate my account any more.

Has anyone installed Truffle on a MacBook so far? I am sure I am not the first one who tried it. Please let me know if any of you knows the answers. Please help me. @filip

3 Likes

Try to install it without the -g , it will install it in your local repository where you have the correct right.

Otherwise do the same command with sudo NOT RECOMMENDED

sudo npm install -g [email protected]

sudo allow you to run the command as root , your user should be in the /etc/sudoers file.
If you can’t execute command as sudo, you will have to log as root and add your user to /etc/sudoers file.
something like :

 ## Allow root to run any commands anywhere
amy    ALL=(ALL)       ALL

depends on your user name

If you want to understand the reason why do
ls -l /usr/local/lib

it should show you something like this
drwxr-xr-x. 4 root root 4096 Sep 20 11:34 lib

only the user root or the group root can write read and execute on this folder
then
id

This command will show you your user name and your group.

If you install it locally (without -g) you should have the right to write in your folder.

Look about file permission/ chmod/ sudoers on google for more information.

7 Likes

Thank you very much, @gabba! It seems that your method of running without -g option worked. I took a screenshot of the installation.
truffle_install

3 Likes

For those using the VSCode editor: you can use the solidity extension for autocompletion / syntax highlighting etc. Search for solidity in marketplace, I use the one by “Juan Blanco”, which seem to work quite good.
Just make sure that you set the correct compiler in the settings in .vscode/settings.json, so it looks like:

{
  "solidity.compileUsingRemoteVersion": "v0.5.12+commit.7709ece9"
}
1 Like

I am having an issue that wants me to update the line you have above @Erno … But not sure where to do that…

On ubuntu I tried 2 things…

First created a file settings.json in the path you mentioned above and pasted in your example.

2nd I clicked the settings within Juan Blanco’s plugin and added that line to the settings… But I am still getting an error about it wanting version 6.0.

Any feedback based on what you were seeing? I installed truffle correctly and see that its using 0.5.12.

What do you mean with that it’s wanting version 6.0? I don’t think I’ve seen that error before.

I changed the compiler version in the truffle config, added pragma 0.5.12 and added the above commit as a version for the plug-in to work. I’m using Mac myself, but I doubt that that should be an issue

Yea it seems to be working, compiler wise and actually compiling and functioning… I think it might just be a hiccup inside of visual studio code…

On the pragma line its highlighted and complaining but its not stopping it from working. I think its just the IDE complaining.

@Amy_Oh, @gabba [quote=“gabba, post:27, topic:10049”]
sudo npm install -g [email protected]
[/quote]

Hello @Amy_Oh !

Did this work for you, I can’t get it to work…

Any tips? @gabba

EDIT;

I fixed it, somehow…

I used this method, if anyone else got a problem;
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

1 Like

Thx for sharing, it’s definitely better than running it as sudo.
I will add this line to my .bashrc :+1:

1 Like

Hi @Paultier. I found a solution if you want to run scripts in powershell you will need to change the execution policy as its default is restricted.

In a admin powershell run Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser to make the current user always able to run scripts else if you just want it to be able to run it for the current shell session you would the need to change the scope to Process instead of CurrentUser.

You can read more about it here
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7

6 Likes

Hi @Albin,

If you see the screenshot I posted, I did NOT use “sudo npm install -g”, but I used “npm install [email protected]” instead, which is installing WITHOUT -g.

As you can see in the screenshot, this method worked fine for me. Despite a few warnings, in the end, it says “+ [email protected] added 27 packages from 439 contributors”. After all, I could run the sample hello world program that was introduced by @filip in Ethereum Smart Contract Programming 201 course. Though I have not done much more than that for the Smart Contract 201 course because I am dealing with other errors at the moment, I think this error was corrected for me by the time I posted my last post. Anyways, I just wanted to clarify that I didn’t use “sudo” for the installation.

2 Likes

Hi, @Amy_Oh,

I did too, with some other tinkering. But thanks for the reply!

I ran into some problems with testing, if you got the same problem, this is a start;



(You’ve probably already found these, but if you haven’t…)

Again, thanks!

1 Like

Hi @filip,

I currently have 32-bit windows. Ganache requires 64 bit. Is there a way that I can follow along with this course without upgrading to windows 64-bit?

Best, Kamil

Hi @KamilK
Did you try to build it from the source?

Thanks @gabba for your suggestion! I tried it, but unfortunately failed.

Having 32-bit windows already brought me a lot of obstacles so I decided that I will get myself a new computer supporting x64 infrastructure. Meanwhile, to not waste time, I am doing Ethereum Smart Contract Security course that I can follow up with using remix.

Have a great day!

1 Like

Ok @KamilK by the way you can do this course using the testnet by running the tests this way:
truffle test --network ropsten
It’s gonna be longer to run the test but if you don’t have other choice it can help you until you get an other computer.
Good luck :wink: