Truffle Introduction

Hi @gabba, I don’t know the difference with zsh beside the fact when I first start the terminal app it was recommending I switch so I figured it might help.

When i try to add the npm global folder to my path using :
export /Users/CalvinCutlass/npm-global/bin/:$PATH

I get this in return:

CalvinCutlass@Macintosh-10 ~ % export /Users/CalvinCutlass/npm-global/bin/:$PATH

export: not valid in this context: /Users/CalvinCutlass/npm-global/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin

Thank you for helping btw I really appreciate it. Everyone is very helpful

Hi @filip ,

I am using PowerShell on Widnows, and whenever I try to do the “truffle init” command, I get this error:

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the
execution policy might expose you to the security risks described in the
about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?

Has anyone else ran into this? If so, did you say “yes” to change the execution policy? I wanted to ask here first before I did anything because I do not want to risk getting a virus or anything on my laptop. Please let me know if know anyways to fix this!

I did not do it wilfully. I think that is the default location

It is not happening.

PS C:\Users\simpl> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See npm help json for definitive documentation on these fields
and exactly what they do.

Use npm install <pkg> afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.

package name: (simpl) npm install ganache-cli
Sorry, name can only contain URL-friendly characters.
package name: (simpl) npm install -g ganache-cli
Sorry, name can only contain URL-friendly characters.

I am using windows system. Does rm command work on windows

What should I do?

Hi @gabba,
I am still struggling to get truffle installed. I got a new macbook and changed the terminal shell back to bash. However this is the error i keep getting
MacBook-Pro:~ CalvinCutlass$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See npm help json for definitive documentation on these fields
and exactly what they do.

Use npm install <pkg> afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (turffle)
version: (1.0.0)
description: truffle
git repository:
license: (ISC)
About to write to /Users/CalvinCutlass/package.json:

{
“name”: “turffle”,
“version”: “1.0.0”,
“description”: “truffle”,
“main”: “index.js”,
“dependencies”: {},
“devDependencies”: {},
“scripts”: {
“test”: “mocha”
},
“keywords”: [
“truffle”
],
“author”: “me”,
“license”: “ISC”
}

Is this OK? (yes)

╭────────────────────────────────────────────────────────────────╮
│ │
│ New patch version of npm available! 6.14.4 → 6.14.5 │
│ Changelog: https://github.com/npm/cli/releases/tag/v6.14.5
│ Run npm install -g npm to update! │
│ │
╰────────────────────────────────────────────────────────────────╯

MacBook-Pro:~ CalvinCutlass$ npm install -g [email protected]
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
/Users/CalvinCutlass/npm-global/bin/truffle -> /Users/CalvinCutlass/npm-global/lib/node_modules/truffle/build/cli.bundled.js

[email protected] postinstall /Users/CalvinCutlass/npm-global/lib/node_modules/truffle
node ./scripts/postinstall.js

  • Fetching solc version list from solc-bin. Attempt #1
  • [email protected]
    updated 1 package in 3.868s
    MacBook-Pro:~ CalvinCutlass$ /Users/CalvinCutlass/npm-global/bin/truffle -v
    Truffle v5.0.42 - a development framework for Ethereum

Usage: truffle [options]

Commands:
build Execute build pipeline (if configuration present)
compile Compile contract source files
config Set user-level configuration options
console Run a console with contract abstractions and commands available
create Helper to create new contracts, migrations and tests
debug Interactively debug any transaction on the blockchain (experimental)
deploy (alias for migrate)
develop Open a console with a local development blockchain
exec Execute a JS module within this Truffle environment
help List all commands or provide information about a specific command
init Initialize new and empty Ethereum project
install Install a package from the Ethereum Package Registry
migrate Run migrations to deploy contracts
networks Show addresses for deployed contracts on each network
obtain Fetch and cache a specified compiler
opcode Print the compiled opcodes for a given contract
publish Publish a package to the Ethereum Package Registry
run Run a third-party command
test Run JavaScript and Solidity tests
unbox Download a Truffle Box, a pre-built Truffle project
version Show version number and exit
watch Watch filesystem for changes and rebuild the project automatically

See more at http://truffleframework.com/docs

MacBook-Pro:~ CalvinCutlass$ truffle version
-bash: truffle: command not found
MacBook-Pro:~ CalvinCutlass$ export /Users/CalvinCutlass/npm-global/bin/:$PATH
-bash: export: `/Users/CalvinCutlass/npm-global/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin’: not a valid identifier
MacBook-Pro:~ CalvinCutlass$ li
-bash: li: command not found
MacBook-Pro:~ CalvinCutlass$ ls
Applications Music mkdir
Classes Pictures node_modules
Desktop Pro Tools npm-global
Documents Public package-lock.json
Downloads Samples package.json
Dropbox Sites test_directory
Incompatible Software The Rosetta Stone v3 truffle
Library busy cards
Movies jimi
MacBook-Pro:~ CalvinCutlass$ cd Desktop
MacBook-Pro:Desktop CalvinCutlass$ ls
20TR42649700942204264970.pdf Scan.pdf
ASSEMBLY Thassos, Giola lagoon, Greece.jpg
Coding Workbook1.xlsx
GAMES comp sci tutorial
Melissa Stuff ivan on tech.docx
Orders.xlsx site pics
Relocated Items viking
MacBook-Pro:Desktop CalvinCutlass$ cd Coding
MacBook-Pro:Coding CalvinCutlass$ ls
Smart_Contracts java 8.29.19.html smart contracts
coding 2020 logic.js website (exercise).html
hello world nodejs demo website.html
MacBook-Pro:Coding CalvinCutlass$ cd Smart_Contracts
MacBook-Pro:Smart_Contracts CalvinCutlass$ ls
HelloWorld package-lock.json
node_modules package.json
MacBook-Pro:Smart_Contracts CalvinCutlass$ cd HelloWorld
MacBook-Pro:HelloWorld CalvinCutlass$ truffle init
-bash: truffle: command not found
MacBook-Pro:HelloWorld CalvinCutlass$

Hi @chaneltiana

Yes it’s normal because you will need permission to execute truffle.
You can have a look at this topics where is cover all the windows installation process

https://forumtest.ivanontech.com/t/windows-installation-git-vscode-nvm-nodes-ganache-truffle/15582

1 Like

Hi @simplyprado
When you are doing
npm init
It will initialize your current project, jsut type enter until you get back to your terminal
When it’s done you can install package with

npm install

In this lines npm initialization asked you to type your project name but you enter a command to install an other package so it ll not work
you should first

npm init

Type ENTER to all the question it asks you
then

npm install -g ganache-cli
2 Likes

Hi @mjwatson10

Ok so truffle is well installed because this is working

To set your environment variable the $ sign is really important because it will use you old PATH variable and add you new folder to it, my bad the full command should be

export PATH=/Users/CalvinCutlass/npm-global/bin/:$PATH

Don’t forget the = and $ sign.

Let me know if truffle is working after that

1 Like

Hello @chaneltiana

That error just hit me as well. The default setting helps to prevent the average user from mistakenly running malicious code. As we are the power users, we need to execute that code to allow for script editing. I used the following snippet found here.

Hope this helps. :wave:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
3 Likes

I feel I should say this (now) don’t forget to save the contract before trying to compile it…goodbye 45 minutes you will be missed.

1 Like

Thanks for the explanation, very helpful

@filip I’m getting the following error when trying to do truffle init in my Windows PowerShell:

npm\truffle.ps1 cannot be loaded because running scripts is disabled on
this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • truffle init
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    
    

Any idea what could be wrong? I appreciate the help!

Hi @rbrownlow

You can check this post were i covered the installation
https://forumtest.ivanontech.com/t/windows-installation-git-vscode-nvm-nodes-ganache-truffle/15582

I think your issue is the permission, open your powershell as administrator

Get-ExecutionPolicy -list

and set the permission this way

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Allsigned

Change the Scope with name of the scope were the execution policy is unrestricted

1 Like

Hi, @filip I have an issue with remix when. I try to run the get numbers function I got this error:

call to HelloWorld.getMessage errored: Error: sender doesn’t have enough funds to send tx. The upfront cost is: 3000000 and the sender’s account only has: 0

Do you know how to fix it?

Thanks,

I am not able to compile the contract. The reason is mainly because of the PowerShell Execution Policy environment settings. What is the current Execution Policy to be set to run Truffle - “AllSigned” or “RemoteSigned”?

I am using Windows 10.

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> truffle compile
truffle : File C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 cannot be loaded. The file C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 is not digitally signed. You cannot run this script on the current system. For more information
about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • truffle compile
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> truffle compile --list
truffle : File C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 cannot be loaded. The file C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 is not digitally signed. You cannot run this script on the current system. For more information
about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • truffle compile --list
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> Get-ExecutionPolicy -List

    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser AllSigned
LocalMachine AllSigned

I changed the Execution Policy of Process to AllSigned. Was not able to change the Execution Policy of UserPolicy to AllSigned, because it says that UserPolicy and MachinePolicy can be set through Group Policy only. What is the current environment settings required to run Truffle?

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”): Y
PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope UserPolicy
Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must be set through Group Policy.
At line:1 char:1

  • Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope UserPolicy
  •   + CategoryInfo          : InvalidOperation: (:) [Set-ExecutionPolicy], InvalidOperationException
      + FullyQualifiedErrorId : CantSetGroupPolicy,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
    

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> Get-ExecutionPolicy -List

    Scope ExecutionPolicy
    ----- ---------------

MachinePolicy Undefined
UserPolicy Undefined
Process AllSigned
CurrentUser AllSigned
LocalMachine AllSigned

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld> truffle compile --list
truffle : File C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 cannot be loaded. The file C:\Users\simpl\AppData\Roaming\npm\truffle.ps1 is not digitally signed. You cannot run this script on the current system. For more information
about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • truffle compile --list
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

PS C:\Users\simpl\Documents\BlockchainTraining\ProgrammingCourse\Ethereum\HelloWorld>

Hi @gabba , again I am getting errors related to Execution Policy. Do you think I should install this way. But the software versions are not matching. The Ganache and Truffle versions what you ask us to install and what Filip is teaching on the videos are different, I reckon.

What editor should I use? I don’t have any and you sound like I should’ve had one long time ago.

All I have is editors for Javascript and C++.

Hey Filip! What am I doing wrong?

Nvm. I’ve sold all the problems.

@simplyprado
The execution Policy shouldn’t happen anymore if it was changed correctly , are all the scope set to Allsigned ?

Get-ExecutionPolicy -list

Did you start your powershell as administrator ?

2 Likes