DEV Community

Cover image for pinata-whiteBoard
KUNDAN SOLANKI
KUNDAN SOLANKI

Posted on

3 4 3 3 3

pinata-whiteBoard

This is a submission for the The Pinata Challenge

What I Built

I built a collaborative whiteboard application called "Pinata Whiteboard" using React and Pinata IPFS services. This application allows users to draw, upload images, save their whiteboards to IPFS, and even mint their creations as NFTs

Demo

Image description

Image description

My Code

https://github.com/KUNDAN1334/pinata-whiteboard

More Details

Here are clear examples of how I used Pinata in my project:

1.Image Upload: When a user uploads an image to the whiteboard, it's stored on IPFS using Pinata's pinning service.

const handleImageUpload = async (file) => {
  const cid = await uploadFile(file);
  const url = getFileUrl(cid);
  canvasRef.current.addImage(url, 0, 0, width, height);
};
Enter fullscreen mode Exit fullscreen mode

2.Saving Whiteboards: Users can save their whiteboards to IPFS, storing the entire whiteboard state.

const handleSave = async () => {
  const whiteboardData = canvasRef.current.getWhiteboardData();
  const cid = await saveWhiteboard(whiteboardData);
  alert(`Whiteboard saved! CID: ${cid}`);
};

Enter fullscreen mode Exit fullscreen mode

3.Loading Whiteboards: Users can load previously saved whiteboards from IPFS.

const handleLoad = async (cid) => {
  const whiteboardData = await loadWhiteboard(cid);
  canvasRef.current.loadWhiteboardData(whiteboardData);
};
Enter fullscreen mode Exit fullscreen mode

4.Listing Saved Whiteboards: The application fetches and displays a list of saved whiteboards using Pinata's Pin List API.

const listWhiteboards = async () => {
  const response = await axios.get(
    'https://api.pinata.cloud/data/pinList?status=pinned',
    {
      headers: {
        pinata_api_key: PINATA_API_KEY,
        pinata_secret_api_key: PINATA_SECRET_API_KEY,
      },
    }
  );
  return response.data.rows.filter(pin => pin.metadata.name === 'Whiteboard');
};

Enter fullscreen mode Exit fullscreen mode

5.NFT Minting: Users can mint their whiteboards as NFTs, storing both the image and metadata on IPFS using Pinata.

const handleMint = async (e) => {
  e.preventDefault();
  const imageBlob = await getWhiteboardImage();
  const imageCID = await uploadFile(new File([imageBlob], 'whiteboard.png'));
  const metadata = {
    name,
    description,
    image: `ipfs://${imageCID}`,
  };
  const metadataCID = await mintNFTMetadata(metadata);
  alert(`NFT minted successfully! Metadata CID: ${metadataCID}`);
};

Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay