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.
thx, compile works:)
I love it⌠we arenât trying to re-invent the wheel
The build folder are probably just JSON files from the ERC20 contracts, generated by truffle. You donât need these anymore.
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
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!
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
cheers,
Dani
@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 GameToken.at("0x8F5E7a4C638B577597978a5326529Bc505591d44")).safeTransferFrom("0x9245182F3c3aD68d03C786dEBC64cC35CCadC10E", "0x617b817006df0522788038dc1da889fd73ff94bc", 1, 10, 0x0)
Thrown:
{ 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',
code: 'INVALID_ARGUMENT',
arg: '_data',
coderType: 'bytes',
value: 0,
hijackedStack:
'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 Array.map (<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.
openzeppelin/contracts/token/ERC1155/ERC1155.sol
constructor(string memory uri_) {
_setURI(uri_);
}
Thanks
Or maybe I can pass the empty string for just now, like this
contract Token is ERC1155{
constructor() ERC1155(""){
}
}
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:
https://ipfs.moralis.io:2053/ipfs/QmRJK5RyepFc4pdwtEWY95vJDFFHzRSRyC9qrNTioWJ1Qy
Carlos Z
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 {
buyToken(1);
}
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
Thanks! I think I understand it better.