Btw hereās the logic file
const nft_contract_address = ā0x34224c6D2386557B7FAAc4Bd3D1E36Ef0Dfb9588ā //NFT Minting Contract Use This One āBatteries Includedā, code of this contract is in the github repository under contract_base for your reference.
/*
Available deployed contracts
Ethereum Rinkeby 0x0Fb6EF3505b9c52Ed39595433a21aF9B5FCc4431
Polygon Mumbai 0x351bbee7C6E9268A1BF741B098448477E08A0a53
BSC Testnet 0x88624DD1c725C6A95E223170fa99ddB22E1C6DDD
*/
const web3 = new Web3(window.ethereum);
//frontend logic
async function login(){
document.getElementById(āsubmitā).setAttribute(ādisabledā, null);
document.getElementById(āusernameā).setAttribute(ādisabledā, null);
document.getElementById(āuseremailā).setAttribute(ādisabledā, null);
Moralis.Web3.authenticate().then(function (user) {
user.set(ānameā,document.getElementById(āusernameā).value);
user.set(āemailā,document.getElementById(āuseremailā).value);
user.save();
document.getElementById(āuploadā).removeAttribute(ādisabledā);
document.getElementById(āfileā).removeAttribute(ādisabledā);
document.getElementById(ānameā).removeAttribute(ādisabledā);
document.getElementById(ādescriptionā).removeAttribute(ādisabledā);
})
}
async function upload(){
const fileInput = document.getElementById(āfileā);
const data = fileInput.files[0];
const imageFile = new Moralis.File(data.name, data);
document.getElementById(āuploadā).setAttribute(ādisabledā, null);
document.getElementById(āfileā).setAttribute(ādisabledā, null);
document.getElementById(ānameā).setAttribute(ādisabledā, null);
document.getElementById(ādescriptionā).setAttribute(ādisabledā, null);
await imageFile.saveIPFS();
const imageURI = imageFile.ipfs();
const metadata = {
ānameā:document.getElementById(ānameā).value,
ādescriptionā:document.getElementById(ādescriptionā).value,
āimageā:imageURI
}
const metadataFile = new Moralis.File(āmetadata.jsonā, {base64 : btoa(JSON.stringify(metadata))});
await metadataFile.saveIPFS();
const metadataURI = metadataFile.ipfs();
const txt = await mintToken(metadataURI).then(notify)
}
async function mintToken(_uri){
const encodedFunction = web3.eth.abi.encodeFunctionCall({
name: āmintTokenā,
type: āfunctionā,
inputs: [{
type: āstringā,
name: ātokenURIā
}]
}, [_uri]);
const transactionParameters = {
gasPrice: '0x270000000',
to: nft_contract_address,
from: ethereum.selectedAddress,
data: encodedFunction
};
const txt = await ethereum.request({
method: āeth_sendTransactionā,
params: [transactionParameters]
});
return txt
}
async function notify(_txt){
document.getElementById(āresultSpaceā).innerHTML =
<input disabled = "true" id="result" type="text" class="form-control" placeholder="Description" aria-label="URL" aria-describedby="basic-addon1" value="Your NFT was minted in transaction ${_txt}">
;
}
async function getAverageGasPrices() {
const results = await Moralis.Cloud.run(āgetAvgGasā);
console.log(āaverage user gas prices:ā, results);
renderGasStats(results);
}
function renderGasStats(data) {
const container = document.getElementById("gas-stats");
container.innerHTML = data
.map(function (row, rank) {
return `<li>#${rank + 1}: ${Math.round(row.avgGas)} gwei</li>`;
})
.join("");
}
//get stats on page load
getStats();