So I am making an ERC1155 token (for the batch mint pretty much). It is only ever going to mint NFT's (as you will see now now).

I am trying to batch mint tokens and store an array for each one. So each tokenID needs to have an uint8[] array associated with it. I am storing it in stateStorageForNumbers_ which is a mapping: mapping(uint256 => uint8[]) internal stateStorageForNumbers_;.

But I have no idea how to pull the array out of the 2D array to store it.

function batchMint(
        address _to,
        uint8 _amount,
        uint8[][] calldata _numbers
        returns(uint256[] memory tokenIDs)
        // Setting up tokenIDs for mint
        uint256[] memory amounts;
        for (uint256 i = 0; i < _amount; i++) {
            // Incrementing the tokenID tracker
            // Adding the tokenID to array
            tokenIDs[i] = _tokenIDsCount.current();
            // Amount is always 1 as only minting NFTs
            amounts[i] = 1;

            // HERE
            stateStorageForNumbers_[tokenIDs[i]] = _numbers[i][];

        // Minting the batch of tokens

For ease of talking about it I am going to name the arrays quick, so its _numbers[j][k].

So as you can see I am passing in a 2D array _numbers, where the length of the j array will be the same as _amount. The inner array k is what I am actually trying to store.

Inside the for loop I am creating new tokenID numbers, creating an array (that gets returned) with all the ID's, then setting the amounts to all be 1 (as I want to mint exclusively NFTs).

You can see how I am trying to store k in stateStorageForNumbers_ by the // HERE, But this gives me the compiler error:

contracts/LottoNFT.sol:97:42: TypeError: Index expression cannot be omitted.
            lottoNumbers_[tokenIDs[i]] = _lottoNumbers[i][];

contracts/LottoNFT.sol:97:42: TypeError: Type uint8 is not implicitly convertible to expected type uint8[] storage ref.
            lottoNumbers_[tokenIDs[i]] = _lottoNumbers[i][];

Is this possible? Do I need to make them fixed-size arrays? I am not sure where to go from here. Thanks in advance, a stressed-out Sol dev.

  • 1
    what happens if you try stateStorageForNumbers_[tokenIDs[i]] = _numbers[i];? Feb 24 '21 at 17:22

The comment is right, removing the [] fixes it.

stateStorageForNumbers_[tokenIDs[i]] = _numbers[i];

^ This works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.