Building our ERC1155 Token Discussion

Hello,

Im running into this error when trying to truffle compile

ParserError: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead.
  --> project:/contracts/marketplace.sol:18:34:
   |
18 |     function () external payable {
   |                                  ^

any help would be appreciated, thank you.

Hello Javier, greetings

With changes in Solidity regarding the declaration of fallback functions in a contract, in this case, you have to change the declaration to:

fallback () external payable {

Hope that resolves the error
With kind regards

1 Like

Hi @alp257, it kinda did , but then, this happens when I run Truffle compile,

Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
 --> project:/contracts/marketplace.sol:5:1:
  |
5 | contract Marketplace {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: The payable fallback function is defined here.
  --> project:/contracts/marketplace.sol:18:5:
   |
18 |     fallback () external payable {
   |     ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
 --> project:/contracts/Migrations.sol:7:3:
  |
7 |   constructor() public {
  |   ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
  --> project:/contracts/marketplace.sol:10:5:
   |
10 |     constructor(IERC1155 token) public {
   |     ^ (Relevant source part starts here and spans across multiple lines).


TypeError: Overriding function is missing "override" specifier.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Trying to override non-virtual function. Did you forget to add "virtual"?
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overriding function is here:
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.
 --> project:/contracts/token.sol:6:1:
  |
6 | contract GameToken is ERC1155, ERC1155Mintable {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155":
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155Mintable":
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Type address is not implicitly convertible to expected type uint256.
  --> project:/contracts/marketplace.sol:23:9:
   |
23 |         uint256 weiAmount = msg.sender;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

,TypeError: Member "add" not found or not visible after argument-dependent lookup in uint256.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:58:33:
   |
58 |             balances[_id][to] = quantity.add(balances[_id][to]);
   |                                 ^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

I know the course is outdated, I think I might not have the proper dependencies or packages installed. Let me know what you think, Thanks again.

$ truffle version
Truffle v5.4.18 (core: 5.4.18)
Solidity - >=0.4.22 <0.9.0 (solc-js)
Node v16.13.0
Web3.js v1.5.3

$ npm --version
8.1.0

Hello @Javier_Flores,

To better understand and for efficiency, I have to look at your code. do you have a repository at Github for that?

I will upload it to github, so you take a better look. The course got quite confusing when Filip did the file setup at the beginning , Changing folder names and force clone. I had 2 migration.sol file, etc. but will get that up Asap. Thank again.

1 Like

@alp257
https://github.com/TotalingArc/erc1155-game-token

hereā€™s What I uploaded, with the exception of node modules. I really think it might be the files are organized in folder, maybe?

How does one Upload node_modules folder up on GitHub, every time I try says file to large.

Hello @Javier_Flores,
Thank you for uploading your code. Currently, checking the code and still need to try it. With a quick look, some of the errors are a bit strange they are coming from the library dependencies (i.e. ERC1155Mintable).

Hereā€™s one you can correct (in the marketplace.sol contract, line 23):

...
        uint256 weiAmount = msg.sender;
...

It should be, to get the value sent by the caller:

...
        uint256 weiAmount = msg.value;
...

With kind regards

1 Like

Hello @alp257,
Thank you for your help, I correct the .value issue, it clear the error in the contract. But I am still getting the compilation error. Iā€™m I missing dependencies or maybe I donā€™t have files in correct folders? Thank again for your time.

Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
 --> project:/contracts/marketplace.sol:5:1:
  |
5 | contract Marketplace {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: The payable fallback function is defined here.
  --> project:/contracts/marketplace.sol:18:5:
   |
18 |     fallback () external payable {
   |     ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
 --> project:/contracts/Migrations.sol:7:3:
  |
7 |   constructor() public {
  |   ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
  --> project:/contracts/marketplace.sol:10:5:
   |
10 |     constructor(IERC1155 token) public {
   |     ^ (Relevant source part starts here and spans across multiple lines).


TypeError: Overriding function is missing "override" specifier.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Trying to override non-virtual function. Did you forget to add "virtual"?
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overriding function is here:
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.
 --> project:/contracts/token.sol:6:1:
  |
6 | contract GameToken is ERC1155 , ERC1155Mintable {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155":
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155Mintable":
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Member "add" not found or not visible after argument-dependent lookup in uint256.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:58:33:
   |
58 |             balances[_id][to] = quantity.add(balances[_id][to]);
   |                                 ^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

Also for some reason my build folder has nothing in it. I thought it should have json files.?

Hello @Javier_Flores,

I suppose itā€™s worth a try to use the same structure as what Filip did (after cloning the repo he mentioned). It might have some dependencies with the path of the library. Placing the ERC1155 contracts in a ā€˜libā€™ folder in the same directory where the ā€˜contractsā€™ folder, and other stuff (i.e. .babelrc, .soliumignore, etc). Then, importing the ERC1155 contracts like this (in the Token contract):

import "../lib/ERC1155.sol";
import "../lib/ERC1155Mintable.sol";

Also, adjust the import statement in the Marketplace contract.
Hope this resolves the problem.
With kind regards

Hi ,@alp257
Yea I dont I can proceed the course until I solve this error, I did what you suggested but still receive error in compilation.

![image|690x388](upload://4eY3gAvEGHdU2MsvW442ubsy6iv.png) 
Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
 --> project:/contracts/marketplace.sol:5:1:
  |
5 | contract Marketplace {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: The payable fallback function is defined here.
  --> project:/contracts/marketplace.sol:18:5:
   |
18 |     fallback () external payable {
   |     ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
 --> project:/contracts/Migrations.sol:7:3:
  |
7 |   constructor() public {
  |   ^ (Relevant source part starts here and spans across multiple lines).

,Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
  --> project:/contracts/marketplace.sol:10:5:
   |
10 |     constructor(IERC1155 token) public {
   |     ^ (Relevant source part starts here and spans across multiple lines).


TypeError: Overriding function is missing "override" specifier.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Trying to override non-virtual function. Did you forget to add "virtual"?
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overriding function is here:
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.  
 --> project:/contracts/token.sol:6:1:
  |
6 | contract GameToken is ERC1155 , ERC1155Mintable {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155":
  --> project:/erc-1155/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155Mintable":
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:24:5:
   |
24 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Member "add" not found or not visible after argument-dependent lookup in uint256.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:58:33:
   |
58 |             balances[_id][to] = quantity.add(balances[_id][to]);
   |                                 ^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

Im still confused as to why there are no json files in my build folder. Im sending a pic of file explorer.

Hello @Javier_Flores,

Upon further analysis, ERC1155.sol needs to be modified for Solidity 0.6 and above (I assume you are already compiling using a higher version of Solidity than what Filip used 2 years ago).

In ERC1155.sol, modify the function declaration of supportsInterface (adding a few keywords - override and virtual),

...
    function supportsInterface(bytes4 _interfaceId)
    public
    view
    override
    virtual
    returns (bool) {
         if (_interfaceId == INTERFACE_SIGNATURE_ERC165 ||
             _interfaceId == INTERFACE_SIGNATURE_ERC1155) {
            return true;
         }

         return false;
    }
...

Then, also modify ERC1155Mintable.sol (just adding ā€˜overrideā€™ will be enough)

...
    function supportsInterface(bytes4 _interfaceId)
    public
    view
    override
    returns (bool) {
        if (_interfaceId == INTERFACE_SIGNATURE_URI) {
            return true;
        } else {
            return super.supportsInterface(_interfaceId);
        }
    }
...

When the compilation is successful, it should then produce the json files in the build folder.
Hope that resolves the errors.
With kind regards

@alp257, hope your well,
It did solve some errors, but the quantity. add still there.

ypeError: Member "add" not found or not visible after argument-dependent lookup in uint256.
  --> project:/erc-1155/Lib/ERC1155Mintable.sol:58:33:
   |
58 |             balances[_id][to] = quantity.add(balances[_id][to]);
   |                                 ^^^^^^^^^^^^

Should I just start over using the current version of solidity contracts to complete this course?
I really dont understand what I am doing wrong, As soon as we began the Mintable section my contracts failed.

@Javier_Flores, greetings

Thank you, hope your well too.
I havenā€™t dig deep, I guess something to do with the scope of a library within a contract and then you call a function from that library within a derived contract.

Havenā€™t tried it but making it explicit to use ā€˜SafeMathā€™ with uint256 data type within ERC1155Mintable.sol will do the trick.

...
contract ERC1155Mintable is ERC1155 {

    **using SafeMath for uint256;**

    bytes4 constant private INTERFACE_SIGNATURE_URI = 0x0e89341c;
...

And, if it still doesnā€™t work, import ā€˜SafeMathā€™ as well in ERC1155Mintable.sol

import "./SafeMath.sol";

You can start over if time permits. (I used Solidity 0.5 for all contracts when I took the course, canā€™t remember exactly I think Filip used Solidity 0.4 when he used the ERC1155 contracts so changes need to be done, itā€™s not your fault). If not, learning these changes is worth to know. These are anyway changes for Solidity 0.6 and up. As you create youā€™re own contract in the future you will eventually use 0.8 and above.

With kind regards

@alp257 , Hi

I tried what you suggested , its reading this error again but new error in code line

,Warning: 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.
--> project:/contracts/token.sol

,Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
 --> project:/contracts/marketplace.sol:5:1:
  |
5 | contract Marketplace {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: The payable fallback function is defined here.
  --> project:/contracts/marketplace.sol:18:5:
   |
18 |     fallback () external payable {
   |     ^ (Relevant source part starts here and spans across multiple lines).


TypeError: Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.
 --> project:/contracts/token.sol:6:1:
  |
6 | contract GameToken is ERC1155, ERC1155Mintable {
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155":
  --> project:/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155Mintable":
  --> project:/Lib/ERC1155Mintable.sol:27:5:
   |
27 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Member "isContract" not found or not visible after argument-dependent lookup in address.
  --> project:/Lib/ERC1155Mintable.sol:69:17:
   |
69 |             if (to.isContract()) {
   |                 ^^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

Yea I really donā€™t have time restarting the build , I really want to start the EJIN blockchain course after this. Its getting a little tight over the holidays, Id really hate to pause my education, everything moves so fast in this space. But I really appreciate your time for helping ,thank you.

1 Like

@alp257, Hello

Ive been looking further, Im getting this now,


jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ truffle compile

Compiling your contracts...
===========================
> Compiling .\Lib\Address.sol
> Compiling .\Lib\ERC1155.sol
> Compiling .\Lib\ERC1155Mintable.sol
> Compiling .\Lib\ERC165.sol
> Compiling .\Lib\IERC1155.sol
> Compiling .\Lib\IERC1155TokenReceiver.sol
> Compiling .\Lib\SafeMath.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\marketplace.sol
> Compiling .\contracts\token.sol

project:/Lib/ERC1155Mintable.sol:30:5: ParserError: Expected '{' but got reserved keyword 'override'
    override
    ^------^
,project:/contracts/marketplace.sol:18:14: ParserError: Expected identifier but got '('
    fallback () external payable {
             ^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

lemme know what you think, thanks

Hi @Javier_Flores,

Glad to help. I agree, things are evolving in this space amazingly. Personally, I try to squeeze in at least a little learning each day to continue moving forward.

Let me correct that code I gave earlier (inside ERC1155.sol, my bad, just add ā€˜virtualā€™ with ā€˜supportsInterfaceā€™, since ERC165 is an interface and ERC1155 has the implementation):

...
    function supportsInterface(bytes4 _interfaceId)
    public
    view
    virtual
    returns (bool) {
         if (_interfaceId == INTERFACE_SIGNATURE_ERC165 ||
             _interfaceId == INTERFACE_SIGNATURE_ERC1155) {
            return true;
         }

         return false;
    }
...

To check the parse errors further, can you share the latest version of your ERC1155Mintable.sol and marketplace.sol?

With kind regards

@alp257 Hi

Here is my current state of contracts.

ERC1155Mintable.sol

pragma solidity >=0.4.22 <0.9.0;

import "./ERC1155.sol";
import "./SafeMath.sol";

/**
    @dev Mintable form of ERC1155
    Shows how easy it is to mint new items.
*/
contract ERC1155Mintable is ERC1155 {

    using SafeMath for uint256;

    bytes4 constant private INTERFACE_SIGNATURE_URI = 0x0e89341c;

    // id => creators
    mapping (uint256 => address) public creators;

    // A nonce to ensure we have a unique id each time we mint.
    uint256 public nonce;

    modifier creatorOnly(uint256 _id) {
        require(creators[_id] == msg.sender);
        _;
    }

    function supportsInterface(bytes4 _interfaceId)
    public
    view
    virtual
    returns (bool) {
        if (_interfaceId == INTERFACE_SIGNATURE_URI) {
            return true;
        } else {
            return super.supportsInterface(_interfaceId);
        }
    }

    // Creates a new token type and assings _initialSupply to minter
    function create(uint256 _initialSupply, string calldata _uri) external returns(uint256 _id) {

        _id = ++nonce;
        creators[_id] = msg.sender;
        balances[_id][msg.sender] = _initialSupply;

        // Transfer event with mint semantic
        emit TransferSingle(msg.sender, address(0x0), msg.sender, _id, _initialSupply);

        if (bytes(_uri).length > 0)
            emit URI(_uri, _id);
    }

    // Batch mint tokens. Assign directly to _to[].
    function mint(uint256 _id, address[] calldata _to, uint256[] calldata _quantities) external creatorOnly(_id) {

        for (uint256 i = 0; i < _to.length; ++i) {

            address to = _to[i];
            uint256 quantity = _quantities[i];

            // Grant the items to the caller
            balances[_id][to] = quantity.add(balances[_id][to]);

            // Emit the Transfer/Mint event.
            // the 0x0 source address implies a mint
            // It will also provide the circulating supply info.
            emit TransferSingle(msg.sender, address(0x0), to, _id, quantity);

            if (to.isContract()) {
                require(IERC1155TokenReceiver(to).onERC1155Received(msg.sender, msg.sender, _id, quantity, '') == ERC1155_RECEIVED, "Receiver contract did not accept the transfer.");
            }
        }
    }

    function setURI(string calldata _uri, uint256 _id) external creatorOnly(_id) {
        emit URI(_uri, _id);
    }
}

marketplace.sol

pragma solidity  >=0.4.22 <0.9.0;

import "../Lib/IERC1155.sol";

contract Marketplace {
    IERC1155 private _token;

    mapping (uint256 => uint256) price;

    constructor(IERC1155 token) public {
        require(address(token) != address(0));
        _token = token;
        price[1] = 100000000000000;
        price[2] = 200000000000000;
        price[3] = 300000000000000;
    }

    fallback () external payable {
        buyToken(0);
    }
    

    function buyToken(uint256 tokenId) public payable {
        uint256 weiAmount = msg.value;
        require (weiAmount >= price[tokenId] && price[tokenId] != 0);

        _token.safeTransferFrom(address(this), msg.sender, tokenId, 1, "");
    }
    function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
        return bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"));
    }
}

Yea, I think its that fallback() causing all the drama, I ran the truffle compile , now getting this;

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ truffle compile

Compiling your contracts...
===========================
> Compiling .\Lib\Address.sol
> Compiling .\Lib\ERC1155.sol
> Compiling .\Lib\ERC1155Mintable.sol      
> Compiling .\Lib\ERC165.sol
> Compiling .\Lib\IERC1155.sol
> Compiling .\Lib\IERC1155TokenReceiver.sol
> Compiling .\Lib\SafeMath.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\marketplace.sol
> Compiling .\contracts\token.sol

project:/contracts/marketplace.sol:18:14: ParserError: Expected identifier but got '('
    fallback () external payable {
             ^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ ver
bash: ver: command not found

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ version
bash: version: command not found

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ solidity ver
bash: solidity: command not found

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ solidity --ver
bash: solidity: command not found

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ -- version
bash: --: command not found

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ truffle compile

Compiling your contracts...
===========================
> Compiling .\Lib\Address.sol
> Compiling .\Lib\ERC1155.sol
> Compiling .\Lib\ERC1155Mintable.sol
> Compiling .\Lib\ERC165.sol
> Compiling .\Lib\IERC1155.sol
> Compiling .\Lib\IERC1155TokenReceiver.sol
> Compiling .\Lib\SafeMath.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\marketplace.sol
> Compiling .\contracts\token.sol

project:/contracts/marketplace.sol:18:14: ParserError: Expected identifier but got '('
    fallback () external payable {
             ^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

Hello @Javier_Flores,

Got it, presenting two approaches that should resolve the issues:

First, changing it back from

    fallback () external payable {
        buyToken(0);
    }

To:

    function () external payable {
        buyToken(0);
    }

If the compiler complains again about the use of ā€˜fallbackā€™ and/or ā€˜receiveā€™, it is something to do with the changes of higher version of Solidity. What we should do is to change the code in the Marketplace.sol to:

    fallback () external payable {
        buyToken(0);
    }

    receive () external payable {
        buyToken(0);
    }

And, then synchronizing the version of Solidity used by the contracts and in your ā€˜truffle-config.jsā€™.
I recommend having ā€˜^0.6.0ā€™ or ā€˜^0.8.0ā€™, specifying in the truffle config version:

version: "^0.6.0",

Then, updating the versions inside the smart contracts (ERC165.sol, ERC1155.sol, Marketplace.sol, etc):

pragma solidity ^0.6.0;

This is where the difficulty lies, updating the code of the course created 2 years ago. Anyway, hope that resolves the compile and parse errors and you can move forward with the course.

With kind regards

@alp257 Hello, hope your well,

I did what you suggested, Im using ā€œ0.8.0ā€ compiler , and ā€œ0.4.15ā€ truffle, Im getting the same error on updated version. But for the meantime its set to this. If you want me to change it let me know. So now the errors are


jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ git --version
git version 2.31.1.windows.1

jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken
$ truffle test
Using network 'test'.


Compiling your contracts...
===========================
> Compiling .\Lib\Address.sol
> Compiling .\Lib\ERC1155.sol
> Compiling .\Lib\ERC1155Mintable.sol
> Compiling .\Lib\ERC165.sol
> Compiling .\Lib\IERC1155.sol
> Compiling .\Lib\IERC1155TokenReceiver.sol
> Compiling .\Lib\SafeMath.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol
> Compiling .\contracts\marketplace.sol

> Compilation warnings encountered:

    Warning: 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.
--> project:/Lib/Address.sol

,Warning: 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.
--> project:/Lib/ERC1155.sol

,Warning: 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.
--> project:/Lib/ERC1155Mintable.sol

,Warning: 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.
--> project:/Lib/ERC165.sol

,Warning: 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.
--> project:/Lib/IERC1155.sol

,Warning: 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.
--> project:/Lib/IERC1155TokenReceiver.sol

,Warning: 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.
--> project:/Lib/SafeMath.sol

,Warning: 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.
--> project:/contracts/marketplace.sol


TypeError: Derived contract must override function "supportsInterface". Two or more base classes define function with same name and parameter types.
 --> project:/contracts/Token.sol:8:1:
  |
8 | contract GameToken is ERC1155, ERC1155Mintable{
  | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155":
  --> project:/Lib/ERC1155.sol:40:5:
   |
40 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "ERC1155Mintable":
  --> project:/Lib/ERC1155Mintable.sol:27:5:
   |
27 |     function supportsInterface(bytes4 _interfaceId)
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Member "isContract" not found or not visible after argument-dependent lookup in address.
  --> project:/Lib/ERC1155Mintable.sol:69:17:
   |
69 |             if (to.isContract()) {
   |                 ^^^^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.18 (core: 5.4.18)
Node v16.13.0

$ truffle version
Truffle v5.4.18 (core: 5.4.18)
Solidity - 0.8.9 (solc-js)
Node v16.13.0
Web3.js v1.5.3

package.json

{
    "name": "erc-1155",
    "version": "1.0.0",
    "description": "ERC-1155 Reference Implementation",
    "main": "truffle-config.js",
    "directories": {
        "test": "test"
    },
    "dependencies": {
        "@truffle/hdwallet-provider": "^2.0.0",
        "bignumber.js": "^4.1.0",
        "solc": "^0.4.15"
    },
    "devDependencies": {
        "truffle": "^5.4.24"
    },
    "scripts": {
        "test": "truffle test"
    },
    "repository": {
        "type": "git",
        "url": "git+https://github.com/enjin/erc-1155.git"
    },
    "keywords": [
        "enjin",
        "coin",
        "ethereum"
    ],
    "author": "Enjin PTE LTD",
    "license": "Apache-2.0",
    "bugs": {
        "url": "https://github.com/enjin/erc-1155/issues"
    },
    "homepage": "https://github.com/enjin/erc-1155#readme"
}

Hello @Javier_Flores,

Thank you, hope your well too, happy holidays :slight_smile:

Did some analysis and testing, try out this version of ā€˜ERC1155Mintable.solā€™.

  • imported Address.sol and added the ā€˜usingā€™ statement for the ā€˜isContractā€™ scope issue
  • commented out the redundant ā€˜supportsInterfaceā€™ function definition (atleast, for this course and to comply with the higher Solidity version changes)
pragma solidity ^0.8.0;

import "./ERC1155.sol";
import "./SafeMath.sol";
import "./Address.sol";

/**
    @dev Mintable form of ERC1155
    Shows how easy it is to mint new items.
*/
contract ERC1155Mintable is ERC1155 {

    using SafeMath for uint256;
    using Address for address;

    bytes4 constant private INTERFACE_SIGNATURE_URI = 0x0e89341c;

    // id => creators
    mapping (uint256 => address) public creators;

    // A nonce to ensure we have a unique id each time we mint.
    uint256 public nonce;

    modifier creatorOnly(uint256 _id) {
        require(creators[_id] == msg.sender);
        _;
    }

    // function supportsInterface(bytes4 _interfaceId)
    // public
    // view
    // override
    // virtual
    // returns (bool) {
    //     if (_interfaceId == INTERFACE_SIGNATURE_URI) {
    //         return true;
    //     } else {
    //         return super.supportsInterface(_interfaceId);
    //     }
    // }

    // Creates a new token type and assings _initialSupply to minter
    function create(uint256 _initialSupply, string calldata _uri) external returns(uint256 _id) {

        _id = ++nonce;
        creators[_id] = msg.sender;
        balances[_id][msg.sender] = _initialSupply;

        // Transfer event with mint semantic
        emit TransferSingle(msg.sender, address(0x0), msg.sender, _id, _initialSupply);

        if (bytes(_uri).length > 0)
            emit URI(_uri, _id);
    }

    // Batch mint tokens. Assign directly to _to[].
    function mint(uint256 _id, address[] calldata _to, uint256[] calldata _quantities) external creatorOnly(_id) {

        for (uint256 i = 0; i < _to.length; ++i) {

            address to = _to[i];
            uint256 quantity = _quantities[i];

            // Grant the items to the caller
            balances[_id][to] = quantity.add(balances[_id][to]);

            // Emit the Transfer/Mint event.
            // the 0x0 source address implies a mint
            // It will also provide the circulating supply info.
            emit TransferSingle(msg.sender, address(0x0), to, _id, quantity);

            if (to.isContract()) {
                require(IERC1155TokenReceiver(to).onERC1155Received(msg.sender, msg.sender, _id, quantity, '') == ERC1155_RECEIVED, "Receiver contract did not accept the transfer.");
            }
        }
    }

    function setURI(string calldata _uri, uint256 _id) external creatorOnly(_id) {
        emit URI(_uri, _id);
    }
}

With kind regards