Learning Truffle

if you have done both of these, then please try and execute “truffle develop”, i wonder is this error happening because your trying to use “truffle console”. let me know anyway ill get this solved for u

hello, thanks it work now, I repeat the process from the start, and change my contract version between 0.7.0 to 0.9.0. and also re-run the Truffle init on my Terminal.

1 Like

brilliant gret that you got it working. on to the next now keep it up.

When I type “truffle migrate --reset” in the visual studio terminal I get this error:
$ truffle migrate --reset
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module ‘C:\Users\micha\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js’
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:
15)
at Function.Module.load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run

main:81:12)
at node:internal/main/run_main_module:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []
}
How do I fix this?
Thanks, Michael

1 Like

this seems to be a problem with your installation of truffle. can you type the following into your terminal

truffle version

what happens if you run this. you should be getting an output similar to this

Truffle v5.4.19 (core: 5.4.19)
Solidity - 0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.5.3

can you confirm that this is indeed what you get from running that command

1 Like

.This is the output from the Visual Studio terminal:
$ truffle version
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module ‘C:\Users\micha\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js’
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:
15)
at Function.Module.load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run
main:77:12)
at node:internal/main/run_main_module:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []
}

1 Like

yeah so you didnt install truffle correctly. ok this may be tricky but your going to have to uninstall it and redo it. so this is the steps i would take.

here you should unistall truffle with npm unistall -g truffle. when its done try reinstalling it with npm just as you did before and again run truffle version and see if you get the correct output this time

When I type npm uninstall -g truffle its says this:
$ npm uninstall -g truffle

up to date, audited 1 package in 596ms

found 0 vulnerabilities

1 Like

ok now install truffle again. specifically type

npm install [email protected] -g

When I run npm install -g truffle I get his response:
npm WARN deprecated [email protected]: This package is broken and no longer maintained. ‘mkdirp’ itself supports promises now, please switch to that.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by @ipld/dag-cbor and multiformats
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated @nodefactory/[email protected]: Package is deprecated in favour of @chainsafe/filsnap-adapter
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
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.)
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by @ipld/dag-pb and multiformats
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
npm WARN deprecated [email protected]: This module has been superseded by the multiformats module
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path C:\Users\micha\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 not set from command line or npm config
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 “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools”
npm ERR! gyp ERR! find VS - found “Visual Studio C++ core features”
npm ERR! gyp ERR! find VS - missing any VC++ toolset
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 **************************************************************
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:122:47)
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384: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:406:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:520:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! System Windows_NT 10.0.18363
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\micha\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules@trufflesuite\bigint-buffer
npm ERR! gyp ERR! node -v v16.14.0
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\micha\AppData\Local\npm-cache_logs\2022-03-14T16_23_39_556Z-debug-0.log

then try truffle verion again when its done

Thank you it is now working but I have a new problem.
$ truffle migrate
Could not find suitable configuration file.
Truffle v5.4.19 (core: 5.4.19)
Node v16.14.0
I am stuck on this video: https://academy.moralis.io/lessons/web3-js-start-coding
How do I get the result that the teacher gets at 05:04?
Thanks

1 Like

perfect yes you have succesfully installed truffle now. dont worry about all those messages above there just wanrning and are expected when you install npm packages. as for ypur new error, you need to execute

truffle init

first before you can type truffle migrate --reset or anything.

I have done truffle init now when I try truffle migrate it says this:

Compiling your contracts…

Compiling .\contracts\Migrations.sol
Artifacts written to C:\Users\micha\OneDrive\Desktop\Ivan On Tech\NFT Marketplace\build\contracts
Compiled successfully using:

  • solc: 0.8.10+commit.fc410830.Emscripten.clang

Something went wrong while attempting to connect to the network at http://127.0.0.1:7545. Check your network configuration.

Could not connect to your Ethereum client with the following parameters:

  • host > 127.0.0.1
  • port > 7545
  • network_id > 5777
    Please check that your Ethereum client:
  • is running
  • is accepting RPC connections (i.e., “–rpc” or “–http” option is used in geth)
  • is accessible over the network
  • is properly configured in your Truffle configuration file (truffle-config.js)
    Truffle v5.4.19 (core: 5.4.19)
    Node v16.14.0
1 Like

ok can you try running

truffle develop

and then after a few when this command runs then try

truffle compile

I love you thank you so much I have been stuck on this and it has stopped me from doing actual coding for hours.
Truffle migrate now works

1 Like

no worries at all glad i could help. a little motivation now, youll be glad to know that this step is the hardest for first time users with truffle because if something goes wrong theres so many things that could be the cause of the issue but now that you have truffle working the only thing that will stop you is actual erors in your code which are usuall always easy to debug with a bit of time. anyway happy coding and see you around the forums

Hello all can someone help me out with this error message.

ompiling your contracts...
===========================
> Compiling ./contracts/token.sol

TypeError: Immutable variables cannot be read during contract creation time, which means they cannot be read in the constructor or any function or modifier called from it.
  --> project:/node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol:27:16:
   |
27 |         return _cap;
   |                ^^^^

Compilation failed. See above.
truffle(develop)> 

This is the contract from @openzeppelin

pragma solidity ^0.8.0;

import "../ERC20.sol";

/**
 * @dev Extension of {ERC20} that adds a cap to the supply of tokens.
 */
abstract contract ERC20Capped is ERC20 {
    uint256 private immutable _cap;

    /**
     * @dev Sets the value of the `cap`. This value is immutable, it can only be
     * set once during construction.
     */
    constructor(uint256 cap_) {
        require(cap_ > 0, "ERC20Capped: cap is 0");
        _cap = cap_ ;
    }

    /**
     * @dev Returns the cap on the token's total supply.
     */
    function cap() public view virtual returns (uint256) {
        return _cap;
    }

    /**
     * @dev See {ERC20-_mint}.
     */
    function _mint(address account, uint256 amount) internal virtual override {
        require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
        super._mint(account, amount);
    }
}
 or paste code here
1 Like

hey i think its because cap is immutable in ERC20Capped thus it cannot be read during the mint process in the constructor. It was done on purpose to lower gas costs. are you trying to mint tokens in the constructor of any of your other files. if so this is why the error is showing

Thanks, I wanted to compile the contract and test, to see if it works. what should I amend to make it compile?

1 Like