Learning Truffle

You can also use the provided accounts from the truffle local blockchain (truffle develop), then you can use the accounts argument to get a list of addresses to use for the constructor.

You will be have to do something like this:

const Wallet = artifacts.require("Wallet");

module.exports = function (deployer, network, accounts) {
    deployer.deploy(Wallet, [accounts[0], accounts[1], accounts[2], 1);
};

There might be a revert getting triggered, i advice you to add a error message for each require to know who is getting triggered.
require(transferRequests[_id].hasBeenSent == false, "transaction has been sent"); In case transaction.hasbeensent = true, the revert error message will be triggered.

Hope this helps.

Carlos Z

1 Like

Thanks for the tips!!

You’re totally right about that. Using events makes debugging a whole less complicated.

I tried to do the same with the migrations file, but I think I made a mistake. Don’t really like hardcoding something in my contract file. Better to use the migrations file then the contract file.

Really appreciate your feedback!!

1 Like

So i cant get truffle to create a helloworld.json file for me, so i cant get my contract to deploy anyone know the reason for it or have any tips
code for helloworld.sol

pragma solidity 0.8.11;

contract hello{
    function Hello() public pure returns (string memory){
        return "Hello world";
    }
}
//Code for hellomirgration.js
const hello = artifacts.require("hello");

module.exports = function (deployer) {
  deployer.deploy(hello);
};

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\Users\Nicco\Desktop\Code\build\contracts
> Compiled successfully using:
   - solc: 0.8.11+commit.d7f03943.Emscripten.clang



Starting migrations...
======================
> Network name:    'develop'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xc07cb9e4324c4c802a55dd59a47c138aa94ebfa83001d96d00d34b2fbee375e1
   > Blocks: 0            Seconds: 0
   > contract address:    0x644C08De0Aad0f48948c943df76C672ceFB3f8c6
   > block number:        1
   > block timestamp:     1641943185
   > account:             0x2cc1EF9a7e8BE44433165Cb1A6186A3663ADD9F6
   > balance:             99.999502316
   > gas used:            248842 (0x3cc0a)
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.000497684 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.000497684 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.000497684 ETH


- Blocks: 0            Seconds: 0
- Saving migration to chain.

truffle(develop)> migrate

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\Users\Nicco\Desktop\Code\build\contracts
> Compiled successfully using:
   - solc: 0.8.11+commit.d7f03943.Emscripten.clang

Network up to date.

truffle(develop)> migrate

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\Users\Nicco\Desktop\Code\build\contracts
> Compiled successfully using:
   - solc: 0.8.11+commit.d7f03943.Emscripten.clang

Network up to date.

truffle(develop)> migrate

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Artifacts written to C:\Users\Nicco\Desktop\Code\build\contracts
> Compiled successfully using:
   - solc: 0.8.11+commit.d7f03943.Emscripten.clang

Network up to date.`
1 Like

Hey @Nicco_Patel, hope you are ok.

Contracts name should start with a Capital letter (“Hello” instead of “hello”), then update your migration file according to the name.

After that, try with migrate --reset to refresh all deployments.

Carlos Z

Hello,
Having some issues with installing truffle, I did downgrade node.js to 10.21.0 but keep getting below message, any feedback would be great!!!

es’]
npm ERR! stack:
npm ERR! ‘Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’’,
npm ERR! errno: -13,
npm ERR! code: ‘EACCES’,
npm ERR! syscall: ‘access’,
npm ERR! path: ‘/usr/local/lib/node_modules’ }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!

1 Like

Never mind I got it working, version 10.21.0 didn’t work for me, instead version 12.22.0. I hope this is helpful for anyone who runs into this type of challenge.

1 Like

Hello,

For some reason I am not compiling, I keep getting this error msg. Let me know best approach to fix this. Thanks a millionđŸ€©
Compiling your contracts


Error: EACCES: permission denied, mkdir ‘/Users/hermevillaparedes/Library/Preferences/truffle-nodejs/compilers’
at Object.mkdirSync (fs.js:779:3)
at new Cache (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/Cache.js:15:1)
at new VersionRange (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/loadingStrategies/VersionRange.js:41:1)
at CompilerSupplier. (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/index.js:59:1)
at Generator.next ()
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/index.js:8:1
at new Promise ()
at exports.modules.147922.__awaiter (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/index.js:4:1)
at CompilerSupplier.load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/compilerSupplier/index.js:41:1)
at Object. (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/index.js:121:27)
at Generator.next ()
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/index.js:7:1
at new Promise ()
at exports.modules.4273.__awaiter (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/index.js:3:1)
at Object.sourcesWithDependencies (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/index.js:103:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/dist/index.js:95:1
Truffle v5.4.29 (core: 5.4.29)
Node v12.0.0

The error refers to trying to create a folder without the administrator privilege’s , if you are using Powershell or windows prompt (cmd), try open it first with “run as administrator”.

Carlos Z

1 Like

Hi Everyone,

When I try to install Truffle, I get this series of Error Messages from PowerShell.

Seems to be indicating that the error is with the Microsoft VSC folder, specifically that it’s missing the C++ workload.

As seen below, I have VSC 2022 installed including the C++ workload that the terminal says I’m missing. The picture also indicates that it should be saved in the C:/Program Files (x86)\Microsoft Visual Studio\2022\BuildTools folder.

I have re installed the VSC and the workload twice and they don’t appear in the file that the VSC installer indicates.

Seems like the installer is looking for some files that should be in there but aren’t, even though I’m ceratin they should be because that’s where I installed the VSC workloads to.

I have tried installing with and without using --force. I have tried using version 16 of node js and also have tried downgrading to node js version 14 and nothing has worked.

If anyone can help me figure out what I’m doing wrong and how to get the program installed, I would be forever grateful.

Additional pictures coming in separate posts because apparently new users can only put one per post?

Hey everybody, I really need some help trying to install truffle on mac big sur OS. I keep getting this error every time I try to install truffle. My node is updated to the 16.13.2 version, and I have tried with other versions, and have tried uninstalling and reinstalling. I have tried using sudo commands and lots of other things I found online, but still no luck. Please help asap! Thanks in advance!

1 Like

Hey @diehlca17, hope you are well.

Those warning messages are related to the modules that truffle use internally, their just warning messages that are not fatal errors nor will stop your progress, you should be able to move forward with the installation or using truffle.

A suggestion will be to downgrade NodeJs to version 12, you might (or not) encounter issues with the version 16, while the version 12 give less issues with packages like truffle or hardhat.

Carlos Z

@thecil thanks, but I am using a mac not windows, kindly let me know how to best fix this. Wondering if it has anything to do with the type of shells on mac bash vs zsh? Look forward to your reply.

1 Like

There are 2 methods on this page, it might be that you just need to trigger your commands has administrator (which involve the keyword sudo at the start of your command line).

Let me know if they work for you :nerd_face:

Carlos Z

Hey I m having truffle installation problem for last 2 days I install truffle on my computer dat is working but on my laptop it is showing error
First it say to install Python, then visual studio build tools now I m not getting the error

dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path C:\Users\HP\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\@trufflesuite\bigint-buffer
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.2 found at "C:\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version was set from command line or npm config
npm ERR! gyp ERR! find VS - looking for Visual Studio version 2015
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS checking VS2019 (16.11.32106.194) found at:
npm ERR! gyp ERR! find VS "D:\New folder"
npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"
npm ERR! gyp ERR! find VS - found VC++ toolset: v142
npm ERR! gyp ERR! find VS - found Windows SDK: 10.0.19041.0
npm ERR! gyp ERR! find VS - msvs_version does not match this version
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS valid versions for msvs_version:
npm ERR! gyp ERR! find VS - "2019"
npm ERR! gyp ERR! find VS - "D:\New folder"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:404:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! System Windows_NT 10.0.10240
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\HP\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\@trufflesuite\bigint-buffer
npm ERR! gyp ERR! node -v v16.13.2
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\HP\AppData\Local\npm-cache\_logs\2022-01-27T06_07_10_995Z-debug.log
PS C:\Users\HP\Desktop>
1 Like

Try installing:

After those 2, you should be able to install truffle.

Hope this helps :nerd_face:

Carlos Z

yeahh after that i set the execution policy unrestricted 
 then it shows truffe version
bdw thnkss so much sir !

Hey @thecil thanks so much! I sorted the issues with adm privileges/sudo command, but still getting below msgs when trying to compile, do you think is the truffle version? Thanks!

1 Like