Hello,
I watched the following YouTube video and successfully minted my first NFT.
However, my issue is that IPFS returns no image even after 24 hours. Metadata went through.
Here is the code according to the tutorial.
const nft_contract_address = "0x0Fb6EF3505b9c52Ed39595433a21aF9B5FCc4431"
const web3 = new Web3(window.ethereum);
async function upload(){
const data = "MY-PNG-IMAGE"";
const imageFile = new Moralis.File("image.png", { base64: data });
document.getElementById('doMint').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":"NAME HERE",
"description":"DESCRIPTION HERE",
"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 = {
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}">`;
}
upload();
mintToken();
notify();
What did I do wrong regarding the IPFS?
How can I ensure IPFS catch my image?
Thanks in advance.