ICON DAPP From A-Z Part 3: ICON Dice Roll DAPP

Nov 2, 2018 · 9 min read

ICON Workshop SF Blockchain Week

# Create a new environment for this DAPP project
$ pwd
# .../icon-tutorial/WORKSHOP
# First clone the workshop project from github
$ git clone https://gitlab.com/ibriz/icon-dice-roll.git
$ cd icon-dice-roll
# Have a glance of the files we cloned
$ ls -1
# 'ICON Workshop Guide.pdf'
# config/
# dice-roll/
# keystores/
# testcmdline/
# webapp/

$ tbears deploy dice-roll -k keystores/keystore_test1.json -c config/tbears_cli_config.json
# Check if deployment was successful
$ tbears txresult 0xd6bf8f864cb12eaf12c94d1af97192e3b95290248b00b87a42a31bb0dd344192
# Check the balance of scoreAddress
$ tbears balance cx6f030fceecce9adad0fa967b79ed46151d292576
# testcmdline/send_set_treasury.json
"jsonrpc": "2.0",
"method": "icx_sendTransaction",
"params": {
"version": "0x3",
"from": "hxe7af5fcfd8dfc67530a01a0e403882687528dfcb",
"value": "0x6f05b59d3b200000",
"stepLimit": "0x200000",
"nid": "0x3",
"nonce": "0x2",
"to": "cx6f030fceecce9adad0fa967b79ed46151d292576",
"dataType": "call",
"data": {
"method": "set_treasury"
"id": 1
# Make the transaction
$ tbears sendtx -k keystores/keystore_test1.json -c config/tbears_cli_config.json testcmdline/send_set_treasury.json
# use test1_Account as keystore password
$ tbears balance cx6f030fceecce9adad0fa967b79ed46151d292576
$ pip install flask
# webapp/main.pydefault_score = "cx6f030fceecce9adad0fa967b79ed46151d292576"
# New terminal window
$ cd <...>/icon-tutorial/
# We installed flask into the virtualenv, so activate it first
$ source venv/bin/activate
# go back to webapp directory
$ cd icon-dice-roll/webapp
$ python main.py# minimize the window, and go back to the original terminal
#testcmdline/send_bet.json"to": "cx6f030fceecce9adad0fa967b79ed46151d292576",
$ tbears sendtx -k keystores/keystore_test1.json -c config/tbears_cli_config.json testcmdline/send_bet.json# use test1_Account as keystore password

# /config/tbears_cli_config_testnet.json
"uri": "https://bicon.net.solidwallet.io/api/v3",
"nid": "0x3",
"keyStore": null,
"from": "hxe9d75191906ccc604fc1e45a9f3c59fb856c215f",
"to": "cx0000000000000000000000000000000000000000",
"deploy": {
"stepLimit": "0x5a000000",
"contentType": "zip",
"mode": "install"
"txresult": {},
"transfer": {}
$ tbears deploy dice-roll -k keystores/keystore1.json -c config/tbears_cli_config_testnet.json# use password: p@ssword1
$ tbears txresult 0xe0e001ad0eaef54ba62f1cc6ba757899de0c95ffa4af4c0dd3b32b7587d72f60 -u https://bicon.net.solidwallet.io/api/v3
# testcmdline/send_set_treasury.json "from": "hxe9d75191906ccc604fc1e45a9f3c59fb856c215f", 
: "cxd73fdab694c5bbb3b489f760bcae767c301ae4dc",
$ tbears sendtx -k keystores/keystore1.json -c config/tbears_cli_config_testnet.json testcmdline/send_set_treasury.json
# webapp/main.py
default_score = "cxd73fdab694c5bbb3b489f760bcae767c301ae4dc"
icon_service = IconService(HTTPProvider("https://bicon.net.solidwallet.io/api/v3"))
python main.py

Python Web Framework

# Install mod_wsgi and enable it
$ sudo apt-get install libapache2-mod-wsgi
$ a2enmod wsgi
|-- icon-dice-roll/
|---- keystores/
|---- main.py
|---- repeater.py
|---- static/
|---- templates/
|---- webapp.wsgi
# main.py 
'wallet1': KeyWallet.load("/<path to>/keystore_test1.json", "test1_Account"),
# webapp.wsgi#!/usr/bin/python
import sys
from main import app as application
/etc/apache2/sites-available/dapps.icon.support-le-ssl.conf<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin 2infiniti@gmail.com
ServerName dapps.icon.support
ServerAlias www.dapps.icon.support
DocumentRoot /var/www/dapps.icon.support/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess dice user=flaskuser group=flaskgroup threads=5
WSGIScriptAlias /icon-dice-roll /var/www/dapps.icon.support/icon-dice-roll/webapp.wsgi
<Directory /var/www/dapps.icon.support/icon-dice-roll>
WSGIProcessGroup dice
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/dapps.icon.support/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/dapps.icon.support/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
# Create sym link to sites-enabled
$ a2ensite /etc/apache2/sites-available/dapps.icon.support-le-ssl.conf
# Restart apache
$ systemctl restart apache2

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade