|
1 | | -# Store IPFS Files on Filecoin: A Drag-and-Drop Guide |
| 1 | +# Filecoin Pin dApp Demo |
2 | 2 |
|
| 3 | +## What You'll Build |
| 4 | + |
| 5 | +In this walkthrough, you’ll build a simple drag-and-drop file uploader that: |
| 6 | + |
| 7 | +- Stores IPFS files directly on Filecoin with built-in payments, all in browser! |
| 8 | +- Tracks real-time upload progress through each step |
| 9 | +- Retrieves data easily from IPFS Mainnet and the underlying Filecoin Service Provider |
| 10 | +- Verifies persistent storage with on-chain Filecoin proofs |
| 11 | +- Multi-user support with session-based authentication |
| 12 | +- Seamlessly integrates with React, TypeScript, and Vite |
| 13 | + |
| 14 | +## Setup |
| 15 | + |
| 16 | +We will start building by [forking the *filecoin-pin-website demo repo](https://github.com/filecoin-project/filecoin-pin-website/fork).* Make sure you have **Node.js 18+** and **npm 9+** installed. The dapp works with Filecoin Calibration testnet. |
| 17 | + |
| 18 | +This will take ~10min. ⏲️ |
| 19 | + |
| 20 | +### Step 1: Fork, Clone, and Install Dependencies |
| 21 | + |
| 22 | +```bash |
| 23 | +# Fork the repo using the command below |
| 24 | +# or visit [https://github.com/filecoin-project/filecoin-pin-website/fork](https://github.com/filecoin-project/filecoin-pin-website/fork) |
| 25 | +gh repo fork filecoin-project/filecoin-pin-website |
| 26 | + |
| 27 | +git clone https://github.com/YOUR-USERNAME/filecoin-pin-website.git |
| 28 | +cd filecoin-pin-website |
| 29 | +npm install |
| 30 | +``` |
| 31 | + |
| 32 | +### **Step 2: Set Up Your Filecoin Wallet** |
| 33 | + |
| 34 | +A Filecoin wallet is needed to send transactions on Filecoin and pay for the Filecoin storage service. |
| 35 | + |
| 36 | +This demo dapp supports two authentication methods: |
| 37 | + |
| 38 | +- **Private Key:** easiest for local development and learning. |
| 39 | +- **Session Key:** recommended for production deployments - allows multiple users to share one wallet safely. |
| 40 | + |
| 41 | +💡 The demo repo supports deployment with a shared session key, allowing multiple users to safely upload files using the same wallet. It has hardcoded DEFAULT_WALLET_ADDRESS and DEFAULT_SESSION_KEY that are ready to go, but please do NOT use it for production. You can override these defaults with env vars, see instructions [here](https://github.com/filecoin-project/filecoin-pin-website/blob/main/CONTRIBUTING.md#local-setup)! |
| 42 | + |
| 43 | +**2.1 Get test FIL and test USDFC** |
| 44 | + |
| 45 | +If you are using your own wallet, you need to get test FIL and test USDFC to pay for the Filecoin storage service and transactions. |
| 46 | + |
| 47 | +1. Create or use an existing Filecoin wallet on the ****Calibration testnet**** ([such as MetaMask](https://docs.filecoin.io/basics/assets/metamask-setup#tab-calibration)). |
| 48 | + |
| 49 | +2. Visit the [Filecoin Calibration Faucet](https://faucet.calibnet.chainsafe-fil.io/funds.html) to get free test FIL (to pay for transaction gas). |
| 50 | + |
| 51 | +3. Visit the [Filecoin USDFC faucet]([https://forest-explorer.chainsafe.dev/faucet/calibnet_usdfc](https://forest-explorer.chainsafe.dev/faucet/calibnet_usdfc?__cf_chl_tk=qFwEfa7MNFkJlhKo32IUtR9rgP99qqf_XOmTs7qhusg-1758703656-1.0.1.1-gE8b6EQEmdp0lgg0gk5j2UZhF_69vRyYAAhtt..weyA)) to get test USDFC, which is a USD stable coin backed by FIL that can be used to pay for services. |
| 52 | + |
| 53 | +### **Step 3: Run Your dApp** |
| 54 | + |
| 55 | +Fire up your local development server: |
| 56 | + |
| 57 | +```bash |
| 58 | + npm run dev |
| 59 | +``` |
| 60 | + |
| 61 | +Visit `http://localhost:5173` and you should see your dApp running! That is all it takes to set up your app. Now, let’s upload a file to see the magic happen! |
| 62 | + |
| 63 | +## Store IPFS Files on Filecoin |
| 64 | + |
| 65 | +The magic happens in one key file [**`src/hooks/use-filecoin-upload.ts`**](https://github.com/filecoin-project/filecoin-pin-website/blob/main/src/hooks/use-filecoin-upload.ts). This is where your IPFS files get uploaded to Filecoin. |
| 66 | + |
| 67 | +### Step 1: Upload the data |
| 68 | + |
| 69 | +- **Prepare Service** - Validates wallet balance and gets the Filecoin Warm Storage service initialized. |
| 70 | +- **Create CAR** - Converts your file to an IPFS CAR (Content Addressed aRchive) file. |
| 71 | +- **Upload** - Sends the CAR file to a Filecoin Storage Provider (SP). |
| 72 | + |
| 73 | +  |
| 74 | + |
| 75 | +### Step 2: Announce CIDs and confirm the transaction |
| 76 | + |
| 77 | +The Filecoin SP: |
| 78 | + |
| 79 | +- indexes the IPFS CAR file and publishes all the contained CIDs to the IPFS network via IPNI. |
| 80 | +- commits to the Filecoin network via onchain transactions to store the data. Once the transaction is confirmed, your data is paid to be persisted on Filecoin. |
| 81 | + |
| 82 | +  |
| 83 | + |
| 84 | + |
| 85 | +### Step 3: Download the data |
| 86 | + |
| 87 | +Your data is available from both the IPFS Mainnet network using standard traditional IPFS tooling and/or directly from Filecoin SPs. |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +### **Step 4: Verify your data storage** |
| 92 | + |
| 93 | +Filecoin storage providers submit cryptographic proofs regularly onchain to prove that they are storing your data, and you can verify and see it for yourself [on the PDP Scan](https://pdp.vxb.ai/calibration). |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +That is it - you now have a dapp with a drag-and-drop interface to store IPFS Files on Filecoin! |
| 98 | + |
| 99 | +# Next Steps |
| 100 | + |
| 101 | +1. Check back on the [filecoin-pin-website repo](https://github.com/filecoin-project/filecoin-pin-website) - it will continue to be updated as new functionality is brought to filecoin-pin. |
| 102 | +2. Feel free to report any issues with the dApp demo to https://github.com/filecoin-project/filecoin-pin-website/issues |
| 103 | +3. Check out the the [other example uses of filecoin-pin](../). |
| 104 | +4. Ask questions or get help with filecoin-pin in the [supported communcation channels](https://github.com/filecoin-project/filecoin-pin?tab=readme-ov-file#support-info). |
0 commit comments