I deleted last postâŚwas being a bit flippant, apologies. I have posted my code below for testing purposes. This is the code that performs the minting. I have a form which the user inputs all the parameters for the NFT file and after validating runs the calls to Rarible plugin (as per the minting tutorial) You will notice that if there is only 1 copy of the file then the contract type is set to ERC721 and if more than 1 it is set to ER1155.
async function submit(){
const input = document.getElementById('input_image');
const sale_price=document.getElementById('input_price');
const royalties=document.getElementById('input_royalties');
const mint_copies=document.getElementById('input_copies');
const sell_copies=document.getElementById('input_sellQty');
const emailAdd=document.getElementById('input_email');
let copies;
let list_sale;
let mintQty;
let sellQty;
if (validateEmail()==false){
return;
}
if(validateNFT()==false){
return;
}
if(validateFile()==false){
return;
}
var additionalData=[];
additionalData=parseAttributes(); //function which parses additional attributes input by user to metadata;
let sellQuantityTemp=document.querySelector('#input_sellQty');
let sellPriceTemp=document.querySelector('#input_price');
let text="Please check the details of your NFT. If the details are not correct then cancel the transaction. \n\n"
if(sellPriceTemp.value!="" && sellQuantityTemp.value==""){
alert("You have listed your NFT for sale but have not set the number of copies you wish to sell. \n The default value has been selected and is equal to the number of copies you have chosen to mint. If you wish to set a specific number of copies to make available for sale immediately then click cancel on the next pop up window!");
text+="Token name: " +document.querySelector('#input_name').value+ "\n";
text+="Description: " + document.querySelector('#input_description').value +"\n";
text+="Sale price(ETH): " + document.querySelector('#input_price').value +"\n";
text+="Royalties on future sales: " + document.querySelector('#input_royalties').value +"% \n";
if(mint_copies.value!="")
text+="Number of copies to mint: " + document.querySelector('#input_copies').value +"\n";
else
text+="Number of copies to mint: 1 " +"\n";
text+="Number of copies on sale: " + document.querySelector('#input_copies').value +"\n";
let email_add=document.querySelector('#input_email').value;
if(email_add!="")
text+="Email address: "+ email_add +"\n";
text+="Attributes: " + JSON.stringify(additionalData,null,"");
}
else{
text+="Token name: " +document.querySelector('#input_name').value+ "\n";
text+="Description: " + document.querySelector('#input_description').value +"\n";
text+="Sale price(ETH): " + document.querySelector('#input_price').value +"\n";
text+="Royalties on future sales: " + document.querySelector('#input_royalties').value +"\n";
if(mint_copies.value!="")
text+="Number of copies to mint: " + document.querySelector('#input_copies').value +"\n";
else
text+="Number of copies to mint: 1 " +"\n";
text+="Number of copies on sale: " + document.querySelector('#input_sellQty').value +"\n";
let email_add=document.querySelector('#input_email').value;
if(email_add!="")
text+="Email address: "+ email_add +"\n";
text+="Attributes: " + JSON.stringify(additionalData,null,"");
}
if ( !confirm(text))
return;
else{
let terms="1.Terms of service \n ....(some text) \n\n 2.Service charge \n EEZIMINT takes a ....... \n\n 3.Disclaimer \n\n EEZIMINT takes no responsibility for incorrect data or NFT's... \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
if ( confirm(terms)){ //this is a pop up alert to agree to terms of service
if(mint_copies.value=="" ||mint_copies.value=="0" ||mint_copies.value=="1"){
mintQty=1;
copies="ERC721"
}
else{
copies="ERC1155";
mintQty=mint_copies.value;
}
if(sale_price.value!=""){
list_sale=true;
}
else{ list_sale=false}
if(sell_copies.value=="" && list_sale==true)
sellQty =mintQty;
if(sell_copies.value!="" && list_sale==false)
sellQty=0;
if(sell_copies.value!="" && list_sale==true)
sellQty=sell_copies.value;
//--------------------------------------------------------------------------------
let data = input.files[0]
const imageFile = new Moralis.File(data.name, data)
await imageFile.saveIPFS();
let imageHash = imageFile.hash();
let metadata = {
name: document.querySelector('#input_name').value,
description: document.querySelector('#input_description').value,
image: "/ipfs/" + imageHash,
attributes: JSON.stringify(additionalData,null,"")
}
console.log(metadata);
const jsonFile = new Moralis.File("metadata.json", {base64 : btoa(JSON.stringify(metadata))});
await jsonFile.saveIPFS();
let metadataHash = jsonFile.hash();
console.log(jsonFile.ipfs());
if(list_sale==true){
let res = await Moralis.Plugins.rarible.lazyMint({
chain: 'rinkeby',
userAddress: user.get('ethAddress'),
tokenType: copies,
tokenUri: 'ipfs://' + metadataHash,
supply: mintQty,
royaltiesAmount: royalties.value*100, // 0.05% royalty. Optional
list: true, // only if lazy listing
listTokenAmount: sellQty, // only if lazy listing
listTokenValue: sale_price.value* (10 ** 18), // only if lazy listing
listAssetClass: 'ETH', // only if lazy listing || optional
})
console.log(res);
document.querySelector('#success_message').innerHTML =
`NFT minted. <a href="https://rinkeby.rarible.com/token/${res.data.result.tokenAddress}:${res.data.result.tokenId}" target="_blank" rel="noopener noreferrer"> View NFT </a>`;
document.querySelector('#success_message').style.display = "block";
//setTimeout(() => {
// document.querySelector('#success_message').style.display = "none";
//}, 5000)
}
else{
let res = await Moralis.Plugins.rarible.lazyMint({
chain: 'rinkeby',
userAddress: user.get('ethAddress'),
tokenType: copies,
tokenUri: 'ipfs://' + metadataHash,
supply: mintQty,
list: false, // only if lazy listing
//listTokenAmount: '0',
listAssetClass: 'ETH', // only if lazy listing || optional
})
console.log(res);
document.querySelector('#success_message').innerHTML =
`NFT minted. <a href="https://rinkeby.rarible.com/token/${res.data.result.tokenAddress}:${res.data.result.tokenId}"target="_blank" rel="noopener noreferrer"> View NFT </a>`;
document.querySelector('#success_message').style.display = "block";
// setTimeout(() => {
//document.querySelector('#success_message').style.display = "none";
// }, 5000)
}
//-----------------------------------------------------------------------------------------
deleteFile();
removeAttributes();
removePreview();
return;
}
else
return;
}
}