Help with _mintBatch ERC1155

Developer Wanted, Review Wanted How do I include id's and amounts in _mintBatch from ERC1155 contract?

Trying to create a function to _batchMint ERC1155 tokens, much like you would use _mint. However, when putting the token id's as array items, I get an error "Invalid type for argument in function call. Invalid implicit conversion from uint256[2] memory to uint256 memory requested."

:1234: Code to reproduce

contract Example is ERC1155, AccessControl {
    uint256 public constant ROWA = 0;
    uint256 public constant ROWB = 1;
    uint256 public constant ROWC = 2;
    uint256 public constant ROWBA = 30;
    

    constructor() public ERC1155("ipfs://example/metadata/{id}.json") {
        
    }
    function mintRowA(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) 
    public 
    payable
    auth {
  
        require(msg.value >= 10, "Not enough ETH sent; check price!"); 
  
        _mintBatch(msg.sender, [ROWA, ROWBA], [1, 1] , "" );
 
    }
}

:computer: Environment

Hardhat

//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "hardhat/console.sol";

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import {AccessControl} from "./AccessControl.sol";


contract Example is ERC1155, AccessControl {
    uint256 public constant ROWA = 0;
    uint256 public constant ROWB = 1;
    uint256 public constant ROWC = 2;
    uint256 public constant ROWBA = 30;
    uint256 public constant WAGMIT = 42;
    uint256[] ROWAT;
    uint256[] ROWBT; 

  
    constructor() public ERC1155("ipfs://example/metadata/{id}.json") {
         ROWAT.push(ROWB);
         ROWAT.push(ROWBA);
         ROWBT.push(uint256(1));
         ROWBT.push(uint256(1));
    }

        function mintRowA() 
            public 
             { 
             
                _mintBatch(msg.sender, ROWAT, ROWBT, "" );
        }

        function mintSingle()
        public
            {
                _mint(msg.sender, ROWA, 1, "");
            }
}

I get a success message on Rinkeby Etherscan with the above code, and I can see in the logs the data that there are 2 arrays and they both seem to be the correct length, but no tokens are transferred like they are with the mintSingle() function call. Halp plz.

@abcoathup ideas? Why does it succeed but no tokens are transferred?

I'm getting the transferBatch emission with seemingly correct data and arrays seem to be included correctly, but no tokens are transferred to the address.

What do you mean "no tokens are transferred to the address"? If you see the TransferBatch event they are being transferred.

The problem is that Solidity array literals are not located in memory. Your solution is using arrays in storage so it will be overly expensive. You can create an array in memory using new uint256[](length), then set the values. For example:

Thank you, @frangio! I was checking to see if the tokens transferred on Rinkeby Etherscan and for whatever reason, RE doesn't seem to register batch-minted ERC1155 tokens. If I mint singles, it shows them, but with mintBatch_ it doesn't. You're right, when checking with balanceOf, the tokens are there. Weird that etherscan doesn't give the same notification for batch-minted tokens as for single mint transactions. Thanks also for the feedback on the storage vs. memory. I initially had used your suggested solution but was playing around with other methods as I thought the way I was constructing the array was maybe the problem. Appreciate your reply and help!

1 Like

I am curious if batch mints are properly registered in mainnet Etherscan. Even if it's only Rinkeby Etherscan, you should report it as a bug if you can.

1 Like

Yeah that’s a good idea. Will do. Thanks again!