Integrating ERC20 Token with the Game Discussion

as i had to make a lot of changes to get it to work so its easier to explain on call

issue minting ERC1155 token

 
```**We could not estimate the price of fuel**. Therefore, there may be an error in the contract and this transaction may fail

 **Here is   GameToken contract:** 

pragma solidity >=0.4.22 <0.9.0;

import “…/lib/ERC1155.sol”;
import “…/lib/ERC1155Mintable.sol”;

contract GameToken is ERC1155, ERC1155Mintable{

constructor() public{

}

function mint(uint256 _id,address[] memory to, uint256[] memory tokenNumber) public {
mint(_id, to , tokenNumber );
//mint(uint256 _id, address[] calldata _to, uint256[] calldata _quantities)

}

}

**here is function  mintAfterGame(nrOfTokens) in eth.js**

var token = new web3.eth.Contract(tokenAbi, “0x6d41e3Da1F72840e9B0Ff7D3adeC718BBBCb75A2”);

var marketplace = new web3.eth.Contract(marketplaceAbi, “0xD893842417CB9928eD4f27A702a2310cF1fF004a”);

function mintAfterGame(nrOfTokens){
web3.eth.getAccounts().then(accountArray => {
var account = accountArray[0];

   token.methods.mint(4, [account], [nrOfTokens]).send({from: account})
  .on('receipt', receipt => {
    alert("Transaction Complete");
  })
});

}

**here is the index.html that call the mining function:**

var coinsSent = false;

function updateTimeLeft(){

     if(gameOver){
        
        mintAfterGame(score);
         coinsSent = true;
       }

       return;
     };

}


why do i have this error in metamask:

We could not estimate the price of fuel**. Therefore, there may be an error in the contract and this transaction may fail

1 Like

Hello @patgeek

Afaik, in the course, you mint the ERC1155 tokens via a migration script and send it to a marketplace. Then, the player buys the tokens from the game which you have to specify a value (as payment).

In turn, since your minting the ERC1155 token using a metamask wallet in the browser, I think you have to try adding options for gas and gasPrice just like how you do it with from: account

See https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html.

With kind regards

1 Like

verry strange when i mint ERC20 GameToken, there is no problem in minting tokens

But it comes to mint ERC1155 token GameToken, i still have this error:

MetaMask - RPC Error: err: max fee per gas less than block base fee: address 0x0000000000000000000000000000000000000000, maxFeePerGas: 21560 baseFee: 3318480442 (supplied gas 500000000) {code: -32000, message: 'err: max fee per gas less than block base fee: add…1560 baseFee: 3318480442 (supplied gas 500000000)'}

my call to contract ERC1155 is;

var token = new web3.eth.Contract(tokenAbi, "0x6d41e3Da1F72840e9B0Ff7D3adeC718BBBCb75A2",{gas:500000000, gasPrice: "21560"});

i also tried

function mintAfterGame(nrOfTokens){
    web3.eth.getAccounts().then(accountArray => {
      var account = accountArray[0];//accountArray[0] ==> address compte metamask connecté
    
       token.methods.mint(4, [account], [nrOfTokens]).send({from: account, gasPrice: 200000000000})
      .on('receipt', receipt => {
        alert("Transaction Complete");
      })
    });

but in this case i still have this error

We could not estimate the price of fuel**. Therefore, there may be an error in the contract and this transaction may fail
1 Like

Hello @patgeek,

I think you also need to provide the amount of eth to pay for gas as you mint in

token.methods.mint(4, [account], [nrOfTokens]).send({from: account, gasPrice: 200000000000})

add some value: for the transaction to push through. In the migration script approach, this is done under the hood because a wallet is already configured to fund the minting.

Hope the information is helpful to you
With kind regards

1 Like

hello

i did not understand what you mean by:
add some value: for the transaction to push through. In the migration script approach, this is done under the hood because a wallet is already configured to fund the minting.

1 Like

Hello @patgeek,

Suggesting to add some eth in executing the transaction like:

.send({from: account, value: 2000000000, gasPrice: 200000000000})

Clarifying the detail, following the course content, you do the minting of the ERC1155 tokens via migration scripts, not from the game.

1 Like

Currently I have a little problem. As soon as the game is over I get the prompt from metamask to confirm the transaction. The problem here is, that for some reason it´s not only one transaction but one transaction per coin.
I am currently working on it but if any of you find a problem in my code please let me know.
https://github.com/paulsimroth/eth_game

Hello @PaulS96,

The quick fix for this is to remove the await in await mintAfterGame(score);. The mint transaction is queued anyway OR you set the coinsSent = true; first before doing await mintAfterGame(score); so that the state (coinsSent) blocks any further attempts to mint coins. If it fails (based on the transaction receipt), revert it to false.

Hope the information is useful to you

2 Likes

Thanks for the help. That fixed my issue.

2 Likes