Polygon: Make a Donation App with IPFS and Polygon
Learn how to create a Web3 donation app using IPFS and Polygon.
What is Polygon?
1. Begin by installing the Truffle NPM package with the following command:
2. Then, create a NextJS app with the commands:
3. Navigate into the newly created application directory and initialize the project:
4. Navigate into the contracts directory and create a new file called DonationContract.sol.
contracts directory and create a new file called DonationContract.sol.
5. Navigate to the migrations directory, then create a new file called 1_initial_migration.js.
migrations directory, then create a new file called 1_initial_migration.js.6. Save this file. Then, navigate back to the contracts directory and create a new file called Migrations.sol.
contracts directory and create a new file called Migrations.sol.7. In the migrations directory, create another new file called 2_donation_contract_migration.js.
migrations directory, create another new file called 2_donation_contract_migration.js.8. Next, install Ganache.

9. Then select ‘Save’ to start your Ganache development blockchain environment.

10. Next, open the truffle-config.js file and replace its existing contents with the following:
truffle-config.js file and replace its existing contents with the following:11. Now it’s time to deploy our Truffle configuration to the Ganache development network with the command:

12. Before moving on with our app, we’ll run a few test scripts. In the tests directory, create a new file called donation-contract-tests.js that contains the following code:
tests directory, create a new file called donation-contract-tests.js that contains the following code:13. Next, install the chai package, which is Truffle’s test script package used in the script above:
chai package, which is Truffle’s test script package used in the script above:14. Then, run the test script with the command:

15. In the root directory of your project, create a new directory called contexts, then create a new file called DataContext.tsx.
contexts, then create a new file called DataContext.tsx.16. Next, open the pages/_app.tsx file and insert the following code:
pages/_app.tsx file and insert the following code:17. For our app’s user interface, we’ll be using the TailwindCSS package. Install it, along with HeadlessUI, with the command:
18. Open the pages/index.tsx file and replace the existing code with the following content:
pages/index.tsx file and replace the existing code with the following content:19. There are three components referenced in this code that don’t exist yet - Body.tsx, UploadImage.tsx, and Header.tsx.
Body.tsx, UploadImage.tsx, and Header.tsx.20. Now, to use the IPFS client, let’s install the IPFS HTTP client package:
21. Lastly, before we can publish this contract, we need to set up authentication through our cryptowallet.
22. Next, create a new file called .secret in the root of your project.
.secret in the root of your project.23. For submitted transactions, you will need some testnet MATIC, which you can get from the Polygon Matic faucet.
24. To cover gas fees, we’ll use the hdwallet-provider package, which can be installed with the command:
hdwallet-provider package, which can be installed with the command:25. Now that we have these configuration details, update your truffle-config.js file with the following:
truffle-config.js file with the following:26. Now it’s time to deploy your donation app’s smart contract to the Polygon Mumbai network with the command:

27. Then, start the web app with the command:
28. The app will be running at localhost:3000. It will look something like this:
localhost:3000. It will look something like this:
29. Select ‘Upload Image’ to upload an image to the application.

30. Select a file from your local computer, provide an optional description, then select ‘Upload’.

Last updated