project screenshot 1
project screenshot 2
project screenshot 3

DecentraBlog

A simple blogging website on Polygon (Matic). The dapp allows users to visualize their name, biography and the feed of all the posts. The user can also publish posts.

DecentraBlog

Created At

Road to Web3

Winner of

trophy

🏊 Polygon Pool Prize

Project Description

A simple blogging website on Polygon (Matic). The dapp allows users to visualize their name, biography and the feed of all the posts created by other bloggers. The user can also publish posts.

We used polygon specifically because it is a blogging platform, hence we want our users to have feasible experience. And further we are planning to extend the project with the help of moralis and bring tipping for creators and making posts and highlighted comments as NFTs. Moreover we will cutt off the gas fees by Implementation of monetization of famous bloggers and creating a business model that revolves around seamless user experience.

How it's Made

Smart contracts are written in solidity and for front-end we have used react.js. In the smart contract we need two structs to define the structure of the data we want to store. The first one will contain the user information and the second one the post information. Mapping in Solidity acts like a hashtable or dictionary in any other language. These are used to store the data as key-value pairs. We create 2 mapping, an address to User data and a postId to post Info. With the mapping, we can access post data such as title or content with the id as key.

Add the post id that we can increment and assign to each new post. When the function is called, it creates a new post and pushes a unique incremental Id into the array used in the mapping for posts. Then we push the id of the post to the users mapping for the caller of the function (msg.sender) so later we can track all the posts created by that writer.

With require, we can restrict to only the writer of the post who can edit his posts. The caller can customize his profile by changing the username and the biography. To get the posts data we have created 2 functions. One gets an array of all the post Ids created by the same address. Another to get the post Id content. For the getPostById, we can access directly through the mapping posts variable as we declared it as public. We declare the event to be triggered. you can see the events of the smart contracts on Polyscan mumbai, in the events section.

background image mobile

Join the mailing list

Get the latest news and updates