Giter VIP home page Giter VIP logo

icblog's Introduction

IC BLOG sample app

This project was created as a sample app for the Internet Computer so new developers in the ecosystem have some working examples to learn from.

It is a simple blog site that allows authenticated users to create, read, update and delte blog posts.

You can try running version of this project on this link: https://gaqra-oqaaa-aaaah-qc4qa-cai.ic0.app

Backend

The project consist of a backend written in Motoko programming language, that has been designed specifically for writing smart contracts on the Internet Computer Protocol. You can find backend code in the canisters/blog/main.mo file.

Backend defines a Post type, HashMap as a database and methods for CRUD interace. There are also functions for filtering only published posts and sorting posts in the right order.

Frontend

Front-end is written in the Svelte framework. There are Routes for Create, Read, Update, Delete, List posts. You can find it in the frontend/routes directory.

It should give a quick start to anyone thinking about starting it's own blog site on the Internet Computer or just want to learn how to create a simple dapp.

I use Svelte starter app created by @miamaruq, he also created starter apps for React, Vue or TS. If you want to use different toolkit, you can follow his repository. This starter app also utilizes the Connect2IC toolkit that simplifies the process of wallet connection for different wallet providers.

Local deployment

We assume that you have:

Once you have cloned the repository, follow this process in your terminal:

  1. In your project directory, run this command to install JS dependencies:
$ npm install
  1. Start local Internet Computer replica (or open a new terminal window and run it without the --background parameter):
$ dfx start --background 
  1. Deploy your canisters locally:
$ dfx deploy
  1. Run local dev server:
$ npm run dev

You should see a localhost URL looking like this "Local: http://localhost:3000/" in your terminal. Open this in your web browser and see the app running.

Canisters are working in anonymous mode for local development. In production, we want create/update/delete methods to be allowed only for not anonymous users. This happens automatically based on global env variable in the frontend:

const [blog] = process.env.NODE_ENV == "production" ? useCanister("blog") : useCanister("blog", { mode: "anonymous" })

In the backend, this part of code is currently commented for local development:

if(Principal.isAnonymous(msg.caller)){ // Only allows signed users to create a posts
    return #err(#UserNotAuthenticated); // If the caller is anonymous Principal "2vxsx-fae" then return an error
};

Deploy to the mainnet

If you have working local development replica, you can deploy your project to the mainnet by running this command:

$ dfx deploy --network ic

You are going to need a cycles wallet. Go through this tutorial to make it working.

Footnote

This project was created by Lukas Vozda, big Dfinity supporter. If you want to reach out to me and ask some qustion here are my social network handles:

  • @lukas on Open Chat
  • @lukas_icp on Twitter

icblog's People

Contributors

lukasvozda 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.