1

I'm developing an NFT Marketplace using the Moralis server. I'd like to know that is there any way to upload multiple nfts with different metadata in one single transaction? Can you please share the smart contract for that?

3 Answers 3

1

This is what i can recommend, but this is the implementation using alchemy.

https://docs.alchemy.com/alchemy/tutorials/how-to-create-an-nft/how-to-mint-a-nft

Just use a loop on your minting function. for example if there are 3 NFT, loop it 3 times in turn it means to called your minting function 3 times.

from alchemy docs :- To mint x number of NFTs in a single command, we can use a simple for loop running from 0 to x-1 within a function wrapping the minting process. This would allow us to effectively mint x NFTs every time the wrapper mint function is called.

0

On the contract side you just run a simple loop.

for (uint i = 0; i < _amount; i++) {
        uint mintIndex = totalSupply();
        _safeMint(msg.sender, mintIndex);
}

For the metadata you need to run a cloud function on you Moralis server posting the new metadata to wherever you're hosting your server.

0

Let us suppose, function safeMint(address to, string memory uri) is the function to mint 1 NFT

Then, the code to mint multiple NFT will be:

function MultiMint(address[] tos, string[] memory uris){
    uint i=0;
    for(i;i<tos.length;i++){
        safeMint(tos[i],uris[i]);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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