Blogchain

A blog on the Ethereum blockchain

Jason Stallings
Jay Hill
Nick McDonnough
Jason Noble

What is a blockchain?

For real though

A distributed, public ledger of transactions stored in immutable, increments called "blocks." In order to create a block, a computational challenge must be completed which is time consuming to compute, but quick to verify. The process of generating new blocks is called "mining." Each block contains data that represents a set of transactions.

Overly simple diagram

What is Ethereum?

Builds on the ideas of the Bitcoin blockchain and adds the Ethereum Virtual Machine (EVM) which allows smart contracts to be stored on the blockchain and executed as transactions.

Smart contract


pragma solidity ^0.4.4;

contract Blog {
  address owner;

  // Constructor.
  function Blog() { owner = msg.sender; }

  // Function to kill the contract.
  function kill() { if (msg.sender == owner) selfdestruct(owner); }

  struct BlogPost {
    bytes32 title;
    // Dynamic length strings are hard in Solidity, so we have to use a byte array.
    bytes32[32] content;
    address author;
  }

  BlogPost[] public BlogPosts;

  function addBlogPost(bytes32 title, bytes32[32] content) public returns (uint) {
    return BlogPosts.push(BlogPost(title, content, msg.sender)) - 1;
  }

  function getBlogPostsCount() public constant returns(uint) {
    return BlogPosts.length;
  }

  function getBlogPostTitle(uint index) public returns(bytes32) {
    return BlogPosts[index].title;
  }

  function getBlogPostContent(uint index) public returns(bytes32[32]) {
    return BlogPosts[index].content;
  }

  function getBlogPostAuthor(uint index) public returns(address) {
    return BlogPosts[index].author;
  }
}
        
100% coverage!

Why host a blog on a blockchain?

  • No single point of failure
  • Difficult to takedown or censor
  • Content cannot be altered

IPFS

InterPlanetary FileSystem - https://ipfs.io/

IPFS is a distributed file system that seeks to connect all computing devices with the same system of files. In some ways, this is similar to the original aims of the Web, but IPFS is actually more similar to a single bittorrent swarm exchanging git objects.

What we built

React.js application built with TypeScript that interacts with our Ethereum smart contract, implemented in Solidity using the truffle framework.

Interesting learnings

  • Attempting to brute force system costs currency
  • Writing blockchain-based apps is mostly "regular boring JavaScript"

Demo!

  • Create post
  • View post
  • View posts by author
  • Access posts via IPFS

Questions?