Giter Site home page Giter Site logo

kaymen99 / ipfs-storage-dapp Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 9.0 601 KB

An Ethereum/Polygon Dapp for decentralized storage & web hosting on IPFS

License: MIT License

Solidity 14.14% Python 21.29% HTML 4.80% CSS 6.16% JavaScript 53.61%
solidity dapp smart-contracts brownie decentralized-storage ipfs web-hosting web3 web3-solidity

ipfs-storage-dapp's Introduction

IPFS storage Dapp

Capture d’écran 2023-05-19 à 01 46 07

This is a decentralized application built on the Ethereum/Polygon blockchain, it works like Dropbox or Google Drive by allowing users to securely store their files on the blockchain using IPFS Technology

Built With

Table of Contents
  1. Getting Started
  2. Usage
  3. Resources
  4. Contact
  5. License

Getting Started

Prerequisites

Please install or have installed the following:

Installation

  1. Installing Brownie: Brownie is a python framework for smart contracts development,testing and deployments. It's quit like HardHat but it uses python for writing test and deployements scripts instead of javascript. Here is a simple way to install brownie.

     pip install --user pipx
     pipx ensurepath
     # restart your terminal
     pipx install eth-brownie
    

    Or if you can't get pipx to work, via pip (it's recommended to use pipx)

    pip install eth-brownie
    

    Install ganache-cli:

     npm install -g ganache-cli
  2. Clone the repo:

    git clone https://github.com/kaymen99/ipfs-storage-dapp.git
    cd ipfs-storage-dapp
  3. Install Ganache: Ganache is a local blockchain that run on your machine, it's used during development stages because it allows quick smart contract testing and avoids all real Testnets problems. You can install ganache from this link : https://trufflesuite.com/ganache/

    Next, you need to setup the ganache network with brownie :

    cd ipfs-storage-dapp
    brownie networks add Ethereum ganache-local host=http://127.0.0.1:7545 chainid=5777
  4. Set your environment variables To be able to deploy to real Polygon testnets you need to add your PRIVATE_KEY (You can find your PRIVATE_KEY from your ethereum wallet like metamask) to the .env file:

    PRIVATE_KEY=<PRIVATE_KEY>
    

    In this project i used the Polygon Testnet but you can choose to use ethereum testnets like rinkeby, Kovan.

    To setup the Polygon Testnet with brownie you'll need an Alchemy account (it's free) and just create a new app on the polygon network

    Capture d’écran 2022-01-25 à 00 14 44

    After creating the app copy the URL from -view key- and run this:

    cd ipfs-storage-dapp
    brownie networks add Polygon polygon-mumbai host=<Copied URL> chainid=80001 name="Mumbai Testnet (Alchemy)"

    You'll also need testnet MATIC. You can get MATIC into your wallet by using the Polygon testnet faucets located here.

  5. As infura recently removed its free IPFS gateway i used web3.storage api for files into IPFS, this api is as simple as infura it requires the creation of a free account and a new api token which you can do here, when you finish add your api token into the src/utils/StoreContent.js file:

     const web3storage_key = "YOUR-WEB3.STORAGE-API-TOKEN";

(back to top)

Usage

Contracts

In the ipfs-storage-dapp folder you'll find a directory contracts, all the smart contracts build in brownie are stored there. The FileStorage contract is the core of this application, it plays the role of the backend and has the following features:

  • SetUploadFee: for every file uploaded the user must pay a small fee set by the owner of the contract
  • Upload: allows the user to upload his file
  • getUserFiles: a function for getting all the files uploaded by a given user
  • Chainlink Price Feed: the contract uses the price feed provided by chainlink oracle for converting the fee set by the owner from $ to MATIC

(back to top)

Scripts

In the ipfs-storage-dapp folder you'll find a directory scripts, it contain all the python code for deploying your contracts and also some useful functions

The reset.py file is used to remove all previous contracts deployments from build directory:

brownie run scripts/reset.py

The deploy.py file allow the deployment to the blockchain, we'll use the local ganache for now:

brownie run scripts/deploy.py --network=ganache-local

The update_front_end.py is used to transfer all the smart contracts data (abi,...) and addresses to the front end in the artifacts directory:

brownie run scripts/update_front_end.py

After running this 3 cammands, the FileStorage contract is now deployed and is integrated with the front end

(back to top)

Testing

In your ipfs-storage-dapp folder you'll find a directory tests, it contain all the python code used for testing the smart contract functionalities

You can run all the tests by :

brownie test

Or you can test each function individualy:

brownie test -k <function name>

(back to top)

Front-end

The user interface of this application is build using React JS, it can be started by running:

cd front-end
yarn
yarn start

It uses the following libraries:

  • Ethers.js: for conecting to Metamask and interacting with smart contract
  • ipfs-http-client: for connecting and uploading files to IPFS
  • @reduxjs/toolkit: for managing the app states (account, balance, blockchain)
  • Material UI: used for react components and styles

The files are structured as follows:

  • Components: Contains all the app component(main, navbar, filestorage,...)
  • features: contains the redux toolkit reducer and actions
  • artifacts: contains all the smart contract data and addresses transfered earlier
  • NetworksMap: a json file for some known blockchains names & chain id

(back to top)

Resources

To learn about Smart Contract and Brownie:

(back to top)

Contact

If you have any question or problem running this project just contact me: [email protected]

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

ipfs-storage-dapp's People

Contributors

kaymen99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.