Truffle Introduction

i try deploying the contract i made but it giving me an error pls what should i do

pragma solidity 0.7.5;
contract BSShareQ{


    mapping(address => uint256)balance;
    mapping(uint256 => uint256) public referralreward;
    mapping(address => uint256) public userreferralbonus;


    address public owner;
    address payable public projectFee;
    address payable  public withdrawalFEE;
    address payable public supportFEe;

    uint256 public minimiuminvestedAmount;
    uint256 public numberinvestors;
    uint256 public deadline;
    uint256 public goal;
 

    uint256 public total_invested;
    uint256 public total_withdrawn;
    uint256 public total_investors;
    uint256 public total_referral_bonus;

    

    constructor(){
        owner = msg.sender;
        minimiuminvestedAmount = 6300000000000000;
        projectFee = msg.sender;
        withdrawalFEE = msg.sender;
        supportFEe = msg.sender;
    }


    function deposit() public payable returns(uint256){
        require(msg.value >= minimiuminvestedAmount);
     balance[msg.sender] += msg.value;

     return balance[msg.sender];   
     if(balance[msg.sender] == 0){


            numberinvestors++;
        }
        balance[msg.sender] += msg.value;
         
      supportFEe.transfer(msg.value * 5 / 100);
        projectFee.transfer(msg.value * 3 / 100);
    }

    
    function withdraw(uint256 amount) public returns(uint256){
        require(balance[msg.sender] >=  amount);
        require(block.timestamp >= block.timestamp + 2592000 seconds && msg.value = msg.value * 140 / 100);
        balance[msg.sender] -= amount;
        msg.sender.transfer(amount);
        balance[msg.sender] = 0;
    }


    function getbalance() public view returns (uint256){
        return address(this).balance;
    }
    
    function transfer(address reciever, uint256 amount) public {
        require(balance[msg.sender] >= amount);
        require(msg.sender != reciever);
        require(owner == msg.sender );


    uint256 previousSenderBalance = balance[msg.sender];
    _transfer(msg.sender , reciever,amount);

    assert(balance[msg.sender] == previousSenderBalance - amount);
    }
    function _transfer(address from, address to, uint256 amount) private{
        balance[from] -= amount;
        balance[to] += amount;

    }
}`Preformatted text`

Hi guys, I would like to know how you solved the issue below after the truffle compile command is used to compile the very first program shown in the video: https://academy.ivanontech.com/lessons/truffle-hello-world

Source file requires different compiler version (current compiler is
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are 
considered to be strictly less than the released version

Notice that in this program the compiler solidity 0.8.0 is used, so I am using the same compiler that I verified with the command solc --version, that gave me the output below:

$$ solc, the solidity compiler commandline interface
Version: 0.8.0+commit.c7dfd78e.Darwin.appleclang

and changed in the truffle-config.js file too the version of my compiler

compilers: {
    solc: {
      version: "0.8.0",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

I also followed what is show in the contents of this article (https://medium.com/blockchangers/how-to-fix-your-truffle-and-solidity-versioning-with-npx-from-npm-51b5fcb0825f) but nothing changed from my end.

Any advise would be highly appreciated it.

1 Like

hey @cgironda change the compiler verion in the truffle config to whatever the veriosn you sepecify in your contracts. try close vs code and your terminal and reopen if its your first time

Thanks for the advise @mcgrane5 but after using the truffle version command I obtain the output below without any other change:

Truffle v5.4.10 (core: 5.4.10)
Solidity - 0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.5.2

Until here everything seems to be working, however the issue below still appears:

Source file requires different compiler version (current compiler is 
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are 
considered to be strictly less than the released version

https://ibb.co/wr5MZGs

1 Like

Yeah strange im now bot sure wjy that would be the case. You could try reinstalling truffle thats works sometimes for people. @thecil have you any ideas on how to fox this error

Hi @mcgrane5 thank you for your time checking what I wrote here. I erased everything to start from scratch. So I reinstalled Truffle and followed the same process:

After using the truffle version command I got the output below:

Truffle v5.4.11 (core: 5.4.11)
Solidity v0.5.16 (solc-js)
Node v14.17.6
Web3.js v1.5.2

So after using the commands npm init and Truffle init I changed the version of the compiler in the truffle-config.js file as shown below:

compilers: {
    solc: {
      version: "0.8.0",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

Then using the truffle version command again I obtained:

Truffle v5.4.11 (core: 5.4.11)
Solidity - 0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.5.2

Finally, after using the truffle compile command I obtained the output below:

Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
> Compiling ./contracts/Migrations.sol
> Artifacts written to /Users/home/Documents/projects/IvanOnTech/ESC_201/hello_world/build/contracts
> Compiled successfully using:
   - solc: 0.8.0+commit.c7dfd78e.Emscripten.clang

However, the message below persists when I open my editor and hover the mouse over the line code: pragma solidity 0.8.0;

Source file requires different compiler version (current compiler is
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are 
considered to be strictly less than the released version

Apparently I am using the compiler version 0.8.0 but according to the message above I am not.

On the other hand, when the line of code pragma solidity 0.8.0; is changed by pragma solidity ^0.8.0; the message below appears when I hover the mouse over the word pragma:

SPDX license identifier not provided in source file. Before publishing, consider adding a
comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file.
Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. 
Please see https://spdx.org for more information.

I was wondering if the syntax plays some role here, or if something else is happening.

Did you have guys (@mcgrane5, @thecil ) a similar problem before?.
Any help would be appreciate it!

Hi guys, as an update to this issue:

I verified that the solidity compiler version used globally (using the flag -g) by truffle:

npm -g ls | grep solc
├─┬ [email protected]

At the beginning, I used the solc-select use 0.8.0 command to make this switch:

Switched global version to 0.8.0

The compilation after using the truffle compile command is giving me:

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Artifacts written to /Users/home/Documents/projects/IvanOnTech/ESC_201/hello_world/build/contracts
> Compiled successfully using:
   - solc: 0.8.0+commit.c7dfd78e.Emscripten.clang

Since I am compiling locally, I don’t understand why the global compiler is triggered in my editor.

By specifying the compiler version in my editor, I couldn’t solve the issue either.
So I still having this https://ibb.co/wr5MZGs

1 Like

Hey @cgironda. Ohhhh ok i see. You dont need to worry at all about the ted solidity error. Thats fine as long as you can run truffle migrate or truffle compile successfully you have done then thats fine. The only reason that error shows is because you are specifying to use a diff solidity version that that of what you installed.

Hi @mcgrane5, thanks for your comment. Yeah, I notice that but I can not configure it. I can run truffle compile but not truffle migrate.

I always get the error below and I can not find how to overcome this issue either.

throw new Error("Could not find artifacts for " + import_path +
" from any sources");

Any idea?. Thanks!

1 Like

Hey @cgironda, hope you are ok.

Could you please share your migration file in the following way?

Carlos Z

Hi @thecil, thanks for your reply.

Actually, there is nothing else to show than what is described in my second post. Every step was followed from the video: https://academy.ivanontech.com/lessons/truffle-hello-world.

Is that what you asked for?

Hi @mcgrane5, I haven’t seen that command yet. What is it for?

hey @cgironda do not mind that last comment i was mstaken

@mcgrane5 anyways thank you!

Hello.

I had have a problem with compiling on my PC. I followed the same steps as in the videos. When I try to compile a simple helloworld contract I get the following output but nothing more.

C:\Users\Admin\Webdev\solidity\eth201project>truffle compile
Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1

After that I got no further feedback. I then just closed VS Code. If I try to compile now I get the following message.

C:\Users\Admin\Webdev\solidity>truffle compile
Could not find suitable configuration file.
Truffle v5.4.29 (core: 5.4.29)
Node v12.0.0

I use solidity version 0.8.0 in both contract and truffle config file. But I also still get this error message.

[{
	"resource": "/c:/Users/Admin/Webdev/solidity/eth201project/contracts/hello.sol",
	"owner": "_generated_diagnostic_collection_name_#1",
	"severity": 8,
	"message": "Source file requires different compiler version (current compiler is 0.8.11+commit.d7f03943.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version",
	"startLineNumber": 2,
	"startColumn": 1,
	"endLineNumber": 2,
	"endColumn": 23
}]

Thanks in advance for your help

Edit: I uninstalled truffle and wnated to reinstall it. Now I get the following error messages wehn I try to install:

C:\Users\Admin>npm install -g truffle
npm does not support Node.js v12.0.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\lib\utils\log-file.js:48
    maxLogsPerFile = 50_000,
                     ^^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:703:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\lib\npm.js:15:17)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
1 Like

Hello sir , I just install truffle and just do a small contract compile it it shows error

"ParserError: Expected ‘{’ but got ‘return’
–> project:/contracts/nft.sol:4:36:
|
4 | function nft () public pure return(string memory) {
| ^^^^^^
"

pragma solidity 0.8.0;
contract nft {  

    function nft ()  public   pure return(string memory) {

    return "nft ";
    }
}

What worked for me:

if you try running this command “npm cache clean -f” and it doesn’t work,

on your windows machine(mine is windows 10) access the “npm” and “npm-cache” folders in this location “~\AppData\Roaming”

delete these two folders “npm” and “npm-cache”.

go to your windows search bar and search for Node, right click to open file location, run the uninstaller to uninstall NodeJs.

then visit nodejs.org and download and install node again, if you’ve already downloaded it, visit the folder where you downloaded it to reinstall it.

after installation, check your version of npm by typing “npm -v” on your command terminal to see the new updated version of npm installed on your machine.

now you’re all set, Happy coding.

SOURCE: https://stackoverflow.com/questions/56805007/npm-warn-npm-does-not-support-node-js-v12-4-0

Hope this helps, if not, let me know to find another probable solution :nerd_face:

Carlos Z

1 Like

Should be returns on the function header, the keyword return is reserved to the function body.

Carlos Z

@thecil Thanks for your help.
This seemed to help. This time I also got stuck at this part.

C:\Users\Admin\Webdev\solidity\eth201project>truffle compile
Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1

But after some more seconds a simple test contract compiled successfully.

1 Like

Another problem I encountered was the following. I also had a different reslut than in the video concerning Big Number.

truffle(develop)> result.toNumber()
Thrown:
evalmachine.<anonymous>:0
result.toNumber()
^

ReferenceError: result is not defined
    at evalmachine.<anonymous>:0:1
    at sigintHandlersWrap (vm.js:276:15)
    at Script.runInContext (vm.js:131:14)
    at runScript (C:\Users\Admin\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:364:1)
    at Console.interpret (C:\Users\Admin\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:379:1)
    at bound (domain.js:415:14)
    at REPLServer.runBound [as eval] (domain.js:428:12)
    at REPLServer.onLine (repl.js:665:10)
    at REPLServer.emit (events.js:196:13)
    at REPLServer.EventEmitter.emit (domain.js:471:20)