• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Shell
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This repository demonstrates the eosio platform running a blockchain as a local single node test net with a simple DApp, NoteChain.

⚠️ Important! Since Jan 1st 2019, eosio/eos-dev docker image in docker hub is deprecated. Starting from that time, eosio-project-boilerplate-simple is building its own docker image based on eos and eosio.cdt instead of pulling eosio/eos-dev. ⚠️

Overview

NoteChain demonstrates the eosio platform running a blockchain as a local single node test net with a simple DApp, NoteChain. NoteChain allows users to create and update notes. This guide uses scripts, containing relevant commands, which will show you how to install, build and run NoteChain, and by doing so will demonstrate:

  • Downloading and running eosio in docker;
  • Managing your docker container;
  • Setting up and running a local single node testnet;
  • Setting up wallets, keys, and accounts;
  • Writing and deploying a smart contract;
  • Implementing a web based UI using React;
  • Connecting the UI to the blockchain using eosjs;
  • Styling the UI using Material-UI.

Github eosio-project-boilerplate-simple (https://github.com/EOSIO/eosio-project-boilerplate-simple) contains the UI and Smart Contract code, as well as setup scripts which will initialise and start all the necessary components.

The sample DApp demonstrates storing data in multi index table and retrieving this data into the web based UI. NoteChain is a simple note taking application, where notes are tied to user accounts. For this example, all accounts are pre-created by scripts and the account details are displayed at the bottom of the NoteChain UI.

Each account can then be used to add a note to the blockchain. The individual notes are saved in a multi-index table and for simplicity are of fixed width. Each account may have one note attached to it, adding a note to an account with an existing note will replace the existing note with a new note.

Any private keys you see in this repository are for demo purposes only. For a real DApp NEVER expose the private keys.

Prerequisites

Make sure Docker and Node.js are installed

The DApp and eosio will occupy the ports 3000, 8888 and 9876. Make sure nothing else is already running on these ports.

Clone the repository:

git clone https://github.com/EOSIO/eosio-project-boilerplate-simple.git

The following guide assumes you are using macOS.

Quick start - Run the DApp

In this section we provide a single command script to run all the commands needed to start both the blockchain and UI. For more detail on each component see the Detailed guide below.

To start

./quick_start.sh

The above command will execute the following in sequence:

  1. first_time_setup.sh
  2. start_eosio_docker.sh
  3. start_frontend.sh

To stop, press ctrl+c on your keyboard, and execute:

docker stop eosio_notechain_container

Detailed guide

In this section we will describe in detail each script used to run the NoteChain environment in details.

Initial setup

./first_time_setup.sh

Executing the above shell script verifies that docker and node.js are installed. It then builds eosio-notechain docker image if it has never been built before (which contains a full version of the eosio blockchain), removes any previous instances of this docker container and installs node packages for the frontend react app.

Initialise and start blockchain and DApp

After the initialisation, two terminal windows are required, both opened in the repository directory

  • The first terminal window is for blockchain process.
  • The second terminal window is for frontend react app.

running the blockchain

For the first (blockchain) terminal window, running

./start_eosio_docker.sh

will:

  • Start the eosio blockchain
  • Create smart contract owner account,
  • Deploy smart contract
  • Pre-create 7 user accounts with hard coded keys.

The log of blockchain will be displayed on your screen. eosio is now running and starts producing blocks.

running the DApp

For the second (frontend) terminal window, running

./start_frontend.sh

will open a browser session connecting to http://localhost:3000/ showing the react app. You can try to add or remove notes using one of the pre-created accounts with its key on the website. This react app will interact with the smart contract, performing transactions, which are written to the blockchain, which stores note data in the multi index table of the smart contract running on your local nodeos.

Stopping blockchain or DApp

stopping the blockchain

In the first (blockchain) terminal window, press ctrl+c on your keyboard, the log will stop printing. And then execute:

docker stop eosio_notechain_container

This action will take a few seconds. The blockchain will be stopped.

stopping the DApp

In the second (frontend) terminal window, press ctrl+c on your keyboard. The frontend react app will be stopped.

Restarting blockchain or DApp

restarting the blockchain

In the first (blockchain) terminal window, execute this command:

./start_eosio_docker.sh

The blockchain will be resumed automatically and the log will be outputted to the terminal.

restarting the DApp

In the second (frontend) terminal window, you can restart the frontend react app by executing:

./start_frontend.sh

Reset blockchain data

First, you need to stop the blockchain (as above) and then execute:

./first_time_setup.sh

This removes all data on the blockchain, including accounts, deployed smart contracts, etc... The block count will be reset when you start the blockchain again.

Project structure

noteChain // project directory
├── eosio_docker
   ├── * contracts // this folder will be mounted into docker
      └── notechain
          └── notechain.cpp // the main smart contract
   ├── * data // blockchain data, generated after first_time_setup.sh
      ├── blocks
      ├── state
      └── initialized // to indicate whether the blockchain has been initialized or not
   └── * scripts // scripts and utilities for docker container
       ├── accounts.json // pre-create account names, public and private keys (for demo only)
       ├── continue_blockchain.sh // continue the stopped blockchain
       ├── create_accounts.sh // create account data
       ├── deploy_contract.sh // deploy contract
       └── init_blockchain.sh // script for creating accounts and deploying contract inside docker container
└── frontend
    ├── node_modules // generated after npm install
    ├── public
       └── index.html // html skeleton for create react app
    ├── src
       ├── pages
          └── index.jsx // an one-pager jsx, include react component and Material-UI
       └── index.js // for react-dom to render the app
    ├── package-lock.json // generated after npm install
    └── package.json // for npm packages

* means the directory will be mounted to the docker container. Whenever the file changes on the local machine, it will be automatically reflected in the docker environment.

DApp development

The DApp consists of two parts. eosio blockchain and frontend react app. These can be found in:

  • eosio_docker
    • eosio block producing node (local node) wrapped in a docker container
      • 1 smart contract
      • auto smart contract deployment
      • auto create 7 user accounts
  • frontend

Users interact with the UI in client and sign the transaction in frontend. The signed transaction (which is an update action in this demo DApp) is sent to the blockchain directly. After the transaction is accepted in blockchain, the note is added into the multi index table in blockchain.

The UI, index.jsx, reads the notes data directly from nodeos using 'getTableRows()'. The smart contract, notechain.cpp, stores these notes in the multi index table using 'emplace()'' and 'modify()'.

Docker usage

Docker is used to wrap the eosio software inside and run a container (instance) from an image (eosio-notechain). To work with the blockchain directly, by running the scripts or using a cleos command line, you need to go into the container bash.

Go into container bash:

docker exec -it eosio_notechain_container bash

We have already set the container working directory to /opt/eosio/bin/, you could run cleos command in this directory directly. For documentation of cleos: https://developers.eos.io/eosio-nodeos/docs/cleos-overview

You can also look at the init_blockchain.sh or deploy_contract.sh scripts for examples of cleos command lines.

To exit from inside the container bash:

exit

Smart contract (Blockchain):

The smart contract can be found at eosio_docker/contracts/notechain/notechain.cpp(host environment), you can edit this smart contract. You will then need to compile and deploy the contract to the blockchain.

To save time, we prepared some scripts for you. Execute the scripts in the container bash (see above.)

The following script will help you to unlock the wallet, compile the modified contract and deploy to blockchain. 1st parameter is the contract name; 2nd parameter is the account name of the contract owner, 3rd and 4th parameter references wallet related information that was created during the Initial setup:

Inside docker container

./scripts/deploy_contract.sh notechain notechainacc notechainwal $(cat notechain_wallet_password.txt)

After running this script the modified smart contract will be deployed on the blockchain.

Remember to redeploy the NoteChain contract each time you modify it using the steps above!

Frontend:

The UI code can be found at frontend/src/pages/index.jsx(host environment), once you have edited this code the frontend react app compile automatically and the page on browser will be automatically refreshed. You can see the change on the browser once the browser finishes loading.

Docker commands

If you are more familiar with docker, you could use the docker commands below to have better control with the whole environment. Below are the explanations of each of the commands:

Execute below command in /eosio_docker:

Run container from eosio-notechain image by mounting contracts / scripts to the container with running the init_blockchain.sh script as the process. The init_blockchain.sh script run the local node of the blockchain and initializes wallets / contract / data.

docker run --rm --name eosio_notechain_container \
-p 8888:8888 -p 9876:9876 \
--mount type=bind,src="$(pwd)"/contracts,dst=/opt/eosio/bin/contracts \
--mount type=bind,src="$(pwd)"/scripts,dst=/opt/eosio/bin/scripts \
--mount type=bind,src="$(pwd)"/data,dst=/mnt/dev/data \
-w "/opt/eosio/bin/" eosio-notechain:eos2.0.5-cdt1.6.2 /bin/bash -c "./scripts/init_blockchain.sh"

Output and follow docker console logs:

docker logs eosio_notechain_container --follow

Remove the container (will remove all wallets / contracts / data), useful if you want to re-init the whole DApp.

docker rm -f eosio_notechain_container

Stop the container (see below troubleshoot section to see how to pause and continue the blockchain):

docker stop eosio_notechain_container

More Repositories

1

eos

An open source smart contract platform
C++
11,274
star
2

Documentation

EOSIO Documents
2,084
star
3

eosjs

General purpose library for the EOSIO blockchain.
TypeScript
1,436
star
4

eosio.cdt

EOSIO.CDT (Contract Development Toolkit) is a suite of tools used to build EOSIO contracts
C++
511
star
5

eosio.contracts

Smart contracts that provide some of the basic functions of the EOSIO blockchain
C++
323
star
6

demux-js

💫 Deterministic event-sourced state and side effect handling for blockchain applications
TypeScript
306
star
7

eosjs-ecc

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption
JavaScript
283
star
8

eos-token-distribution

Shell
196
star
9

eos-vm

A Low-Latency, High Performance and Extensible WebAssembly Backend Library
C++
193
star
10

eosjs-api

Application programming interface to EOS blockchain nodes.
JavaScript
178
star
11

eosio-card-game-repo

The Elemental Battles Tutorial is divided into easy to follow lessons that take you through the process of creating your own fully-functional blockchain-based dApp.
158
star
12

eosio-web-ide

eosio-web-ide
TypeScript
151
star
13

universal-authenticator-library

A library for allowing apps to easily use different auth providers.
TypeScript
127
star
14

eosio-java

EOSIO SDK for Java - API for integrating with EOSIO-based blockchains
Java
125
star
15

eosio-explorer

An application providing Web GUI to communicate with EOSIO blockchain in a local development environment.
JavaScript
115
star
16

eosio-project-demux-example

Simple Blog DApp built with Demux and React for the EOSIO Blockchain
JavaScript
89
star
17

eosjs-keygen

Javascript keys generator for EOS
JavaScript
72
star
18

history-tools

EOSIO History Tools
C++
65
star
19

eosio-reference-ios-authenticator-app

iOS reference app demonstrating inter-application transaction signing for EOSIO blockchain apps
Swift
65
star
20

eosio-swift

EOSIO SDK for Swift - API for integrating with EOSIO-based blockchains
C
61
star
21

patroneos

RPC Checkpoint for EOS nodes
Go
47
star
22

ricardian-template-toolkit

Renderer for the Ricardian Contract specification
TypeScript
41
star
23

spec-repo

EOSIO Specifications Repository
40
star
24

demux-js-eos

Demux-js Action Reader implementations for EOSIO blockchains
TypeScript
38
star
25

fc

C++
38
star
26

eosio-webauthn-example-app

Example web app demonstrating EOSIO signing via WebAuthn
TypeScript
38
star
27

welcome

Documentation that covers EOSIO Overview, Getting Started and Protocol documents
C++
38
star
28

abieos

Binary <> JSON conversion using ABIs. Compatible with languages which can interface to C
C++
34
star
29

eosio-java-android-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Java
Java
32
star
30

eosio-swift-ios-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Swift
Swift
30
star
31

eosjs-json

Information about the EOS blockchain in the JSON file format.
JavaScript
28
star
32

eosio-reference-chrome-extension-authenticator-app

Chrome extension reference app demonstrating how users could sign transactions using various EOSIO Labs tools
TypeScript
25
star
33

ual-token-pocket

authenticator meant to be used with Token Pocket and the Universal Authenticator Library
TypeScript
24
star
34

ricardian-spec

Specification defining valid Ricardian contracts
23
star
35

ual-reactjs-renderer

This library provides a React renderer around the Universal Authenticator Library
JavaScript
23
star
36

tropical-example-web-app

An example for developers showing an application built on EOSIO combining UAL, Manifest Spec, and Ricardian Contracts
JavaScript
22
star
37

eosio.exchange

C++
21
star
38

eosjs-secp256k1

Compiles c++ secp256k1 pedersen commitments, borromean ring signatures, and ZK range proofs into JavaScript.
JavaScript
17
star
39

hackathon-howto-guide

Getting started guide for EOS Global Hackathon series
16
star
40

musl

Mirror of git://git.musl-libc.org/musl
C
14
star
41

eosio-toppings

A monorepo with tools working on top of nodeos
TSQL
14
star
42

ual-scatter

authenticator meant to be used with Scatter and Universal Authenticator Library
TypeScript
14
star
43

ual-authenticator-walkthrough

tutorial walking through the steps required to create a new authenticator for the Universal Authenticator Library
JavaScript
13
star
44

EEPs

EOSIO Enhancement Proposals
13
star
45

eosio-swift-vault

Utility library for managing keys and signing with Apple's Keychain and Secure Enclave
Swift
12
star
46

eosio.assert

A security feature to reduce the need for users to trust blockchain apps when a user signs a transaction for a trusted blockchain network with a trusted wallet application
C++
12
star
47

eosio-java-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Java for signing transactions using in-memory keys
Java
12
star
48

eosio.forum

C++
12
star
49

eosio-swift-ecc

Swift utilities for working with keys, cryptographic signatures, encryption/decryption, etc.
Swift
11
star
50

key-value-example-app

An example app for using the key value database feature new to 2.1 of EOSIO.
TypeScript
11
star
51

eosio-java-android-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Java using ABIEOS
Java
11
star
52

eosio-authentication-transport-protocol-spec

EOSIO authentication transport protocol specification for consistent request-response lifecycle
10
star
53

ual-plainjs-renderer

library providers a Plain JS renderer around the Universal Authenticator Library
TypeScript
10
star
54

eosio-wasm-spec-tests

Repo for holding the generated wasm spec tests, as well as the generator
C++
10
star
55

demux-js-postgres

Demux-js Action Handler implementation for Postgres databases
TypeScript
10
star
56

eosjs-ledger-signature-provider

EOSJS Ledger Signature Provider Interface
TypeScript
10
star
57

demux-cli

CLI tool for starting, developing, and interacting with demux-js projects.
JavaScript
10
star
58

mojey

Swift
9
star
59

tutorials

Tutorials, examples and how-tos for EOS.IO
9
star
60

eosio.system

Reference system contract for an EOSIO based chain
C++
9
star
61

eosio-java-android-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
9
star
62

manifest-spec

A specification detailing how EOSIO-enabled applications comply with the application manifest requirements of EOSIO-compatible user agents
9
star
63

eosio-android-keystore-signature-provider

Pluggable signature provider for EOSIO SDK for Java using Android's Keystore
Kotlin
9
star
64

vt-blockchain-bootcamp-starter

JavaScript
8
star
65

homebrew-eosio

homebrew tap for EOSIO
Shell
8
star
66

ual-eosio-reference-authenticator

Authenticator meant for use with EOSIO Reference Authenticator Apps and the Universal Authenticator Library
TypeScript
7
star
67

eosio.helm

Helm charts for EOSIO.
Shell
6
star
68

return-values-example-app

An example app for using the action return value feature new to 2.1 of EOSIO.
Shell
6
star
69

training-EED101

C++
6
star
70

eosio-swift-reference-ios-authenticator-signature-provider

A pluggable signature provider for EOSIO SDK for Swift for signing transactions with EOSIO Reference iOS Authenticator App
Swift
6
star
71

test-state-history

JavaScript
5
star
72

eosio-java-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
5
star
73

eosio-java-abieos-serialization-provider

Java version of the ABIEOS Serialization Provider
Java
5
star
74

ual-ledger

authenticator meant to be used with Ledger and the Universal Authenticator Library
TypeScript
5
star
75

ual-lynx

authenticator meant to be used with Lynx and Universal Authenticator Library
TypeScript
5
star
76

taurus-node

EOSIO-Taurus - The Most Powerful Infrastructure for Decentralized Applications
C++
4
star
77

eosio-swift-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Swift using ABIEOS
C++
4
star
78

eosio.token

Reference contract for an EOSIO based token
C++
4
star
79

eosio-swift-vault-signature-provider

Pluggable signature provider for EOSIO SDK for Swift using Apple's Keychain or Secure Enclave
Swift
4
star
80

history-tools-docs

history-tools migrated docs for dev portal consumption
3
star
81

eosjs-ios-browser-signature-provider-interface

a Signature Provider Interface for communicating with an authenticator from iOS Safari using the EOSIO Authentication Transport Protocol Specification
TypeScript
3
star
82

chain-kv

key-value storage for blockchains
C++
3
star
83

eosio-swift-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Swift for signing transactions using in-memory keys
Swift
3
star
84

eosjs-window-message-signature-provider-interface

A Signature Provider Interface for communicating with an authenticator over the Window Messaging API using the EOSIO Authentication Transport Protocol Spec.
TypeScript
3
star
85

eosjs-signature-provider-interface

An abstract class that implements the EOSJS SignatureProvider interface, and provides helper methods for interacting with an authenticator using the EOSIO Authentication Transport Protocol Specification.
TypeScript
3
star
86

homebrew-eosio.cdt

homebrew tap for eosio.cdt
Ruby
2
star
87

training-tictactoe

Bootstrap for certain training courses
C++
2
star
88

auto-request-generator

Python
2
star
89

eos-vm-test-wasms

Binary wasms for testing eos-vm.
1
star
90

taurus-zpp-bits

C++
1
star