Bulk Minter is not Bulk Minting according to TokenID order

I have deployed this contract that I have modified from the Moralis example in order to bulk mint 50 NFTs.

Here is the code.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

// Import 1155 token contract from Openzeppelin
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract WEBContract is ERC1155, Ownable {
    using SafeMath for uint256;

    uint256 public items;

    constructor() ERC1155("ipfs://QmSSqnAuYdU3sndc8AMgxVv74DMJeDfebkadKjWidgjqFv/metadata/{id}.json") {
        items = 50;

    function mintAll() public onlyOwner {
        for (uint256 i = 1; i <= items; i++) {
            mint(msg.sender, i, 2000000);

    function mint(address to, uint256 id, uint256 amount) public onlyOwner {
        _mint(to, id, amount, "");

    function burn(address from, uint256 id, uint256 amount) public {
        require(msg.sender == from);
        _burn(from, id, amount);

The code works but I realized that sometimes the TokenID is not the same as the JSON equivalent.
For example, here the TokenID is 20 but the image that is minted is image #14, the JSON metadata is also for #14 instead of 20.

My question is, why is this happening?
I assume it has to do with the fact that the constructor is grabbing this {id} for JSON, so the indexer here is id, but in the loop, I am not using this id at all.
Instead, I am using this variable “i” for the loop.

How can I include each JSON inside this loop, so that TokenID[1] mints the “1.json” file and so on until TokenID[50] mints “50.json”?

Hello this would be the same issue outlined here if you’re using the same tutorial.

The tutorial code doesn’t work properly past 9 NFTs as the ERC1155 ID needs to be in hexadecimal format, not decimal; in your case 20 (decimal) is 14 (hex). So you will need to adjust the generation code.

1 Like

Thanks a lot @alex.
It was exactly the thing that you mentioned.
The original example that I followed had this bug that was using decimal instead of hexadecimal.
All I had to do was to change every place where decimal values were being used to hexadecimal ones.
I will write a few examples here in case people refer to this thread.
In filesystem.js

  let filename = editionCount.toString(16) + ".png";

In metadata.js

    let id = i.toString(16);
    let paddedHex = (
      "0000000000000000000000000000000000000000000000000000000000000000" + id

Here I am converting from decimal to hexadecimal using toString(16).