Building An Ethereum and IPFS-based Decentralized Social Network System
Building An Ethereum and IPFS-based Decentralized Social Network System
Quanqing Xu∗ , Zhiwen Song† , Rick Siow Mong Goh∗ , Yongjun Li‡
∗ Institute
of High Performance Computing, A∗ STAR, Singapore
† School
of Computing, National University of Singapore
‡ School of Computer, Northwestern Polytechnical University
Abstract—Evolvement of blockchain technology has greatly to the government intervention and censorship based on the
changed the network and it makes many applications to be IPs used by the social media servers. Some have raised the
distributed, decentralized without loss of security. Ethereum is point that blockchain technology can be used to tackled some
an open-source blockchain platform that provides a runtime en- of the issues existing in the industry. Blockchain technology
vironment for running smart contracts, which is called Ethereum enables decentralization and security for the social media
Virtual Machine (EVM). Ethereum-based applications are usually
services, which make it available during server downtime or
referred to as Decentralized Applications (DApps), since they
are based on the decentralized EVM, and its smart contracts. even against censorship from governments or Internet Service
Meanwhile, distributed data store also evolves fast with the Providers (ISPs). In this paper, an application is developed to
blockchain technology. Distributed storage develops to reduce the prove the possibility of incorporating blockchain technology
cost of the server side hardware and increase data availability. into social media network to empower it against existing
InterPlanetary File System (IPFS) is a protocol for distributed problems.
storage. IPFS stores immutable data, remove duplication, and
obtain address information for storage nodes to search for files We use social media industry for our experiment to
in the network. Many DApps have been created with the use of demonstrate the capability of blockchain to enhance other
these technologies and one example is to use this design for a existing industry. In this paper, we propose a social media
decentralized Twitter-like system that is resistant to censorship application based on Ethereum platform [5] for recording data
and single point of failure. This paper involves researching the and use InterPlanetary File System (IPFS) [6] as distributed
blockchain technology and implementing a decentralised social data storage service to support a decentralized application. The
network application on the Ethereum private blockchain with social media application uses a frontend webpage UI to interact
the use of smart contract and IPFS. In addition, it examines how with users and save users’ information on blockchain while
blockchain and distributed storage can enable more functionali-
ties of traditional social network systems.
storing the larger file data in the IPFS system. The purpose of
developing this application is to give an brief idea about how
blockchain technology can be used to enhance the existing
I. I NTRODUCTION industry. Relevant smart contracts have been developed to
Since Satoshi Nakamoto introduced Bitcoin to the demonstrate the usage of blockchain to record data including
world [1], blockchain technology has gained increasing popu- the social media messages from the users. This is a system
larity over the past few years. Blockchain begins with the core prototype and further improvement on the system prototype is
technology as a distributed ledger supporting cryptocurrency necessary to make it a holistic application.
exchanges and has shown capability for even other sectors or The remainder of this paper is organized as follows: In
areas as a secure, immutable and reliable platform to record Section II, we give the background of this system. Section III
data and transactions. Social network services, e.g., Facebook describes overall design structure. Section IV shows system
and Twitter, have already become part of our daily life and have deployment and demo. Section V reviews the related work.
a significant number of users across the world. There was a Section VI concludes this paper.
data leakage issue from Facebook to Cambridge Analytica [2],
which brought the security and privacy issues of social media II. BACKGROUND
to a higher level. Many researches and discussions have been
running through to seek appropriate solution to tackle the In this section, we discuss some concepts and tools used
problems existing currently in the social media services. in our system.
Currently, the main problems challenging the social media A. Blockchain
networks [3] include many aspects. Due to the traditional
client-server model, social media clients often suffer from Blockchain is a chain or list of blocks. Each block in
unavailable service during server downtime or when server the blockchain has its own digital signature or cryptographic
faces issues of single point of failure or DDoS attacks. For hash, which contains digital signature of the previous block,
example, Bitcoin blockchain was used to provide decentralized and it has data including state data and transaction data. Each
content trust for docker images to resist potential threats in block is generated within a specific epoch (i.e., period of time)
docker content trust [4]. Besides that, it is well known that and pointed towards its parent in the blockchain, forming a
social media services are not available in some countries due long chain of hashed blocks. Ethereum is a blockchain-based
987
blockchain system for function call, contract deployment and When the client wants to update the tweets from the follows
fund transfer. IPFS library is triggered when user posts tweet (see Figure 5), it will first retrieve all the tweets from the User
with picture or video that is stored in IPFS data storage, and contract, currently Solidity does not support return of complex
receives an IPFS hash in return. data structure including array and struct. In this case the logic
for retrieval of tweets from all the follows is handled in the
frontend. Frontend client will retrieve the follow address list
C. Application design and request for the latest tweet for each of the follow.
The whole system consists of three main components, hƐĞƌŽŶƚƌĂĐƚ
namely backend private blockchain, IPFS storage and frontend
web UI. When client starts and user attempts to register or
login as shown in Figure 3, it will first check if current account Ϯ͘ZĞƚƵƌŶƚǁĞĞƚƐ
address has already created a User contract by calling function ĚĂƚĂ
from AccountManager contract, if a valid contract address is
returned, it will take it as a valid User contract address, else ϯ͘^ĞŶĚ/W&^
ϭ͘'ĞƚůĂƚĞƐƚ ƌĞƋƵĞƐƚ ϰ͘ZĞƚƌŝĞǀĞ
a 0x0 address is returned, meaning that the current account ƚǁĞĞƚƐĨƌŽŵ
has not initialized a User account in the blockchain. In this ƉŝĐƚƵƌĞ
ĨŽůůŽǁƐ ĨƌŽŵ/W&^
case, client frontend will send a transaction to the blockchain
to deploy a User contract for the current account.
hƐĞƌŽŶƚƌĂĐƚ ĐĐŽƵŶƚDĂŶŐĞƌŽŶƚƌĂĐƚ
Fig. 5. Workflow for update
ŐĞƚ&ŽůůŽǁĚĚƌĞƐƐ;Ϳ
ϭ͘^ĞŶĚƉŝĐƚƵƌĞ
ƚŽ/W&^ Fig. 6. User smart contract
ϯ͘^ĞŶĚƚǁĞĞƚ Ϯ͘ZĞƚƵƌŶ/W&^
ƚƌĂŶƐĂĐƚŝŽŶƐ ŚĂƐŚĨŽƌ The User contract also includes functions for checking the
ƚŚĞƉŝĐƚƵƌĞ status of the follows and their tweets. Currently, user can get
the number of the follows via getNumFollow function and get
the follow’s address via getFollowAddress function. Regarding
the tweets, users can always check their number of tweet
by calling getNumTweet function. So far, the functionalities
Fig. 4. Workflow for posting tweet proposed for user is still at a very simple stage, later more
988
&ƌŽŶƚŶĚ h/;ZĞĂĐƚ:ƐͿ
ZĞŐŝƐƚĞƌͬůŽŐŝŶͬ dƌĂŶƐĂĐƚŝŽŶ ^ĂǀĞĨŝůĞͬ ZĞƚƵƌŶ/W&^ŚĂƐŚͬ
ƉŽƐƚƚǁĞĞƚ ƌĞƐƵůƚͬƌĞĐĞŝƉƚ ƌĞƚƌŝĞǀĞĨŝůĞ ĨŝůĞďLJƚĞĐŽŶƚĞŶƚ
tĞďϯ>ŝďƌĂƌLJ /W&^>ŝďƌĂƌLJ
ƐĞŶĚdƌĂŶƐĂĐƚŝŽŶ /W&^ƌĞƋƵĞƐƚ
ĐĐŽƵŶƚ
hƐĞƌ DĂŶĂŐĞƌ /W&^^ƚŽƌĂŐĞ
ƚŚĞƌĞƵŵ sŝƌƚƵĂůDĂĐŚŝŶĞ
ƚŚĞƌĞƵŵ ůŽĐŬĐŚĂŝŶ
functionalities will be added, including commenting for the retrieve the latest tweet from the ones the user is following.
tweet, retweeting, reporting and “Like” functions. All the tweets and followers addresses will be stored in their
User smart contract.
As shown in Figure 7, AccountManager contract includes
a mapping data structure from client account address to User
contract address. This is to ensure that each client account
is only created once, and to avoid any problems caused.
AccountManager includes register and retrieve functions such
that each User contract is able to bind its address with account
address and be retrieved for later reusage. When a User
contract is created, the client will call the register function
such that the newly created User contract address and current
client contract address are stored in the mapping. Later when
login, after authentication, the client will be able to retrieve
the User contract address by calling Retrieve function.
ĐĐŽƵŶƚDĂŶĂŐĞƌ ŽŶƚƌĂĐƚ
Fig. 8. System Demo
hƐĞƌƐ͗ŵĂƉƉŝŶŐ;ĂĚĚƌĞƐƐсхĂĚĚƌĞƐƐͿ
After successful login or registration, a contract address
will be displayed and status will be updated to be successfully
login. When the users post tweets to the User contract, they can
ZĞŐŝƐƚĞƌ;Ϳ ZĞƚƌŝĞǀĞ;Ϳ
send pictures together with their tweets, and pictures are sent
to IPFS file storage and stored as IPFS hash in the contract.
After that, when the user wants to retrieve the tweet from their
Fig. 7. AccountManager contract follows, they can click the Update button and when retrieving
the tweets, the picture will be fetched in the frontend React
application from the IPFS storage using the hash stored in the
E. UI Design contract.
We use ReactJs as the frontend framework to call relevant
Web3 API so as to interact with the private blockchain running IV. S YSTEM D EPLOYMENT AND D EMO
on machines. This entire social media DApp follows a similar A. Set up Private blockchain
style as Twitter where users can follow/unfollow others, post
tweets and receive the tweets from the ones they are following. Currently Ethereum provides three types of Ethereum
For simplification purpose, in this simple system, we only clients, namely cpp-ethereum, go-ethereum and py-ethereum.
989
Any of the clients is able to be used in initializing a private D. Configure the frontend client
blockchain. In the example, go-ethereum is used for demo
purpose. To create an Ethereum private blockchain, we first We need to set certain environmental variables before the
install the Ethereum client, geth using the following command start of the program, which include the IPFS endpoint, Ethre-
(or any other commands depends on the OS used, here the rum endpoint, contract Application Binary Interface (ABI),
command provided is for Linux system, for Mac users, Geth AccountManager contract address and User contract bytecode
can be simply installed via Homebrew). A genesis block is (if modified). We set the AccountManager contract address in
shown in Figure 9. the frontend source code as follows:
ManagerContract.options.address =
^ ’0xBF35ebb108a70A092CF63F4ae1F1C552edC5F23e’;
FRQILJ^ We set the IPFS configuration in ipfs.js that depends on
FKDLQ,G the current configuration. Both public free space and private
KRPHVWHDG%ORFN local configuration are provided, switch if needed.
HLS%ORFN
FRQVW ,3)6 UHTXLUH
LSIVDSL
HLS%ORFN FRQVW LSIV QHZ,3)6^KRVW
LSIVLQIXUDLR
SRUWSURWRFRO
KWWSV
`
` UXQZLWKORFDOGDHPRQ
GLIILFXOW\[ FRQVW LSIV$SL UHTXLUHþLSIVDSLÿ
FRQVW LSIV QHZLSIV$SLþORFDOKRVWÿþÿ^SURWRFROþKWWSÿ`
JDV/LPLW[VHWWKLVUHDOO\KLJKIRUWHVWLQJ
DOORF^` Fig. 10. IPFS configuration
`
C. Deploy the AccountManager Contract They have provided detailed explanation on how to build a
decentralized application with the use of Ethereum platform,
Since AccountManager contract is a permanent contract web3.js library and ReactJs as the frontend. This provides
used for logging the User contract address, it is initialized a brief understanding of how these components can come
separately. Here we can initialize it either with Mist client, together to build a successful DApp. Meanwhile, they also
Remix Web tool, Geth javascript console or any other means. provide explanation for other concepts including IPFS system
Details are not listed here. After setting up the AccountMan- which is currently used in the social media application in this
ager contract, we can retrieve its contract address for later use. paper. They provide a lot of insights and tips on setting up a
The account address can be seen from the Mist client if it is private blockchain and make the entire DApp works at a ready
created from Mist client or Geth javascript console. state.
990
VI. C ONCLUSIONS AND F UTURE W ORK ɋɥŜɫŜɩɨŚ
Ƈ
This system prototype is done for the purpose of system ƃƄŚ
Ś
implementation according to the knowledge learnt through the ƃƄŚ
Ƈ
research. The whole system still remains on the prototype or
Ś
proof-of-concept stage and should not be used for production Ś
Ś
purpose. This system prototype has demonstrated the idea ƈ
of using IPFS and smart contracts together on the Ethereum ſƀƇ
blockchain and further work needs to be done to examine the ſŜ ʰʰƀŚ
ɏŚ
performance and improve the smart contract based on the real ƈ
done to beautify the UI of the application and re-arrange the
ſɏƀ
Ƈ
ŜſɏƀŚ
components on the web page to make it more logical. ƈ
991