Building our ERC1155 Token Discussion

@alp257 greetings , happy holidays also,

I went ahead and started over in new build using 0.8.0 compilier, ERC1155 openzeppelin, I compiled everything getting the ok, just warnings. So I wondering if you can take a look at the response and code, I will upload to github also.

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

Compiling your contracts...
===========================
> Compiling @openzeppelin\contracts\access\Ownable.sol
> Compiling @openzeppelin\contracts\security\Pausable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\ERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155Receiver.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Burnable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Supply.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\IERC1155MetadataURI.sol
> Compiling @openzeppelin\contracts\utils\Address.sol
> Compiling @openzeppelin\contracts\utils\Context.sol
> Compiling @openzeppelin\contracts\utils\introspection\ERC165.sol
> Compiling @openzeppelin\contracts\utils\introspection\IERC165.sol
> Compiling .\contracts\Marketplace.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol
> Compilation warnings encountered:

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

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:36:32:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |                                ^^^^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:36:51:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |                                                   ^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:36:66:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |                                                                  ^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:36:79:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |                                                                               ^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:36:95:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |                                                                                               ^^^^^^^^^^^^^^^^^^^^

,Warning: Function state mutability can be restricted to pure
  --> project:/contracts/Marketplace.sol:36:5:
   |
36 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){
   |     ^ (Relevant source part starts here and spans across multiple lines).


> Artifacts written to D:\jflor\Documents\ERC1155GameToken2\build\contracts
> Compiled successfully using:
   - solc: 0.8.9+commit.e5eed63a.Emscripten.clang


jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken2
$

token.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";

contract GameToken is ERC1155, Ownable, Pausable, ERC1155Burnable, ERC1155Supply {
    constructor() ERC1155("") {}

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }

    function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        internal
        whenNotPaused
        override(ERC1155, ERC1155Supply)
    {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
    }
}

marketplace.sol

pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";


contract Marketplace {

    IERC1155 private _token;

    mapping (uint => uint) price;

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

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

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

    function buyTokens(uint 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)"));
    }
}

thank for your help.

@alp257 Hello,

I got it to compile, but i cant get it to migrate now ,

4_create_migration.js
=====================

TypeError: (intermediate value).create is not a function
    at createToken1 (D:\jflor\Documents\ERC1155GameToken2\migrations\4_create_migration.js:11:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Migration._deploy (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:70:1)    
    at Migration._load (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:56:1)      
    at Migration.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:217:1)       
    at Object.runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)    
    at Object.runFrom (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.runAll (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
    at Object.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
    at runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:258:1

hey thanks again,
Javier

Hello @Javier_Flores,

I would suggest skipping the ‘create’ migration script. Haven’t checked in detail, I see the Openzeppelin version of ERC1155 just simply have the ‘_mint’ function unlike Enjin’s original code where the creator (usually the owner) of the contract first need to ‘create’ the token then ‘mint’ them afterwards.

With kind regards

@alp257 Merry Christmas, Hope all is well,

I kind of understand , but would I have to create a new js file for the mintability function? Thanks again hope you had a good xmas.

Javier

@alp257

Deleted the create js file, compilier clang!, so I guess I can proceed, but these are the the issues I got about the call data.

$ truffle compile

Compiling your contracts...
===========================
> Compiling .\contracts\Marketplace.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol
> Compiling .\contracts\Token.sol
> Compilation warnings encountered:

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

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:32:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                ^^^^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:51:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                   ^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:66:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                  ^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:79:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                               ^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:95:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                                               ^^^^^^^^^^^^^^^^^^^^

,Warning: Function state mutability can be restricted to pure
  --> project:/contracts/Marketplace.sol:37:5:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |     ^ (Relevant source part starts here and spans across multiple lines).


> Artifacts written to D:\jflor\Documents\ERC1155GameToken2\build\contracts
> Compiled successfully using:
   - solc: 0.8.9+commit.e5eed63a.Emscripten.clang

Hello @Javier_Flores,

Merry Christmas to you too :slight_smile:

With respect to the course, you can ignore the unused variable warnings coming from the ‘onERC1155Received’ function.

Beyond the scope of the course, here you can implement some checks with the parameters for specific reasons (depending on your application) before the ‘return bytes4(keccak256…’ statement. Thus, eliminating the warnings.

With kind regards

@alp257 Hi,

I running the local first, it seem to work, so now the way this ERC115 is setup should be able to mint from game, but until then no tokens have been created? if I am understanding what your saying, Im going to test the mint function with local, check the transfering, is there anything you suggets to do also?

seems to compile, and Ive migrated, including removing the create.js file. But no tokens appear in balance. So like I stated before, it should mint when called to, right?

anyways thanks for all your help with this, hope you had a great holiday, are you ready the new year?

Javier

@alp257

current execution;

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

Compiling your contracts...
===========================
> Compiling @openzeppelin\contracts\access\Ownable.sol
> Compiling @openzeppelin\contracts\security\Pausable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\ERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155Receiver.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Burnable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Supply.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\IERC1155MetadataURI.sol
> Compiling @openzeppelin\contracts\utils\Address.sol
> Compiling @openzeppelin\contracts\utils\Context.sol
> Compiling @openzeppelin\contracts\utils\introspection\ERC165.sol
> Compiling @openzeppelin\contracts\utils\introspection\IERC165.sol
> Compiling .\contracts\Marketplace.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol
> Compilation warnings encountered:

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

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:32:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                ^^^^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:51:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                   ^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:66:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                  ^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:79:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                               ^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:95:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                                               ^^^^^^^^^^^^^^^^^^^^

,Warning: Function state mutability can be restricted to pure
  --> project:/contracts/Marketplace.sol:37:5:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |     ^ (Relevant source part starts here and spans across multiple lines).


> Artifacts written to D:\jflor\Documents\ERC1155GameToken2\build\contracts
> Compiled successfully using:
   - solc: 0.8.9+commit.e5eed63a.Emscripten.clang


jflor@DESKTOP-VSIL3IC MINGW64 /d/jflor/Documents/ERC1155GameToken2
$ truffle develop
Truffle Develop started at http://127.0.0.1:9545/

Accounts:
(0) 0x8c28dfbab09e02cff509ebce7f751bb4362e5a6b
(1) 0x937875ef4d03233d5b530eddebbd2f7d98c18b71
(2) 0x636fadee3ec84358d1206b297b616f748e649726
(3) 0xbf9f3544b6e3c0bc0c41672f975283be6efabf4e
(4) 0xa21d885140e362bf10113dc4a2436a59e671bd63
(5) 0x5fd2185ead3b19976441bd06e0555175b0d8f116
(6) 0xc49dbc8291125aec93677944c7bab572b29900a1
(7) 0x9659e920d89b2e6377ebca252d7923dca8e649fa
(8) 0x0b3da789d17f285171a047b392fe0a8cb0636232
(9) 0xad34d6c591860623de201ad7c395a5c33323a3b0

Private Keys:
(0) b41cd01c05a64c50b157a33079838f9ad497006cb643cc12ce868933b7bfc4d8
(1) 3da4d92126126b3a5a892fe1088b8cff01a45a0db2e6c91a65ce40f7186ec311
(2) 52def5527a353ba5f709de0367a130e427bc590c3a7209bd4f727b3df23e91c1
(3) c0b7b64382c82438fe621b88e7a5f3d7a1afd35261fd3ba866431fcbf27aab4d
(4) 54844f0127ff44177b2384357a64d73c755fc4b6583fba3151af769aa0007023
(5) d07ffb1ad542a745f2e3ab070592ef6e8f859791dfaf2e932bfb97905f6d9b10
(6) 282bac4b6cec24f98d8e9747aa54173161429d72d9ada64e19cc658b181f2bd8
(7) 1adf041539ac29f67e5b0e002998817c028edb946fb5bb22c5829ea3ffbbcaf0
(8) a9acebb160bc266ead7648fc8f19428afce77924b8cecf0dd718712f4b6d4549
(9) 288a8244e58b7336069a5b9f2d4e4a97d0b46e1d75cbe92ed2a41e9f3b4b28a5

Mnemonic: trouble kiwi loan wonder try when taxi pattern rough core load you

⚠️  Important ⚠️  : This mnemonic was created for you by Truffle. It is not secure.
Ensure you do not use it on production blockchains, or else you risk losing funds.

truffle(develop)> truffle migrate --reset

Compiling your contracts...
===========================
> Compiling @openzeppelin\contracts\access\Ownable.sol
> Compiling @openzeppelin\contracts\security\Pausable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\ERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155.sol
> Compiling @openzeppelin\contracts\token\ERC1155\IERC1155Receiver.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Burnable.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\ERC1155Supply.sol
> Compiling @openzeppelin\contracts\token\ERC1155\extensions\IERC1155MetadataURI.sol
> Compiling @openzeppelin\contracts\utils\Address.sol
> Compiling @openzeppelin\contracts\utils\Context.sol
> Compiling @openzeppelin\contracts\utils\introspection\ERC165.sol
> Compiling @openzeppelin\contracts\utils\introspection\IERC165.sol
> Compiling .\contracts\Marketplace.sol
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\Token.sol
> Compilation warnings encountered:

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

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:32:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                ^^^^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:51:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                   ^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:66:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                  ^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:79:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                               ^^^^^^^^^^^^^^

,Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> project:/contracts/Marketplace.sol:37:95:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |                                                                                               ^^^^^^^^^^^^^^^^^^^^

,Warning: Function state mutability can be restricted to pure
  --> project:/contracts/Marketplace.sol:37:5:
   |
37 |     function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4){      
   |     ^ (Relevant source part starts here and spans across multiple lines).


> Artifacts written to D:\jflor\Documents\ERC1155GameToken2\build\contracts
> Compiled successfully using:
   - solc: 0.8.9+commit.e5eed63a.Emscripten.clang



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


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

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0x4cfc59b9713062531ac77c93d2ad40eb5c5793c50232f9474888c3d9dad77c2e
   > Blocks: 0            Seconds: 0
   > contract address:    0xcd1E6c502695Be56B257C07b669Baab1376B6046
   > block number:        1
   > block timestamp:     1640557856
   > account:             0x8C28dFBaB09E02cff509eBcE7F751BB4362E5A6B
   > balance:             99.999335562
   > gas used:            332219 (0x511bb)
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.000664438 ETH


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


2_token_migration.js
====================

   Replacing 'GameToken'
   ---------------------
   > transaction hash:    0x10c9d5401f77237dd6299b2675682d98bc137385527bf39d891e736edaab0021
   > Blocks: 0            Seconds: 0
   > contract address:    0x3362bD957F45BCCf43027F590cF21047D40A76e9
   > block number:        3
   > block timestamp:     1640557865
   > account:             0x8C28dFBaB09E02cff509eBcE7F751BB4362E5A6B
   > balance:             99.991841664
   > gas used:            3704414 (0x38865e)
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.007408828 ETH


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


3_marketplace_migration.js
==========================

   Replacing 'Marketplace'
   -----------------------
   > transaction hash:    0x3cdab05a804b65d911190b08c09eaa1195b8ca72afa07133e67f6f6521c29139
   > Blocks: 0            Seconds: 0
   > contract address:    0xfCBAA661a1fcab4957Cbc22aEab5d2B935D3F552
   > block number:        5
   > block timestamp:     1640557873
   > account:             0x8C28dFBaB09E02cff509eBcE7F751BB4362E5A6B
   > balance:             99.990956606
   > gas used:            414994 (0x65512)
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.000829988 ETH


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


Summary
=======
> Total deployments:   3
> Final cost:          0.008903254 ETH


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

truffle(develop)> (await GameToken.at("0x3362bD957F45BCCf43027F590cF21047D40A76e9")).balanceOf("0xfCBAA661a1fcab4957Cbc22aEab5d2B935D3F552", 1)
BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null }
truffle(develop)> (await GameToken.at("0x3362bD957F45BCCf43027F590cF21047D40A76e9")).balanceOf("0x8c28dfbab09e02cff509ebce7f751bb4362e5a6b", 1)
BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null }
truffle(develop)>

Hello @Javier_Flores,

Glad to help. Thanks, had a great holiday. Hope your having a great one as well.

Yes, that’s right. It should mint when called to. With Openzeppelin’s version of ‘mint’ you have to call the function something like this:

await token.mint(market.address, 1, 30, "");
await token.mint(market.address, 2, 20, "");
await token.mint(market.address, 3, 10, "");

In the course, just like Filip, I did the minting inside a .js migration file so that it will be available in the game when it loads and fetch the data from the blockchain.

Looking forward for the next year.
With kind regards

@alp257 Hi,
yes , thank you,

Do I have to create a new modified “create_migration.js” to have marketplace mint pre-tokens it sells? or add markerplace mint functionality?

Now Im at the testnet part, going to run thru Kovan, like my ERC20GameToken, hopefully no errors,

Javier

Hello @Javier_Flores,

Yes, a new ‘mint_migration.js’ to pre-mint the tokens in the marketplace for the player to buy/sell.

Hope you do fine in the testnet part.
With kind regards

@alp257 Hello,

Hope your good,
Well I removed the mint.js, and ran the contract deployment locally, passed no issue, other than I had to add marketplace balance, without mint.js yet. I had a problem with kovan/infura , but got it fixed. But now Im have an error in the mint.js file when I add it, can you take a look for me please, thank you.

Error;

4_mint_migration.js
===================

   > Saving migration to chain.
   -------------------------------------
   > Total cost:                   0 ETH


Summary
=======
> Total deployments:   3
> Final cost:          0.008903254 ETH


UnhandledRejections detected
Promise {
  <rejected> Error: Invalid number of parameters for "mint". Got 2 expected 4!
      at createToken1 (D:\jflor\Documents\ERC1155GameToken2\migrations\4_mint_migration.js:11:28)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Migration._deploy (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:70:1)
      at Migration._load (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:56:1)
      at Migration.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:217:1)
      at Object.runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
      at Object.runFrom (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
      at Object.runAll (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
      at Object.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
      at runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:258:1)
      at Object.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:223:1)
      at Command.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:183:1) {
    hijackedStack: 'Error: Invalid number of parameters for "mint". Got 2 expected 4!\n' +
      '    at Object.InvalidNumberOfParams (C:\\Users\\jflor\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-core-helpers\\lib\\errors.js:33:1)\n' +
      '    at Object._createTxObject (C:\\Users\\jflor\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth\\node_modules\\web3-eth-contract\\lib\\index.js:669:1)\n' +
      '    at C:\\Users\\jflor\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\execute.js:195:1\n' +
      '    at processTicksAndRejections (node:internal/process/task_queues:96:5)'
  },

4_mint_migration.js

var Marketplace = artifacts.require("./Marketplace.sol");
var Token = artifacts.require("./GameToken.sol");

module.exports = (deployer) => deployer
  .then(() => createToken1())
  .then(() => createToken2())
  .then(() => createToken3())
  .then(() => mintTokens());

async function createToken1(){
  (await Token.deployed()).mint(0, "");
}

async function createToken2(){
  (await Token.deployed()).mint(0, "");

}

async function createToken3(){
  (await Token.deployed()).mint(0, "");
}
function mintTokens(){
  Token.deployed().then(instance => {
    instance.mint(1, [Marketplace.address], [30], 0x0);
    instance.mint(2, [Marketplace.address], [20], 0x0);
    instance.mint(3, [Marketplace.address], [10], 0x0);
  });
}

I feel like Im missing parameter arguments.

Hello @Javier_Flores, greetings

Try removing the ‘createToken’ calls and related code:

  .then(() => createToken1())
  .then(() => createToken2())
  .then(() => createToken3())

This pattern was done in the course to create the token type first before minting.

With Openzeppelin’s contract, the ‘creation’ of a token type ID is also done at the same time you mint the token (might need to have the right ‘minter’ role if you used the preset MinterPauser contract).

Hope this is useful to you.
With kind regards

May I understand why in the marketplace.sol we are importing the IERC.sol and not the ERC.sol?

Without the ERC.sol, how can we invoke the safeTransferFrom function?

Hello @Eleanor_Tay, greetings

When you build the Marketplace contract, it does not need any ERC-1155 implementation in the contract itself but to support handling ERC-1155 tokens the contract needs to know the function signatures (function names, parameters) to call the ERC-1155 functions. That’s where the IERC1155.sol comes in, and then you just pass the address to get an instance of that ERC-1155 token.
Afterwards, you can invoke the safeTransferFrom function in the Marketplace contract.

Hope this is useful to you.
With kind regards

Thank you, I think I understand it now

I was wondering how could you change the code to buy the erc-1155 tokens using our game tokens that get minted instead of ether?

1 Like

Hello @TypicalGamer,

There are different approaches how you can design this, giving you a few:

  1. fully on-chain
  • ask the user to give allowance for their tokens (buy amount) to be transferred by that ERC20 token contract
  • your ERC1155 smart contract have it built and interact with the ERC20 token contract, check for the required token allowance is met then make the transfer, mint the ERC1155 token
  1. mix of on chain and off chain
  • ask the user to make a transfer (buy amount) to your wallet (designated wallet), like buying it from you. then your web app/game (or you, authorized wallet) trigger a mint of that ERC1155 token given to that user as a receiver.

For both and any other approaches, this is the general flow, make sure put in the right checks for security, etc

Hope the information is helpful to you
With kind regards

2 Likes

For the sake of future students:
There is no need to define function “onERC1155Received” in your contract any more because ERC1155 standard already has it in function “_doSafeTransferAcceptanceCheck” which is called by “_safeBatchTransferFrom”.

1 Like

Hi,
Hope someone will be able to help this. I cloned the github project, then cd this directory
https://github.com/filipmartinsson/Ethereum-Game-Programming-Course/tree/master/Building-our-ERC1155-Token/Marketplace

When I truffle develop
then migrate --reset

I got “Error: returned error: VM Exception while processing transaction” error. It seems the error is triggered when the mintTokens() function is called in 4_create_migrations.js.

Did anyone else experience this? Thanks in advance