I am getting the following error.
below is my code, (my actual code has the projectId, projectSecret and subdomain coded into it, i just put xxx’s below for safety measures.
import { useState } from ‘react’;
import { ethers } from “ethers”;
import { Row, Form, Button } from ‘react-bootstrap’;
import { Buffer } from ‘buffer’;
import { create as ipfsHttpClient } from ‘ipfs-http-client’;
// connect to a different API
const projectId = ‘xxxx’;
const projectSecret = ‘xxxx’;
const subdomain = “https://nft-capstone.infura-ipfs.io”;
const authorization = Basic ${Buffer.from(
${projectId}:${projectSecret}).toString('base64')}
;
const client = ipfsHttpClient.create({
host: ‘ipfs.infura.io’,
port: 5001,
protocol: ‘https’,
headers: {
authorization: authorization,
},
});
const Create = ({ market, nft }) => {
const [image, setImage] = useState('')
const [price, setPrice] = useState(null)
const [name, setName] = useState('')
const [description, setDescription] = useState('')
const uploadToIPFS = async (event) => {
event.preventDefault();
const file = event.target.files[0];
if(typeof file !== 'undefined') {
try {
const result = await client.add(file);
console.log(result);
setImage(`${subdomain}/ipfs/${result.path}`);
} catch (error) {
console.log("ipfs image upload error: ", error);
}
}
}
const createNFT = async () => {
if(!image || !price || !name || !description) return
try {
const result = await client.add(JSON.stringify({ image, name, description }))
mintThenList(result)
} catch (error) {
console.log("ipfs uri upload error", error)
}
}
const mintThenList = async (result) => {
const uri = `${subdomain}/ipfs/${result.path}`;
// mint nft
await (await nft.mint(uri)).wait()
// get tokenId of new nft
const id = await nft.tokenCount()
// approve marketplace to spend nft
await( await nft.setApprovalForAll(market.address, true)).wait()
// add nft to marketplace
const listingPrice = ethers.utils.parseEther(price.toString())
await (await market.makeItem(nft.address, id, listingPrice)).wait()
}
im following this tutorial someone had a similiar issue and im following the solution provided but still get an error