Adding ERC1155 Token to Game Discussion

#1

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

0 Likes

#2

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

0 Likes

#3

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

1 Like

#4

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”

0 Likes

#5

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

#6

Thanks a lot. It worked :+1:

1 Like

#7

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


0 Likes

#8

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

0 Likes

#9

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

0 Likes

#10

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.

0 Likes

#11

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

0 Likes

#12

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

0 Likes

#13

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.

0 Likes

#14

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.

0 Likes

#15

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

0 Likes