0

I try to do example this tutorial. I run succesfully this. But I take error that "Upload errorTypeError: str is undefined". How can ı solve his?

I did before: -> I deleted artifacts the ı deployed hardhat succesfully again.But nothing happened.I took same error. -> And I tried to upload small pictures but nothing happened again.

Now I want to asked something that how can ı add liquidity and treasury process? Do you have any document or video about that?

Here is the project link- https://github.com/kayhannkaya/Nft-Mint-Tutorial/tree/main

Error ss: enter image description here

Code :

export const uploadFileToIPFS = async(file) => {
const url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
//making axios POST request to Pinata ⬇️

let data = new FormData();
data.append('file', file);

const metadata = JSON.stringify({
    name: 'testname',
    keyvalues: {
        exampleKey: 'exampleValue'
    }
});
data.append('pinataMetadata', metadata);

//pinataOptions are optional
const pinataOptions = JSON.stringify({
    cidVersion: 0,
    customPinPolicy: {
        regions: [
            {
                id: 'FRA1',
                desiredReplicationCount: 1
            },
            {
                id: 'NYC1',
                desiredReplicationCount: 2
            }
        ]
    }
});
data.append('pinataOptions', pinataOptions);

return axios 
    .post(url, data, {
        maxBodyLength: 'Infinity',
        headers: {
            'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
            'Authorization': `Bearer ${JWT}`,
            'pinata_api_key': key,
            'pinata_secret_api_key': secret,
        }
    })
    .then(function (response) {
        console.log("image uploaded", response.data.IpfsHash)
        return {
           success: true,
           pinataURL: "https://blush-defeated-roundworm-642.mypinata.cloud/ipfs/" + response.data.IpfsHash
       };
    })
    .catch(function (error) {
        console.log(error)
        return {
            success: false,
            message: error.message,
        }

});

SellNFT.js code:

export default function SellNFT () {
const [formParams, updateFormParams] = useState({ name: '', description: '', price: ''});
const [fileURL, setFileURL] = useState(null);
const ethers = require("ethers");
const [message, updateMessage] = useState('');
const location = useLocation();

async function disableButton() {
    const listButton = document.getElementById("list-button")
    listButton.disabled = true
    listButton.style.backgroundColor = "grey";
    listButton.style.opacity = 0.3;
}

async function enableButton() {
    const listButton = document.getElementById("list-button")
    listButton.disabled = false
    listButton.style.backgroundColor = "#A500FF";
    listButton.style.opacity = 1;
}

//This function uploads the NFT image to IPFS
async function OnChangeFile(e) {
    var file = e.target.files[0];
    //check for file extension
    try {
        //upload the file to IPFS
        disableButton();
        updateMessage("Uploading image.. please dont click anything!")
        const response = await uploadFileToIPFS(file);
        if(response.success === true) {
            enableButton();
            updateMessage("")
            console.log("Uploaded image to Pinata: ", response.pinataURL)
            setFileURL(response.pinataURL);
        }
    }
    catch(e) {
        console.log("Error during file upload", e);
    }
}

//This function uploads the metadata to IPFS
async function uploadMetadataToIPFS() {
    const {name, description, price} = formParams;
    //Make sure that none of the fields are empty
    if( !name || !description || !price || !fileURL)
    {
        updateMessage("Please fill all the fields!")
        return -1;
    }

    const nftJSON = {
        name, description, price, image: fileURL
    }

    try {
        //upload the metadata JSON to IPFS
        const response = await uploadJSONToIPFS(nftJSON);
        if(response.success === true){
            console.log("Uploaded JSON to Pinata: ", response)
            return response.pinataURL;
        }
    }
    catch(e) {
        console.log("error uploading JSON metadata:", e)
    }
}
data.append('file', file);

const metadata = JSON.stringify({
    name: 'testname',
    keyvalues: {
        exampleKey: 'exampleValue'
    }
});
data.append('pinataMetadata', metadata);

//pinataOptions are optional
const pinataOptions = JSON.stringify({
    cidVersion: 0,
    customPinPolicy: {
        regions: [
            {
                id: 'FRA1',
                desiredReplicationCount: 1
            },
            {
                id: 'NYC1',
                desiredReplicationCount: 2
            }
        ]
    }
});
data.append('pinataOptions', pinataOptions);

return axios 
    .post(url, data, {
        maxBodyLength: 'Infinity',
        headers: {
            'Content-Type': `multipart/form-data; boundary=${data._boundary}`,
            'Authorization': `Bearer ${JWT}`,
            'pinata_api_key': key,
            'pinata_secret_api_key': secret,
        }
    })
    .then(function (response) {
        console.log("image uploaded", response.data.IpfsHash)
        return {
           success: true,
           pinataURL: "https://blush-defeated-roundworm-642.mypinata.cloud/ipfs/" + response.data.IpfsHash
       };
    })
    .catch(function (error) {
        console.log(error)
        return {
            success: false,
            message: error.message,
        }

});
1
  • we can't really help without looking at your code. Nov 2, 2023 at 8:50

0

Your Answer

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