Learning Truffle

Hi @inzhagey

Please push your code to github and share the repo.

https://github.com/Tagi17/truffle.git

Capture 2
Capture

Is this anything to worry about? I was still able to run truffle but I saw that on Filipā€™s demonstration he did not have anything that resembled these messages.

Hi @DJaySplash

The warnings you get are related to deprecated dependencies that truffle is using for its installation. All good no need to do anything.

Cheers,
Dani

Hi @inzhagey

Please upload the whole truffle project not just the files.
Also donā€™t change your file names (truffleconfig should be truffle-config).
I need to have the exact same repo you have in your machine as the issue is somewhere in your code and we need to be able to replicate it.

https://github.com/Tagi17/TokenProject.git

Hi @inzhagey

I cloned your repo and I was able to migrate it correctly.

Run truffle -v and write here the version of Truffle installed.
Also try to update truffle npm i truffle.

  • Make sure you have fully close your local blockchain;
  • Run truffle develop;
  • Run truffle migrate --reset;

Screenshot 2021-05-06 at 15.24.45

The configuration is correct so it has to be something in your machine.

Make sure you are compiling the right project (from your terminal you have to be inside the root folder of your project ā€œTokenProjectā€).

If you keep getting the same error, other than you truffle version please cd into the root folder of your project, then run ls and screenshot the results.
Then run cd contracts, ls and send me the screenshot.

Let me know,
Dani

It says Truffle v5.3.0 and it worked, I think it was an update issue. Thank you for your help

Even though it was previously running and working, thereā€™s still a red line on the pragma solidity version
and i think it may be interfering with the compile

Screen Shot 2021-05-08 at 6.32.16 PM
Screen Shot 2021-05-08 at 6.32.20 PM

1 Like

You might have typed wrong imports instead of import, apparently is not in the contract, so you can check in your migration or test files. Some where, you type it incorrectly.

Carlos Z

I cant find imports anywhere
I saw that I misspelled ERC20.sol and the /ā€¦/ā€¦/utils/Context.sol after import, but I fixed both of them too and I exited and started truffle develop again and got the same error. What do you mean by test files?

1 Like

Could you please upload it to your github repo? Your contract looks ok, have you modify any of the openzeppelin contract? Those should never be modified.

Anyway I want to try to replicate the error myself, maybe I could find something that is not showed in your screenshots :face_with_monocle:

Carlos Z

https://github.com/Tagi17/TokenProject.git

1 Like

Hi All,

A question about the difference between calls and transactions.

  • When writing code in Solidity, the compiler allows me to declare an external function that returns a value.
  • However if I invoke the same function from the console in truffle develop, a transaction is generated, I can see all transaction details but I donā€™t have a chance to see the returned value.
  • Are returned values simply ignored by the EVM and never returned anywhere when invoked from a transaction? As a developer, is it usual practice not to use returned values with external functions?

I got confused because the Remix IDE shows functions returned values under ā€œdecoded outputā€ even in the case of a transaction invocation.

Thanks!

Matt

Thanks @dan-i! I will follow your instructions. Good to know that it works on your machine

1 Like

So the only error that i found was on the minting function that is beign called from ther ERC20Capped contract instead the ERC20.

So i just change your token contract a little bit and its compile great for me:

pragma solidity >=0.6.0 < 0.8.3;
// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

contract MyToken is ERC20Capped {
    constructor () ERC20("Penny", "PNY" ) ERC20Capped(100000){
        ERC20._mint(msg.sender, 1000);
    }
}

image

Carlos Z

1 Like

I changed the minting function to the one you posted, however, im still getting this in terminal: Compiling your contractsā€¦

TypeError: Cannot read property ā€˜importsā€™ of undefined
at Object. (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
at Generator.next ()
at fulfilled (/usr/local/lib/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)

  • Fetching solc version list from solc-bin. Attempt #1

and these errors Screen Shot 2021-05-11 at 3.37.59 PM

I noticed that Filips ERC20Capped.sol file had

function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        require(!paused(), "ERC20Pausable: token transfer while paused");
    }

which is not my ERC20Capped.sol:
/

/ SPDX-License-Identifier: MIT

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 immutable private _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);
    }
}

, but itā€™s in my ERC20Pausable.sol contract

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../../../security/Pausable.sol";

/**
 * @dev ERC20 token with pausable token transfers, minting and burning.
 *
 * Useful for scenarios such as preventing trades until the end of an evaluation
 * period, or having an emergency switch for freezing all token transfers in the
 * event of a large bug.
 */
abstract contract ERC20Pausable is ERC20, Pausable {
    /**
     * @dev See {ERC20-_beforeTokenTransfer}.
     *
     * Requirements:
     *
     * - the contract must not be paused.
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        require(!paused(), "ERC20Pausable: token transfer while paused");
    }

}
Screen Shot 2021-05-11 at 9.57.58 PM
So I tried to write

contract MyToken is  ERC20Pausable {
    constructor () ERC20("Penny", "PNY" ) ERC20Capped(100000){
        ERC20._mint(msg.sender, 1000);
    }
}

and im still getting that error. I updated my github btw.

Hi @inzhagey

Follow the steps below and let me know:

  • Delete the node_modules folder completely.
  • Run npm i @openzeppelin/contracts
  • Try again to migrate the project truffle migrate --reset

If that did not fix:

  • Run node -v and truffle -v and write here the versions of both

Cheers,
Dani

Um, I got a bunch of warnings
Screen Shot 2021-05-12 at 5.58.25 PM

Screen Shot 2021-05-12 at 5.57.59 PM

node -v and truffle -v: v14.15.4