Building our ERC1155 Token Discussion

Welcome to the discussion about this section. Here you can ask questions or post feedback about this specific section.


Hi Filip
Can You tell me what is “build” folder in Your implementation. I didn’t see that in the previous episode and it suddenly occured. I don’t have it in my project and I am wondering if it is necessary for the next steps in this project?

I don’t remember of the top of my head. But it shouldn’t be necessary. If you need it just run the compile command in the truffle console and you will also get the folder.

1 Like

thx, compile works:)

I love it… we aren’t trying to re-invent the wheel :facepunch:

1 Like

The build folder are probably just JSON files from the ERC20 contracts, generated by truffle. You don’t need these anymore.

1 Like

Loving this course so far… so much fun… excited to see we are taking advantage of enjin libraries… been stacking enjin bags for about a year now :slight_smile:

1 Like

I am working on my own project and writing for help with the implementation of the erc1155 contracts. I have already finished the game course related to the 1155 contracts. I am going deeper into the standard and I have run into a problem and need help. I am using the same code as in the ethereum game course except I have added ERC1155MixedFungibleMintable.sol and ERC1155MixedFungible.sol. I am able to mint NFT’s and fungible tokens but I am unable to successfully call function safeTransferFrom so the transaction does not go through. I am using remix and getting error “transact to TokenContract.safeTransferFrom errored: Error encoding arguments: Error: invalid bytes value (arg=”", coderType=“bytes”, value="", version=4.0.47)."

I am stuck and not sure how to get past this issue. Thank you for your time and help.

your value is empty, have you tried to set a default value?

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

why is having an empty value an error? How would I set a default value for the bytes _data in safeTransferFrom? I am able to call mintNonFungible() without a having a value for bytes _data param.

Hey @rou369

Having an empty string is wrong as the code require for a byte argument.

safeTransferFrom(from, to, id, amount, data)

An empty bytes data is represented with 0x0



@filip Hi Filip , how do we use the GameToken we earn from the game to trade for item instead of purchase the item with ether?

I’m hitting the same “invalid bytes value” error with the following output:

truffle(develop)> (await"0x8F5E7a4C638B577597978a5326529Bc505591d44")).safeTransferFrom("0x9245182F3c3aD68d03C786dEBC64cC35CCadC10E", "0x617b817006df0522788038dc1da889fd73ff94bc", 1, 10, 0x0)
{ Error: invalid bytes value (arg="_data", coderType="bytes", value=0)    at PromiEvent (C:\Users\Will\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\promievent.js:9:1)
    at TruffleContract.safeTransferFrom (C:\Users\Will\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\execute.js:169:1)
    at evalmachine.<anonymous>:1:8
    at process._tickCallback (internal/process/next_tick.js:68:7)
  reason: 'invalid bytes value',
  arg: '_data',
  coderType: 'bytes',
  value: 0,
   'Error: invalid bytes value (arg="_data", coderType="bytes", value=0)\n    at Object.throwError (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\errors.js:68:1)\n    at CoderDynamicBytes.encode (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\abi-coder.js:540:1)\n    at C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\abi-coder.js:605:21\n    at Array.forEach (<anonymous>)\n    at pack (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\abi-coder.js:604:1)\n    at CoderTuple.encode (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\abi-coder.js:764:1)\n    at AbiCoder.encode (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\node_modules\\ethers\\utils\\abi-coder.js:897:1)\n    at ABICoder.encodeParameters (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-abi\\src\\index.js:96:1)\n    at C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-contract\\src\\index.js:426:1\n    at (<anonymous>)\n    at Object._encodeMethodABI (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-eth-contract\\src\\index.js:425:10)\n    at execute.prepareCall.then (C:\\Users\\Will\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\execute.js:181:1)\n    at process._tickCallback (internal/process/next_tick.js:68:7)' }

I seem to hit the invalid bytes value error no matter what I put in there. I’ve tried “”, 0x0, 0x1, etc.

hey @thecil,
Hope you’re doing great.

I’m trying to import the ERC1155.sol contract from openZeppelin rather than Enjin.
But IDK what value to put in for URI as the constructor demands it.


 constructor(string memory uri_) {


1 Like

Or maybe I can pass the empty string for just now, like this

contract Token is ERC1155{

 constructor() ERC1155(""){
1 Like

Yes, completely valid, the URI is used when you want to link metadata to the nft, but for that you need an url (a domain ) and extra complexity from your server side to display the JSON object like:

Carlos Z

1 Like

Thanks, @thecil for the clarification. :slightly_smiling_face:

1 Like

I have a question about some of the solidity code in this section. I completed the Ethereum Smart Contracts 101 and 201 courses, but am unfamiliar with something Filip wrote in the video. Here’s the code/contract I’m talking about:

pragma solidity 0.5.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; 

   function () external payable {

   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, ""); 


Specifically, I don’t quit understand this piece of code:

IERC1155 private _token; 

What exactly does that do? Does it use “_token” to point to the IERC1155 contract? I notice later in the contract Filip uses “_token” to invoke the “safeTransferFrom” function in the IERC155 contract:

   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, "");

Hello @CaliCrypto22,
‘_token’ in this context is used as a reference to your token contract (or any token contract) following the ERC1155 standard. As you already know if a token follows a certain standard it is expected that it has a set of functions that can be called, which means if you assign another token (maybe not yours) to ‘_token’ that follows the the ERC1155, your code still works as it uses the ‘safeTransferFrom’ function where this function is defined in the interface IERC1155 meaning all ERC1155 tokens should have this implemented in them. This ensures that whatever token you assign with ‘_token’ as long as it followed the ERC1155 standard it is expected that ‘safeTransferFrom’ function and all others are present.

Hope this makes it clear for you.
With kind regards

1 Like

Thanks! I think I understand it better.