-
Java 14+
-
PostgreSQL 12+
see install prerequisites at the end of this document for assistance if needed
# Create the development database. Assumes that TimescaleDB is running on `localhost:5432`
sudo su -l postgres
createdb -h localhost -U postgres stable_coin
# CTRL+D to exit postgres user shell
# Install git
sudo apt install git
# Clone the repository (note, if you're setting up the full demo, you can skip this)
git clone https://github.com/hashgraph/hedera-stable-coin.git
#if you're setting up the full demo
cd stable-coin-java-hcs
#else
cd hedera-stable-coin
# Assemble JAR.
./gradlew build
cp .env.sample .env
nano .env
set the following environment variables
These variables must be set to your environment before starting the token node
- HSC_DATABASE_URL=postgresql://localhost:5432/
- HSC_POSTGRES_DB=stable_coin
- HSC_DATABASE_USERNAME=postgres
- HSC_DATABASE_PASSWORD=password
- HSC_NETWORK=testnet
Note that an operator is not required to run a token node on an existing topic.
- HSC_OPERATOR_ID={0.0.___}
- HSC_OPERATOR_KEY={Private key 302e___}
java -jar build/libs/stable-coin-0.2.0.jar
Note the topic id
output to the console on first run and update .env
file accordingly for subsequent runs.
You can CTRL+C as soon as the new topic id is shown.
After the first token node is run, it will output a topic id
for subsequent uses, copy this topic id
and update below.
HSC_TOPIC_ID={0.0.____}
java -jar build/libs/stable-coin-0.2.0.jar
These variables are defaulted and may be ignored for initial testing
- HSC_TOKEN_NAME=Fire
- HSC_TOKEN_SYMBOL=XFR
- HSC_TOKEN_DECIMAL=2
- HSC_TOTAL_SUPPLY=10000
Defaults to the operator key.
Note: Running java -jar build/libs/stable-coin-0.2.0.jar --newkeys
will generate and output a set of keys you may use here in the environment file.
Remember to uncomment
these variables.
- HSC_OWNER_KEY={Private Key 302___}
- HSC_SUPPLY_MANAGER_KEY_PUB={Public Key 302___}
- HSC_COMPLIANCE_MANAGER_KEY_PUB={Public Key 302___}
- HSC_ENFORCEMENT_MANAGER_KEY_PUB={Public Key 302___}
- HSC_STATE_PORT=9000
- HSC_COMMIT_INTERVAL=5
The token node will read the latest snapshot on launch to skip reading from the entire topic.
- HSC_STATE_DIR=_state
- HSC_STATE_HISTORY_SIZE=3
- GENERATE_OWNER_KEY={private keys 302___}
- HSC_SUPPLY_MANAGER_KEY_PUB={private keys 302___}
- GENERATE_COMPLIANCE_MANAGER_KEY={private keys 302___}
- GENERATE_ENFORCEMENT_MANAGER_KEY={private keys 302___}
The current state of the contract is available via the State API.
By default, this is exposed at port 9000 and can be changed via the HSC_STATE_PORT
variable.
http GET :9000/
{
"complianceManager": "cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dc",
"decimals": "2",
"name": "Fire",
"owner": "cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dc",
"proposedOwner": "0000000000000000000000000000000000000000000000000000000000000000",
"supplyManager": "cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dc",
"symbol": "XFR",
"totalSupply": "10000"
}
http GET :9000/:address
http GET :9000/cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dc
{
"balance": "10000",
"isFrozen": false,
"isKycPassed": true
}
http GET :9000/:address/allowance/:other
http GET :9000/cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dc/allowance/cf750f7c2adc1baf87b3de9df1c317a5f845c994d0b28a6ec4655e7fc59b75dd
{
"allowance": "0"
}
Note: These installation instructions are applicable to Debian 4.19
, other operating systems may differ.
# update and upgrade apt
sudo apt upgrade
sudo apt update
# install curl and wget
sudo apt -y install wget curl
# download JDK14
curl -O https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz
# Extract
tar xvf openjdk-14_linux-x64_bin.tar.gz
# Move to /opt
sudo mv jdk-14 /opt/
# Setup environment
sudo nano /etc/profile.d/jdk14.sh
export JAVA_HOME=/opt/jdk-14
export PATH=$PATH:$JAVA_HOME/bin
# save file
# Source profile
source /etc/profile.d/jdk14.sh
# Confirm java version
echo $JAVA_HOME
/opt/jdk-14
java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
(instructions from https://docs.timescale.com/latest/getting-started/installation/debian/installation-apt-debian)
Note: Assumes wget is installed
# `lsb_release -c -s` should return the correct codename of your OS
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -c -s)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
# Add timescale repository
sudo sh -c "echo 'deb https://packagecloud.io/timescale/timescaledb/debian/ `lsb_release -c -s` main' > /etc/apt/sources.list.d/timescaledb.list"
wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | sudo apt-key add -
sudo apt-get update
# Now install appropriate package for PG version
sudo apt-get install timescaledb-postgresql-12
# Configure the database, respond "y" to prompts
sudo timescaledb-tune
# Restart PostgreSQL instance
sudo service postgresql restart
# Set password for postgres user
sudo passwd postgres
# Connect to the database
sudo su -l postgres
psql
# psql (12.4 (Debian 12.4-1.pgdg100+1))
# Type "help" for help.
# Set postgres user password to 'password'
alter user postgres with password 'password';
CTRL+D to exit psql
CTRL+D again to return to your user shell
If you make changes to the database schema, you'll need to rebuild the automatically generated code.
# Set environment variables
export HSC_DATABASE_URL="postgresql://localhost:5432/"
export HSC_POSTGRES_DB="stable_coin"
export HSC_DATABASE_USERNAME="postgres"
export HSC_DATABASE_PASSWORD="password"
# Create / update entities in the database
./gradlew flywayMigrate
# Build java artifacts
./gradlew jooqGenerate
Licensed under Apache License, Version 2.0 – see LICENSE in this repo or apache.org/licenses/LICENSE-2.0.