Adding ERC1155 Token to Game Discussion

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

As soon as I click on the buy button I get this error in metamask

Looks like something is wrong in your contract. Could you send me the contract and it’s address?

1 Like

GameToken Contract
pragma solidity ^0.5.0;

import ‘…/lib/ERC1155.sol’;
import ‘…/lib/ERC1155Mintable.sol’;

contract GameToken is ERC1155, ERC1155Mintable {
constructor() public {}
}

GameToken Contract Address: “0x88ad3ae682f0a35283610a06668B3a5ec3898403”

Marketplace Contract
pragma solidity ^0.5.0;

import ‘…/lib/IERC1155.sol’;

contract Marketplace {
IERC1155 private _token;

mapping (uint256 => uint256) price; //mapping from id of the token to its 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(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)"));
}

}

Marketplace Contract Address: “0x0d94CbB328989f86c300d6A5bc58Fa1618971592”

You have an error in your buyToken function.

    require(weiAmount >= price[tokenID] && price[tokenID] == 0);

should be

    require(weiAmount >= price[tokenID] && price[tokenID] != 0);

We want to check so that the price of the item is NOT 0. You’re require function failed because the item price was not zero.

1 Like

Thanks a lot. It worked :+1:

1 Like

When I try to start The ERC1155 section all over again, I stumble to a problem that I didn’t had before.
In Develop local mode it works fine.
But when I try to deploy to Ropsten testnet, I get weird errors once it’s at the marketplace part: Does anybody recognize this?? it would reduce my debug time! :grinning:
Thanks, Fabrice


Gonna recompile everything. I notice that if you make changes to a contract that inherits another contract. you get in trouble easily.

Almost looks like an API request limit. Hmmm, maybe just let it rest for 5 min a try again.

I’m still having this issue. Today I’m gonna search the problem again, Looks like some problem with my HDWallet

(ps.i’m on ubuntu linux)

I read this in the console:
If you’re using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.

update in infura:
Project Id’s will be required from 27/03/2019 (my birthday lol)

I’m not 100% sure that the dashboard update has anything to do with infura API. Will have to check when I get home.

according to someone it was more than a dashboard update.
I used a new key in infura but still have the same issue.
I let you know when I found it.
maybe I have a gas issue or something.

Changed to a new project ID in infura and
I have tried many things without success, and today it suddenly works. :+1:
But I don’t know why it works. It’s definitely something with infura or HdwalletProvider locally.

BOOOOM, nice job @Fabrice. I’m happy to hear that you solved it. Probably just an old ID. You got caught in the middle of the update.

I am also getting this but maybe for different reason then above.

!

also Reading this error in the console…

web3.min.js:1 Uncaught (in promise) Error: Transaction has been reverted by the EVM:
{

There is an error in your code somewhere. Your transaction is throwing an error. Try debugging it yourself and look into the transaction that is failing. Look at what data you are sending to it and why it might throw. If you can’t solve it you can post your code here as a last resort and I will take a look.

Thanks filip for making sure I wont stay stuck for too long but it was something pretty obvious, just had to set the “buyTokens” to at least 1 and problem solved.

1 Like

now I’m getting this same issue :joy:
Programming is fun :joy:
it’s a game of ‘hide and seek’ the bug :stuck_out_tongue_winking_eye:

1 Like

when re-deploy erc1155 on Ropsten, I mostly have this same issue again. When I change my truffle config to rinkeby, it works perfectly every time. :+1: