├── .browserslistrc ├── src ├── eventBus.js ├── plugins │ └── vuetify.js ├── service │ ├── tokenProperties.js │ ├── accountGetInfo.js │ ├── accountCreate.js │ ├── client.js │ ├── fileService.js │ └── tokenService.js ├── assets │ └── logo.svg ├── router │ └── index.js ├── main.js ├── App.vue ├── components │ ├── Tokens.vue │ ├── ComposerDialog.vue │ ├── TransactionsDrawer.vue │ ├── ErrorNoEnvFilePopup.vue │ ├── Accounts.vue │ ├── MintBurnDialog.vue │ ├── Header.vue │ ├── AccountCard.vue │ ├── TransferDialog.vue │ ├── TokenCard.vue │ ├── TokenCreateDialog.vue │ ├── TokenDetailsDialog.vue │ ├── NonFungibleComposer.vue │ ├── Wallet.vue │ └── FungibleComposer.vue ├── utils.js ├── views │ └── Dashboard.vue └── store │ └── store.js ├── babel.config.js ├── public ├── favicon.ico ├── index.html └── tokenTemplates.json ├── docker-compose.yaml ├── .gitpod.yml ├── vue.config.js ├── .gitignore ├── .github ├── ISSUE_TEMPLATE │ ├── question.md │ ├── feature_request.md │ └── bug_report.md ├── PULL_REQUEST_TEMPLATE.md └── CODEOWNERS ├── .eslintrc.js ├── .env.sample ├── nginx.conf ├── Dockerfile ├── package.json ├── CODE_OF_CONDUCT.md ├── README.md ├── CONTRIBUTING.md └── LICENSE /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /src/eventBus.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | 3 | export const EventBus = new Vue(); 4 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["@vue/cli-plugin-babel/preset"] 3 | }; 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hashgraph/hedera-hts-demo/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | hts-demo: 4 | build: 5 | context: . 6 | ports: 7 | - "8080:8080" 8 | -------------------------------------------------------------------------------- /src/plugins/vuetify.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Vuetify from "vuetify/lib"; 3 | 4 | Vue.use(Vuetify); 5 | 6 | export default new Vuetify({}); 7 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - name: HTS demo 3 | before: cp -n .env.sample .env 4 | init: yarn 5 | command: yarn run serve --host 0.0.0.0 --disable-host-check 6 | 7 | ports: 8 | - port: 8080 9 | onOpen: open-preview -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transpileDependencies: ["vuetify", "@koumoul/vjsf"], 3 | configureWebpack: { 4 | devtool: "source-map", 5 | devServer: { 6 | host: '0.0.0.0', 7 | allowedHosts: ['localhost', '.gitpod.io'], 8 | } 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /src/service/tokenProperties.js: -------------------------------------------------------------------------------- 1 | export function loadTokenTemplates() { 2 | let result = null; 3 | const xmlhttp = new XMLHttpRequest(); 4 | xmlhttp.open("GET", "tokenTemplates.json", false); 5 | xmlhttp.send(); 6 | if (xmlhttp.status === 200) { 7 | result = xmlhttp.responseText; 8 | } 9 | return JSON.parse(result); 10 | } 11 | -------------------------------------------------------------------------------- /src/assets/logo.svg: -------------------------------------------------------------------------------- 1 | black-whiteH -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | 9 | # local environment 10 | .env 11 | .env.production 12 | .env.local 13 | .env.*.local 14 | 15 | .DS_Store 16 | node_modules 17 | /dist 18 | 19 | # Editor directories and files 20 | .idea 21 | .vscode 22 | *.suo 23 | *.ntvs* 24 | *.njsproj 25 | *.sln 26 | *.sw? 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Get an answer to your question 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | Please ask questions you have in our [Discord](https://hedera.com/discord) group first. You can also search GitHub to see if the issue has been reported already. 11 | 12 | Otherwise, please feel free to ask your question here. 13 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"], 7 | parserOptions: { 8 | parser: "babel-eslint" 9 | }, 10 | rules: { 11 | "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", 12 | "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off" 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import VueRouter from "vue-router"; 3 | import Dashboard from "../views/Dashboard"; 4 | Vue.use(VueRouter); 5 | 6 | const routes = [ 7 | { 8 | path: "/", 9 | component: Dashboard, 10 | name: "Dashboard" 11 | } 12 | ]; 13 | 14 | const router = new VueRouter({ 15 | mode: "history", 16 | base: process.env.BASE_URL, 17 | routes 18 | }); 19 | 20 | export default router; 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | **Detailed description**: 9 | 10 | **Which issue(s) this PR fixes**: 11 | Fixes # 12 | 13 | **Special notes for your reviewer**: 14 | 15 | **Checklist** 16 | - [ ] Documentation added 17 | - [ ] Tests updated 18 | -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | # Account Id 2 | VUE_APP_OPERATOR_ID=0.0.xxxx 3 | # private key 4 | VUE_APP_OPERATOR_KEY=302xxx 5 | 6 | # network (specify testnet or mainnet) 7 | VUE_APP_NETWORK=testnet 8 | 9 | # initial balance for new accounts (in hbar) 10 | VUE_APP_INITIAL_BALANCE=100 11 | 12 | # max query payment (hbar) 13 | VUE_APP_MAX_QUERY_PAYMENT=10 14 | 15 | # max transaction fee (hBar) 16 | VUE_APP_MAX_TX_FEE=10 17 | 18 | # optional https://nft.storage API Key to store NFT metadata on IPFS 19 | VUE_APP_NFT_STORAGE_API_KEY= -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import App from "./App.vue"; 3 | import router from "./router"; 4 | import store from "./store/store"; 5 | import vuetify from "./plugins/vuetify"; 6 | 7 | Vue.config.productionTip = false; 8 | Vue.config.productionTip = false; 9 | // Vue.http.headers.common['Access-Control-Allow-Origin'] = '*' 10 | // Vue.http.headers.common['Access-Control-Allow-Origin'] = true 11 | 12 | void store.dispatch("setup"); 13 | void store.dispatch("fetch"); 14 | 15 | new Vue({ 16 | router, 17 | store, 18 | vuetify, 19 | render: h => h(App) 20 | }).$mount("#app"); 21 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 8080; 3 | 4 | sendfile on; 5 | default_type application/octet-stream; 6 | 7 | server_name your-site.com; 8 | 9 | gzip on; 10 | gzip_http_version 1.1; 11 | gzip_disable "MSIE [1-6]\."; 12 | gzip_min_length 256; 13 | gzip_vary on; 14 | gzip_proxied expired no-cache no-store private auth; 15 | gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; 16 | gzip_comp_level 9; 17 | 18 | root /usr/share/nginx/html; 19 | 20 | location / { 21 | try_files $uri $uri/ /index.html =404; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Hedera Token Service 9 | 10 | 11 | 12 | 13 | 16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 27 | 28 | 50 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.9 AS build 2 | 3 | COPY ./package.json /srv/hedera-hts-demo/package.json 4 | COPY ./yarn.lock /srv/hedera-hts-demo/yarn.lock 5 | COPY ./.browserslistrc /srv/hedera-hts-demo/.browserslistrc 6 | COPY ./.eslintrc.js /srv/hedera-hts-demo/.eslintrc.js 7 | COPY ./babel.config.js /srv/hedera-hts-demo/babel.config.js 8 | COPY ./vue.config.js /srv/hedera-hts-demo/vue.config.js 9 | COPY ./.env /srv/hedera-hts-demo/.env 10 | COPY ./.env /srv/hedera-hts-demo/.env.production 11 | ADD ./src /srv/hedera-hts-demo/src 12 | ADD ./public /srv/hedera-hts-demo/public 13 | 14 | RUN cd /srv/hedera-hts-demo && yarn install 15 | RUN cd /srv/hedera-hts-demo && yarn build 16 | 17 | FROM nginx:alpine 18 | 19 | COPY ./nginx.conf /etc/nginx/conf.d/default.conf 20 | RUN rm -rf /usr/share/nginx/html/* 21 | COPY --from=build /srv/hedera-hts-demo/dist /usr/share/nginx/html 22 | COPY --from=build /srv/hedera-hts-demo/.env /usr/share/nginx/html/.env 23 | COPY --from=build /srv/hedera-hts-demo/.env /usr/share/nginx/html/.env.production 24 | 25 | CMD ["nginx", "-g", "daemon off;"] 26 | -------------------------------------------------------------------------------- /src/service/accountGetInfo.js: -------------------------------------------------------------------------------- 1 | import { hederaClient } from "./client"; 2 | import { notifyError } from "../utils"; 3 | const { AccountInfoQuery } = require("@hashgraph/sdk"); 4 | 5 | export async function accountGetInfo(accountId) { 6 | const client = hederaClient(); 7 | try { 8 | // cycle token relationships 9 | let tokenRelationships = {}; 10 | const info = await new AccountInfoQuery() 11 | .setAccountId(accountId) 12 | .execute(client); 13 | const hBarBalance = info.balance; 14 | 15 | for (let key of info.tokenRelationships.keys()) { 16 | const tokenRelationship = { 17 | tokenId: key.toString(), 18 | hbarBalance: hBarBalance.toString(), 19 | balance: info.tokenRelationships.get(key).balance.toString(), 20 | freezeStatus: info.tokenRelationships.get(key).isFrozen, 21 | kycStatus: info.tokenRelationships.get(key).isKycGranted 22 | }; 23 | tokenRelationships[key] = tokenRelationship; 24 | } 25 | 26 | return tokenRelationships; 27 | } catch (err) { 28 | notifyError("getAccountInfo " + err.message); 29 | return undefined; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/Tokens.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 37 | 38 | 39 | 55 | -------------------------------------------------------------------------------- /src/service/accountCreate.js: -------------------------------------------------------------------------------- 1 | import { hederaClient } from "./client"; 2 | import { EventBus } from "@/eventBus"; 3 | import {notifyError} from "@/utils"; 4 | 5 | const { 6 | PrivateKey, 7 | AccountCreateTransaction, 8 | Hbar 9 | } = require("@hashgraph/sdk"); 10 | 11 | export async function accountCreate(wallet) { 12 | const client = hederaClient(); 13 | 14 | try { 15 | 16 | const privateKey = await PrivateKey.generate(); 17 | 18 | const response = await new AccountCreateTransaction() 19 | .setKey(privateKey.publicKey) 20 | .setInitialBalance(new Hbar(process.env.VUE_APP_INITIAL_BALANCE)) 21 | .execute(client); 22 | 23 | const transactionReceipt = await response.getReceipt(client); 24 | const newAccountId = transactionReceipt.accountId; 25 | 26 | const transaction = { 27 | id: response.transactionId.toString(), 28 | type: "cryptoCreate", 29 | inputs: "initialBalance=" + process.env.VUE_APP_INITIAL_BALANCE, 30 | outputs: "accountId=" + newAccountId.toString() 31 | }; 32 | EventBus.$emit("addTransaction", transaction); 33 | 34 | return { 35 | accountId: newAccountId.toString(), 36 | account: { 37 | wallet: wallet, 38 | privateKey: privateKey.toString(), 39 | tokenRelationships: {} 40 | } 41 | }; 42 | } catch (err) { 43 | notifyError(err.message); 44 | console.error(err); 45 | return {}; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | ######################### 2 | ##### Global Rule ##### 3 | ######################### 4 | * @hashgraph/developer-advocates 5 | ######################### 6 | ##### Core Files ###### 7 | ######################### 8 | 9 | # NOTE: Must be placed last to ensure enforcement over all other rules 10 | 11 | # Protection Rules for Github Configuration Files and Actions Workflows 12 | /.github/ @hashgraph/platform-ci @hashgraph/release-engineering-managers 13 | 14 | # Self-protection for root CODEOWNERS files (this file should not exist and should definitely require approval) 15 | /CODEOWNERS @hashgraph/release-engineering-managers 16 | 17 | # Protect the repository root files 18 | /README.md @hashgraph/platform-ci @hashgraph/release-engineering-managers @hashgraph/developer-advocates 19 | **/LICENSE @hashgraph/release-engineering-managers 20 | 21 | # CodeCov configuration 22 | **/codecov.yml @hashgraph/platform-ci @hashgraph/release-engineering-managers 23 | 24 | # Git Ignore definitions 25 | **/.gitignore @hashgraph/platform-ci @hashgraph/developer-advocates 26 | **/.gitignore.* @hashgraph/developer-advocates 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@hts-demo/admin", 3 | "private": true, 4 | "scripts": { 5 | "serve": "vue-cli-service serve", 6 | "build": "vue-cli-service build", 7 | "lint": "vue-cli-service lint" 8 | }, 9 | "dependencies": { 10 | "@hashgraph/sdk": "2.0.19", 11 | "@koumoul/vjsf": "^1.17.1", 12 | "bignumber.js": "^9.0.0", 13 | "core-js": "^3.6.5", 14 | "nft.storage": "^0.4.1", 15 | "vue": "^2.6.11", 16 | "vue-router": "^3.2.0", 17 | "vuetify": "^2.2.11", 18 | "vuex": "^3.4.0", 19 | "vuex-persistedstate": "^4.0.0-beta.1" 20 | }, 21 | "devDependencies": { 22 | "@vue/cli-plugin-babel": "~4.5.0", 23 | "@vue/cli-plugin-eslint": "~4.5.0", 24 | "@vue/cli-plugin-router": "~4.5.0", 25 | "@vue/cli-plugin-vuex": "~4.5.0", 26 | "@vue/cli-service": "~4.5.0", 27 | "@vue/eslint-config-prettier": "^6.0.0", 28 | "babel-eslint": "^10.1.0", 29 | "eslint": "^6.7.2", 30 | "eslint-plugin-prettier": "^3.1.3", 31 | "eslint-plugin-vue": "^6.2.2", 32 | "prettier": "^1.19.1", 33 | "sass": "^1.19.0", 34 | "sass-loader": "^8.0.0", 35 | "vue-cli-plugin-vuetify": "~2.0.7", 36 | "vue-template-compiler": "^2.6.11", 37 | "vuetify-loader": "^1.3.0" 38 | }, 39 | "eslintConfig": { 40 | "root": true, 41 | "env": { 42 | "node": true 43 | }, 44 | "extends": [ 45 | "plugin:vue/essential", 46 | "eslint:recommended", 47 | "@vue/prettier" 48 | ], 49 | "parserOptions": { 50 | "parser": "babel-eslint" 51 | }, 52 | "rules": {} 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/components/ComposerDialog.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 49 | 50 | 66 | -------------------------------------------------------------------------------- /src/service/client.js: -------------------------------------------------------------------------------- 1 | import { getAccountDetails } from "../utils"; 2 | 3 | const { Client, Hbar } = require("@hashgraph/sdk"); 4 | 5 | export function hederaClientForUser(user) { 6 | const account = getAccountDetails(user); 7 | return hederaClientLocal(account.accountId, account.privateKey); 8 | } 9 | 10 | function checkProvided(environmentVariable) { 11 | if (environmentVariable === null) { 12 | return false; 13 | } 14 | if (typeof environmentVariable === "undefined") { 15 | return false; 16 | } 17 | return true; 18 | } 19 | 20 | export function hederaClient() { 21 | const operatorPrivateKey = process.env.VUE_APP_OPERATOR_KEY; 22 | const operatorAccount = process.env.VUE_APP_OPERATOR_ID; 23 | 24 | if (!checkProvided(operatorPrivateKey) || !checkProvided(operatorAccount)) { 25 | throw new Error( 26 | "environment variables VUE_APP_OPERATOR_KEY and VUE_APP_OPERATOR_ID must be present" 27 | ); 28 | } 29 | return hederaClientLocal(operatorAccount, operatorPrivateKey); 30 | } 31 | 32 | function hederaClientLocal(operatorAccount, operatorPrivateKey) { 33 | if (!checkProvided(process.env.VUE_APP_NETWORK)) { 34 | throw new Error("VUE_APP_NETWORK must be set in environment"); 35 | } 36 | 37 | let client; 38 | switch (process.env.VUE_APP_NETWORK.toUpperCase()) { 39 | case "TESTNET": 40 | client = Client.forTestnet(); 41 | break; 42 | case "MAINNET": 43 | client = Client.forMainnet(); 44 | break; 45 | default: 46 | throw new Error('VUE_APP_NETWORK must be "testnet" or "mainnet"'); 47 | } 48 | client.setOperator(operatorAccount, operatorPrivateKey); 49 | if ((typeof(process.env.VUE_APP_MAX_TX_FEE) !== undefined) && (process.env.VUE_APP_MAX_TX_FEE !== "")) { 50 | client.setMaxTransactionFee(new Hbar(process.env.VUE_APP_MAX_TX_FEE)); 51 | } 52 | if ((typeof(process.env.VUE_APP_MAX_QUERY_PAYMENT) !== undefined) && (process.env.VUE_APP_MAX_QUERY_PAYMENT !== "")) { 53 | client.setMaxQueryPayment(new Hbar(process.env.VUE_APP_MAX_QUERY_PAYMENT)); 54 | } 55 | return client; 56 | } 57 | -------------------------------------------------------------------------------- /src/components/TransactionsDrawer.vue: -------------------------------------------------------------------------------- 1 | 40 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/components/ErrorNoEnvFilePopup.vue: -------------------------------------------------------------------------------- 1 | 2 | 34 | 54 | 55 | 56 | 75 | -------------------------------------------------------------------------------- /src/components/Accounts.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 83 | 84 | 85 | 101 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | import { EventBus } from "./eventBus"; 2 | import state from "./store/store"; 3 | 4 | export function notifySuccess(message) { 5 | notify(true, message); 6 | } 7 | 8 | export function notifyError(message) { 9 | notify(false, message); 10 | } 11 | 12 | function notify(status, message) { 13 | EventBus.$emit("notify", { 14 | status: status, 15 | message: message 16 | }); 17 | } 18 | 19 | export function getUserAccounts() { 20 | let accounts = []; 21 | if (state.getters.numberOfAccounts !== 0) { 22 | for (const key in state.getters.getAccounts) { 23 | if (state.getters.getAccounts[key].account.wallet !== "Issuer") { 24 | accounts.push(key); 25 | } 26 | } 27 | } 28 | 29 | return accounts; 30 | } 31 | 32 | export function getUserAccountsWithNames(exclude) { 33 | let accounts = []; 34 | const account = { 35 | accountId: "0.0.0", 36 | name: "" 37 | }; 38 | accounts.push(account); 39 | if (state.getters.numberOfAccounts !== 0) { 40 | for (const key in state.getters.getAccounts) { 41 | if (state.getters.getAccounts[key].account.wallet !== "Issuer") { 42 | if (state.getters.getAccounts[key].account.wallet !== exclude) { 43 | const account = { 44 | accountId: key, 45 | name: state.getters.getAccounts[key].account.wallet 46 | }; 47 | accounts.push(account); 48 | } 49 | } 50 | } 51 | } 52 | 53 | return accounts; 54 | } 55 | 56 | export function amountWithDecimals(amount, decimals) { 57 | return (amount / parseFloat(Math.pow(10, decimals))).toFixed(decimals); 58 | } 59 | 60 | export function getPrivateKeyForAccount(accountId) { 61 | return state.getters.getAccounts[accountId].account.privateKey; 62 | } 63 | 64 | export function getAccountDetails(account) { 65 | if (state.getters.numberOfAccounts !== 0) { 66 | for (const key in state.getters.getAccounts) { 67 | if (state.getters.getAccounts[key].account.wallet === account) { 68 | return { 69 | accountId: key, 70 | privateKey: state.getters.getAccounts[key].account.privateKey 71 | }; 72 | } 73 | } 74 | } 75 | 76 | return { 77 | accountId: "", 78 | privateKey: "" 79 | }; 80 | } 81 | 82 | export function secondsToParts(seconds) { 83 | const secondsInMonth = 30 * 24 * 60 * 60; 84 | const secondsInDay = 24 * 60 * 60; 85 | const secondsInHour = 60 * 60; 86 | 87 | const months = seconds / secondsInMonth; 88 | seconds = seconds % secondsInMonth; 89 | const days = seconds / secondsInDay; 90 | seconds = seconds % secondsInDay; 91 | const hours = seconds / secondsInHour; 92 | seconds = seconds % secondsInHour; 93 | const minutes = seconds / 60; 94 | seconds = seconds % 60; 95 | 96 | let result = months + " months "; 97 | if (days + hours + minutes + seconds != 0) { 98 | result += days + " days "; 99 | if (hours + minutes + seconds != 0) { 100 | result += hours + " hours "; 101 | if (minutes + seconds != 0) { 102 | result += minutes + " minutes "; 103 | if (seconds != 0) { 104 | result += seconds + " seconds "; 105 | } 106 | } 107 | } 108 | } 109 | return result; 110 | } 111 | -------------------------------------------------------------------------------- /src/components/MintBurnDialog.vue: -------------------------------------------------------------------------------- 1 | 56 | 57 | 100 | 101 | 102 | 118 | -------------------------------------------------------------------------------- /src/views/Dashboard.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | 105 | 106 | 122 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at oss@hedera.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /public/tokenTemplates.json: -------------------------------------------------------------------------------- 1 | { 2 | "helpCompletingThisFile": "https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/about", 3 | "card": { 4 | "type": "object", 5 | "properties": { 6 | "photo": { 7 | "type": "object", 8 | "title": "Photo", 9 | "contentMediaType": "image/*", 10 | "writeOnly": true, 11 | "properties": { 12 | "type": { 13 | "type": "string" 14 | }, 15 | "data": { 16 | "type": "string" 17 | }, 18 | "size": { 19 | "type": "number" 20 | }, 21 | "x-props": { 22 | "dense": true 23 | } 24 | } 25 | }, 26 | "Storage": { 27 | "type": "string", 28 | "title": "Metadata Storage", 29 | "enum": [ 30 | "HEDERA", 31 | "IPFS" 32 | ], 33 | "x-props": { 34 | "dense": true 35 | } 36 | }, 37 | "Quality": { 38 | "type": "string", 39 | "title": "Quality", 40 | "enum": [ 41 | "Meteorite", 42 | "Diamond", 43 | "Shadow" 44 | ], 45 | "x-props": { 46 | "dense": true 47 | } 48 | }, 49 | "Rarity": { 50 | "type": "string", 51 | "title": "Rarity", 52 | "enum": [ 53 | "Legendary", 54 | "Rare", 55 | "Common" 56 | ], 57 | "x-props": { 58 | "dense": true 59 | } 60 | }, 61 | "Type": { 62 | "type": "string", 63 | "title": "Type", 64 | "enum": [ 65 | "Creature", 66 | "Spell" 67 | ], 68 | "x-props": { 69 | "dense": true 70 | } 71 | } 72 | } 73 | }, 74 | "frog": { 75 | "type": "object", 76 | "properties": { 77 | "photo": { 78 | "type": "object", 79 | "title": "Photo", 80 | "contentMediaType": "image/*", 81 | "writeOnly": true, 82 | "properties": { 83 | "type": { 84 | "type": "string" 85 | }, 86 | "data": { 87 | "type": "string" 88 | }, 89 | "size": { 90 | "type": "number" 91 | }, 92 | "x-props": { 93 | "dense": true 94 | } 95 | } 96 | }, 97 | "Storage": { 98 | "type": "string", 99 | "title": "Metadata Storage", 100 | "enum": [ 101 | "HEDERA", 102 | "IPFS" 103 | ], 104 | "x-props": { 105 | "dense": true 106 | } 107 | }, 108 | "SkinColor": { 109 | "type": "string", 110 | "title": "Skin Color", 111 | "enum": [ 112 | "Green", 113 | "Brown", 114 | "Yellow" 115 | ], 116 | "x-props": { 117 | "dense": true 118 | } 119 | }, 120 | "AdultSize": { 121 | "type": "string", 122 | "title": "Adult size", 123 | "enum": [ 124 | "Tiny", 125 | "Small", 126 | "Medium", 127 | "Large" 128 | ], 129 | "x-props": { 130 | "dense": true 131 | } 132 | }, 133 | "DangerLevel": { 134 | "type": "string", 135 | "title": "Am I dangerous to humans", 136 | "enum": [ 137 | "Slimy", 138 | "Poisonous", 139 | "Lethal" 140 | ], 141 | "x-props": { 142 | "dense": true 143 | } 144 | } 145 | } 146 | }, 147 | "cat": { 148 | "type": "object", 149 | "properties": { 150 | "photo": { 151 | "type": "object", 152 | "title": "Photo", 153 | "contentMediaType": "image/*", 154 | "writeOnly": true, 155 | "properties": { 156 | "type": { 157 | "type": "string" 158 | }, 159 | "data": { 160 | "type": "string" 161 | }, 162 | "size": { 163 | "type": "number" 164 | }, 165 | "x-props": { 166 | "dense": true 167 | } 168 | } 169 | }, 170 | "Storage": { 171 | "type": "string", 172 | "title": "Metadata Storage", 173 | "enum": [ 174 | "HEDERA", 175 | "IPFS" 176 | ], 177 | "x-props": { 178 | "dense": true 179 | } 180 | }, 181 | "Breed": { 182 | "type": "string", 183 | "title": "Breed", 184 | "enum": [ 185 | "Persian", 186 | "Maine Coon", 187 | "Short hair", 188 | "Siamese" 189 | ], 190 | "x-props": { 191 | "dense": true 192 | } 193 | }, 194 | "EyeColor": { 195 | "type": "string", 196 | "title": "Eye Color", 197 | "enum": [ 198 | "Lava", 199 | "Sunfire", 200 | "Teal", 201 | "Gold" 202 | ], 203 | "x-props": { 204 | "dense": true 205 | } 206 | } 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/service/fileService.js: -------------------------------------------------------------------------------- 1 | import { notifyError, notifySuccess } from "../utils"; 2 | import { EventBus } from "@/eventBus"; 3 | import { hederaClient } from "@/service/client"; 4 | 5 | import { Blob, NFTStorage } from "nft.storage"; 6 | 7 | const { 8 | FileContentsQuery, 9 | FileCreateTransaction, 10 | FileUpdateTransaction, 11 | FileAppendTransaction, 12 | FileId, 13 | PrivateKey, 14 | Status 15 | } = require("@hashgraph/sdk"); 16 | 17 | export async function fileGetContents(fileId, storageProtocol = "HEDERA") { 18 | if (storageProtocol === "HEDERA") { 19 | // Get file from Hedera File Storage 20 | const client = hederaClient(); 21 | let info = {}; 22 | try { 23 | info = await new FileContentsQuery() 24 | .setFileId(FileId.fromString(fileId)) 25 | .execute(client); 26 | } catch (err) { 27 | notifyError(err.message); 28 | } 29 | return info; 30 | } else if (storageProtocol === "IPFS") { 31 | // Get file from IPFS storage using Cloudflare IPFS Gateway 32 | return await fetch(`https://cloudflare-ipfs.com/ipfs/${fileId}`); 33 | } 34 | } 35 | 36 | export async function fileCreate(fileData, storage = "HEDERA") { 37 | if (storage === "HEDERA" || storage === undefined) { 38 | // Publish file to Hedera File Service storage 39 | const privateKey = PrivateKey.fromString(process.env.VUE_APP_OPERATOR_KEY); 40 | const client = hederaClient(); 41 | let fileId = ""; 42 | const fileChunk = 4000; 43 | const largeFile = fileData.length > fileChunk; 44 | let startIndex = 0; 45 | try { 46 | const keys = []; 47 | keys.push(privateKey); 48 | const fileCreateTransaction = new FileCreateTransaction(); 49 | 50 | if (largeFile) { 51 | // if we have a large file (> 4000 bytes), create the file with keys 52 | // then run file append 53 | // then remove keys 54 | fileCreateTransaction.setContents(fileData.slice(0, fileChunk)); 55 | fileCreateTransaction.setKeys(keys); 56 | } else { 57 | fileCreateTransaction.setContents(fileData); 58 | } 59 | 60 | let response = await fileCreateTransaction.execute(client); 61 | let transactionReceipt = await response.getReceipt(client); 62 | 63 | if (transactionReceipt.status !== Status.Success) { 64 | notifyError(transactionReceipt.status.toString()); 65 | return ""; 66 | } 67 | 68 | fileId = transactionReceipt.fileId.toString(); 69 | 70 | const transaction = { 71 | id: response.transactionId.toString(), 72 | type: "fileCreate", 73 | inputs: fileData.substr(0, 20), 74 | outputs: "fileId=" + fileId 75 | }; 76 | 77 | startIndex = startIndex + fileChunk; 78 | let chunks = 1; 79 | while (startIndex <= fileData.length) { 80 | notifySuccess("Saving token properties file chunk " + chunks); 81 | chunks += 1; 82 | // sleep 500ms to avoid duplicate tx errors 83 | await new Promise(r => setTimeout(r, 500)); 84 | // append to file 85 | response = await new FileAppendTransaction() 86 | .setContents(fileData.slice(startIndex, startIndex + fileChunk)) 87 | .setFileId(FileId.fromString(fileId)) 88 | .execute(client); 89 | let transactionReceipt = await response.getReceipt(client); 90 | 91 | if (transactionReceipt.status !== Status.Success) { 92 | notifyError(transactionReceipt.status.toString()); 93 | return ""; 94 | } 95 | startIndex = startIndex + fileChunk; 96 | } 97 | 98 | EventBus.$emit("addTransaction", transaction); 99 | 100 | if (largeFile) { 101 | // remove keys 102 | response = await new FileUpdateTransaction() 103 | .setKeys([]) 104 | .setFileId(FileId.fromString(fileId)) 105 | .execute(client); 106 | transactionReceipt = await response.getReceipt(client); 107 | 108 | if (transactionReceipt.status !== Status.Success) { 109 | notifyError(transactionReceipt.status.toString()); 110 | return ""; 111 | } 112 | 113 | notifySuccess("Token properties file created"); 114 | } 115 | } catch (err) { 116 | notifyError(err.message); 117 | console.error(err); 118 | 119 | return ""; 120 | } 121 | 122 | return fileId; 123 | } else { 124 | // Store file in IPFS 125 | try { 126 | const NFT_STORAGE_API_KEY = process.env.VUE_APP_NFT_STORAGE_API_KEY; 127 | if (NFT_STORAGE_API_KEY) { 128 | const nftStorageClient = new NFTStorage({ token: NFT_STORAGE_API_KEY }); 129 | const content = new Blob([fileData], { type: "application/json" }); 130 | return await nftStorageClient.storeBlob(content); 131 | } else { 132 | const NO_API_KEY_ERROR = 133 | "You don't seem to have an NFT.STORAGE API key in your .env file. Please\n" + 134 | " get a new API key at https://nft.storage/, add it to .env file and restart\n" + 135 | " the server."; 136 | notifyError(NO_API_KEY_ERROR); 137 | console.error(NO_API_KEY_ERROR); 138 | 139 | return ""; 140 | } 141 | } catch (err) { 142 | notifyError(err.message); 143 | console.error(err); 144 | 145 | return ""; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/components/Header.vue: -------------------------------------------------------------------------------- 1 | 69 | 70 | 71 | 155 | 174 | -------------------------------------------------------------------------------- /src/components/AccountCard.vue: -------------------------------------------------------------------------------- 1 | 76 | 77 | 192 | 193 | 194 | 210 | -------------------------------------------------------------------------------- /src/components/TransferDialog.vue: -------------------------------------------------------------------------------- 1 | 90 | 91 | 174 | 175 | 176 | 192 | -------------------------------------------------------------------------------- /src/store/store.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Vuex from "vuex"; 3 | import createPersistedState from "vuex-persistedstate"; 4 | import { accountCreate } from "../service/accountCreate"; 5 | import { accountGetInfo } from "../service/accountGetInfo"; 6 | import { tokenGetInfo } from "../service/tokenService"; 7 | import { notifySuccess } from "../utils"; 8 | import { EventBus } from "../eventBus"; 9 | Vue.use(Vuex); 10 | 11 | export default new Vuex.Store({ 12 | plugins: [createPersistedState()], 13 | state: { 14 | tokens: {}, 15 | accounts: {}, 16 | bids: {}, 17 | currentTokenId: undefined, 18 | enablePoll: false 19 | }, 20 | mutations: { 21 | setPolling(state, polling) { 22 | state.enablePoll = polling; 23 | }, 24 | setCurrentTokenId(state, tokenId) { 25 | state.currentTokenId = tokenId; 26 | }, 27 | setTokens(state, tokens) { 28 | state.tokens = tokens; 29 | }, 30 | setAccounts(state, accounts) { 31 | state.accounts = accounts; 32 | }, 33 | setAccount(state, account) { 34 | Vue.set(state.accounts, account.accountId, account); 35 | }, 36 | setToken(state, token) { 37 | Vue.set(state.tokens, token.tokenId, token); 38 | }, 39 | addBid(state, bid) { 40 | Vue.set(state.bids, bid.tokenId, bid); 41 | }, 42 | deleteBid(state, bid) { 43 | Vue.delete(state.bids, bid.tokenId); 44 | }, 45 | reset(state) { 46 | state.accounts = {}; 47 | state.tokens = {}; 48 | state.bids = {}; 49 | state.currentTokenId = undefined; 50 | }, 51 | wipeAccount(state, wipeInstruction) { 52 | const accountId = wipeInstruction.accountId; 53 | const tokenId = wipeInstruction.tokenId; 54 | const account = state.accounts[accountId]; 55 | 56 | if (typeof account !== "undefined") { 57 | const relationship = account.tokenRelationships[tokenId]; 58 | if (typeof relationship !== "undefined") { 59 | state.accounts[accountId].tokenRelationships[tokenId].balance = 0; 60 | } 61 | } 62 | }, 63 | freezeAccount(state, freezeInstruction) { 64 | const accountId = freezeInstruction.accountId; 65 | const tokenId = freezeInstruction.tokenId; 66 | const account = state.accounts[accountId]; 67 | 68 | if (typeof account !== "undefined") { 69 | const relationship = account.tokenRelationships[tokenId]; 70 | if (typeof relationship !== "undefined") { 71 | const freeze = freezeInstruction.freeze ? 1 : 2; 72 | account.tokenRelationships[tokenId].freezeStatus = freeze; 73 | Vue.set(state.accounts, accountId, account); 74 | } 75 | } 76 | }, 77 | kycAccount(state, kycInstruction) { 78 | const accountId = kycInstruction.accountId; 79 | const tokenId = kycInstruction.tokenId; 80 | const account = state.accounts[accountId]; 81 | 82 | if (typeof account !== "undefined") { 83 | const relationship = account.tokenRelationships[tokenId]; 84 | if (typeof relationship !== "undefined") { 85 | const kyc = kycInstruction.kyc ? 1 : 2; 86 | state.accounts[accountId].tokenRelationships[tokenId].kycStatus = kyc; 87 | } 88 | } 89 | } 90 | }, 91 | getters: { 92 | getBids(state) { 93 | if (typeof state.bids === "undefined") { 94 | return {}; 95 | } else { 96 | return state.bids; 97 | } 98 | }, 99 | currentTokenId(state) { 100 | return state.currentTokenId; 101 | }, 102 | numberOfTokens(state) { 103 | return Object.keys(state.tokens).length || 0; 104 | }, 105 | numberOfAccounts(state) { 106 | return Object.keys(state.accounts).length || 0; 107 | }, 108 | getTokens(state) { 109 | if (typeof state.tokens === "undefined") { 110 | return {}; 111 | } else { 112 | return state.tokens; 113 | } 114 | }, 115 | getAccounts(state) { 116 | if (typeof state.accounts === "undefined") { 117 | return {}; 118 | } else { 119 | return state.accounts; 120 | } 121 | } 122 | }, 123 | actions: { 124 | async setup({ commit, state }) { 125 | if (Object.keys(state.accounts).length === 0) { 126 | // set ourselves up 127 | // create issuer account 128 | let newAccount = await accountCreate("Issuer"); 129 | commit("setAccount", newAccount); 130 | notifySuccess("Setting up demo 1/4 - issuer account created"); 131 | // create user 1 132 | newAccount = await accountCreate("Alice"); 133 | commit("setAccount", newAccount); 134 | notifySuccess("Setting up demo 2/4 - Alice wallet account created"); 135 | // create user 2 136 | newAccount = await accountCreate("Bob"); 137 | commit("setAccount", newAccount); 138 | notifySuccess("Setting up demo 3/4 - Bob wallet account created"); 139 | // create user 3 140 | newAccount = await accountCreate("Marketplace"); 141 | commit("setAccount", newAccount); 142 | notifySuccess( 143 | "Setting up demo 4/4 - Marketplace wallet account created" 144 | ); 145 | } 146 | commit("setCurrentTokenId", undefined); 147 | notifySuccess("Demo Ready"); 148 | commit("setPolling", true); 149 | EventBus.$emit("busy", false); 150 | }, 151 | async fetchAccounts({ commit, state }) { 152 | if (typeof state.accounts === "undefined") { 153 | return; 154 | } 155 | if (Object.keys(state.accounts).length === 0) { 156 | return; 157 | } 158 | for (const key in state.accounts) { 159 | if (!state.enablePoll) { 160 | return; 161 | } 162 | let account = state.accounts[key]; 163 | const accountDetails = await accountGetInfo(key); 164 | account.tokenRelationships = accountDetails; 165 | commit("setAccount", account); 166 | } 167 | }, 168 | async fetchTokens({ commit, state }) { 169 | if (typeof state.tokens === "undefined") { 170 | return; 171 | } 172 | if (Object.keys(state.tokens).length === 0) { 173 | return; 174 | } 175 | for (const key in state.tokens) { 176 | if (!state.enablePoll) { 177 | return; 178 | } 179 | const token = state.tokens[key]; 180 | const tokenUpdate = await tokenGetInfo(token); 181 | commit("setToken", tokenUpdate); 182 | } 183 | }, 184 | async fetch({ dispatch, state }) { 185 | if (!state.enablePoll) { 186 | return; 187 | } 188 | await dispatch("fetchAccounts"); 189 | await dispatch("fetchTokens"); 190 | } 191 | }, 192 | modules: {} 193 | }); 194 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub license](https://img.shields.io/github/license/hashgraph/hedera-hts-demo)](https://github.com/hashgraph/hedera-hts-demo/blob/master/LICENSE) 2 | [![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://hedera.com/discord) 3 | 4 | # Hedera Token Service (HTS) demo 5 | 6 | This demo is a user interface written in Javascript (Vue.JS) to illustrate the use of the Hedera Token Service. When first launched, the demo will create three accounts as follows: 7 | * An account for the owner/admin of new tokens 8 | * Two accounts representing users (wallet holders) that will use the token, Alice and Bob 9 | * Another account representing a marketplace (escrow) for the purpose of holding tokens that have been offered for sale 10 | 11 | Each account is credited some hBar to fund their activity on Hedera. 12 | 13 | The demo enables you to: 14 | * Create tokens 15 | * Mint and Burn 16 | * Associate and Dissociate tokens to/from accounts 17 | * Manage KYC and Freeze for token/account relationships 18 | * Transfer from treasury (owner) to users 19 | * Transfer between users 20 | * Atomically transfer up to two tokens between users, with an optional hBar payment as one atomic transaction 21 | * Transfer tokens to a marketplace escrow account along with an offer price in hBar 22 | 23 | For convenience, accounts and tokens created during the demo will be persisted to a cookie and will be available when the demo is restarted. 24 | 25 | _Note: This is purely for demonstration purposes and should not be used as-is in production_ 26 | 27 | ## Prerequisites 28 | 29 | * A testnet or mainnet account (head to https://portal.hedera.com to create an account if you don't have one) 30 | * Node.js v14.9.0 31 | * Yarn 1.22.10 32 | * Docker 33 | * Docker compose (optional) 34 | 35 | ## Environment files 36 | 37 | The project requires an environment file to be setup. 38 | First, copy `.env.sample` to `.env` 39 | Edit `.env` and setup the following variables 40 | 41 | * VUE_APP_OPERATOR_ID=0.0.xxxx Input your operator id 42 | * VUE_APP_OPERATOR_KEY=302xxx Input your private key 43 | * VUE_APP_INITIAL_BALANCE=100 44 | * VUE_APP_NETWORK=testnet (or mainnet) 45 | 46 | optionally you may set 47 | * VUE_APP_MAX_QUERY_PAYMENT=10 max allowed query payment 48 | * VUE_APP_MAX_TX_FEE=10 max allowed transaction fee 49 | 50 | ## I just want to run it quickly 51 | 52 | You can deploy the UI with docker-compose after you have edited the `.env` file above. 53 | 54 | Build 55 | ```shell script 56 | docker-compose build --no-cache 57 | ``` 58 | 59 | Run 60 | ```shell script 61 | docker-compose up 62 | ``` 63 | 64 | Note: `docker-compose` build is only necessary the first time, or if you make changes to the code or `.env` to (re)build the images. 65 | 66 | ## I want to build it myself 67 | 68 | ### Project setup 69 | ``` 70 | yarn install 71 | ``` 72 | 73 | #### Compiles and hot-reloads for development 74 | ``` 75 | yarn serve 76 | ``` 77 | 78 | #### Compiles and minifies for production 79 | ``` 80 | yarn build 81 | ``` 82 | 83 | #### Lints and fixes files 84 | ``` 85 | yarn lint 86 | ``` 87 | 88 | ## Using the UI 89 | 90 | Navigate to the URL output by the `serve` command (e.g. http://localhost:8080/) to access the UI. 91 | If you are running docker-compose, the url is `http://localhost:8080`. 92 | 93 | The Header has links for the following: 94 | * An admin page where you can manage tokens 95 | * Accounts for the users 96 | * A `+` button to add a token 97 | * A button to show a list of transactions that were executed while running the demo (newest at the top) 98 | * A button to reset (nuke) the demo. This will remove all traces of the tokens and accounts in your browser and re-create a clean demo environment with three new accounts. 99 | 100 | Once a token is created, you can: 101 | * Show accounts associated with the token 102 | * Mint (If a supply key was provided when the token was created) 103 | * Burn (If a supply key was provided when the token was created) 104 | * Transfer from treasury to users 105 | Note: Update and Delete are not currently supported 106 | 107 | Clicking on the accounts button (left most) will show which accounts are currently associated with the token, from there you can: 108 | * Freeze/UnFreeze an account in relation to the token (if a freeze key was provided when the token was created) 109 | * Grant or Revoke KYC for an account in relation to the token (if a KYC key was provided when the token was created) 110 | * Wipe an amount of tokens from an account (if a wipe key was provided when the token was created) 111 | 112 | Choosing one of the user accounts in the header allows you to associate or dissociate the account from a token. 113 | Once associated (and subject to the account being KYCd and unfrozen if appropriate for the token), you can transfer to the other user account. 114 | 115 | ## NFTs 116 | 117 | Support for creating NFTs is demonstrated in the composer whereby a set of templates (driven from `/public/tokenTemplates.json`) are available within the UI when creating an NFT. 118 | Each template carries a set of properties that are input during the token creation. 119 | These properties (along with an image if necessary) as then stored in an immutable file on Hedera, the resulting FileId is used to define the symbol for the token, e.g. HEDERA://0.0.xxxx. 120 | 121 | You may edit or add to the templates by editing the `/public/tokenTemplates.json` file, following guidelines from [the vjsf component](https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/about). 122 | Note that if you wish to include a picture in your NFT specification, the property must be called `photo` since the UI depends on that field value. 123 | 124 | _Note: An alternative to using files on Hedera would be to host the file on a shared location and use a hash of the file as the symbol for the token so that the validity of the file can be verified at any time. 125 | We demonstrate usage of IPFS storage using [nft.storage](https://nft.storage) integration. You can create your API key on https://nft.storage and add it to your .env file to enable IPFS upload._ 126 | 127 | ## Marketplace 128 | 129 | A pseudo-market place is enabled in the demo, this enables a token to be transferred to a market place (an escrow account of sorts) along with an offer price in hBar. 130 | 131 | One a token has been transferred to the market place, Alice or Bob can request transfer of the token from the marketplace to their account in exchange for the offered hBar value whereby they will own the token in exchange for the hBar value which will be transferred to the account that transferred the token to the market place in the first place. 132 | 133 | _Note: If Alice transferred a token to the market place, she's not able to buy the token, only Bob can. If the issuer (owner) of the token transferred to the marketplace, both Bob and Alice can buy it._ 134 | 135 | ## Contributing 136 | 137 | Contributions are welcome. Please see the [contributing](CONTRIBUTING.md) guide to see how you can get 138 | involved. 139 | 140 | ## Code of Conduct 141 | 142 | This project is governed by the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are 143 | expected to uphold this code of conduct. Please report unacceptable behavior to [oss@hedera.com](mailto:oss@hedera.com) 144 | 145 | ## License 146 | 147 | [Apache License 2.0](LICENSE) 148 | -------------------------------------------------------------------------------- /src/components/TokenCard.vue: -------------------------------------------------------------------------------- 1 | 76 | 77 | 207 | 208 | 209 | 228 | -------------------------------------------------------------------------------- /src/components/TokenCreateDialog.vue: -------------------------------------------------------------------------------- 1 | 115 | 219 | 220 | 221 | 237 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | The Hedera HTS Demo accepts contributions via GitHub pull requests. This document outlines the process to help get your contribution accepted. 4 | 5 | ## Contents 6 | - [Support Channels](#support-channels) 7 | - [Issues](#issues) 8 | - [Vulnerability Disclosure](#vulnerability-disclosure) 9 | - [Types](#issue-types) 10 | - [Lifecycle](#issue-lifecycle) 11 | - [Pull Requests](#pull-requests) 12 | - [Forking](#forking) 13 | - [Sign Off](#sign-off) 14 | - [Lifecycle](#pr-lifecycle) 15 | - [Releases](#releases) 16 | 17 | ## Support Channels 18 | 19 | Whether you are a user or contributor, official support channels include: 20 | 21 | - [Issues](https://github.com/hashgraph/hedera-hts-demo/issues) 22 | - [Discord](https://hedera.com/discord) 23 | 24 | Before opening a new issue or submitting a new pull request, it's helpful to search the project - 25 | it's likely that another user has already reported the issue you're facing, or it's a known issue 26 | that we're already aware of. It is also worth asking on the Discord channels. 27 | 28 | ## Issues 29 | 30 | Issues are used as the primary method for tracking anything to do with the project. 31 | 32 | ### Vulnerability Disclosure 33 | 34 | Most of the time, when you find a bug, it should be reported using 35 | [GitHub issues](https://github.com/hashgraph/hedera-hts-demo/issues). However, if 36 | you are reporting a _security vulnerability_, please email a report to 37 | [security@hedera.com](mailto:security@hedera.com). This will give 38 | us a chance to try to fix the issue before it is exploited in the wild. 39 | 40 | ### Issue Types 41 | 42 | There are 3 types of issues (each with their own corresponding [label](https://github.com/hashgraph/hedera-hts-demo/labels)): 43 | 44 | - **Bugs:** These track bugs with the code or problems with the documentation (i.e. missing or incomplete) 45 | - **Features:** These track specific feature requests and ideas until they are complete. If the feature is 46 | sufficiently large, complex or requires coordination among multiple Hedera projects, it should 47 | first go through the [Hedera Improvement Proposal](https://github.com/hashgraph/hip) process. 48 | - **Question:** These are support or functionality inquiries that we want to have a record of for 49 | future reference. Generally these are questions that are too complex or large to store in the 50 | Discord channel or have particular interest to the community as a whole. Depending on the discussion, 51 | these can turn into a "Feature" or "Bug". 52 | 53 | ### Issue Lifecycle 54 | 55 | The issue lifecycle is mainly driven by the core maintainers, but is good information for those 56 | contributing. All issue types follow the same general lifecycle. Differences are noted below. 57 | 58 | 1. **Issue creation** 59 | 2. **Triage** 60 | - The maintainer in charge of triaging will apply the proper labels for the issue. This 61 | includes labels for priority and type. 62 | - Clean up the title to succinctly and clearly state the issue (if needed). 63 | - Add the issue to the correct milestone. 64 | - We attempt to do this process at least once per work day. 65 | 3. **Discussion** 66 | - "Feature" and "Bug" issues should be connected to the PR that resolves it. 67 | - Whoever is working on a "Feature" or "Bug" issue (whether a maintainer or someone from 68 | the community), should either assign the issue to them self or make a comment in the issue 69 | saying that they are taking it. 70 | - "Question" issues should stay open until resolved or if they have not been 71 | active for more than 30 days. This will help keep the issue queue to a manageable size and 72 | reduce noise. 73 | 4. **Issue closure** 74 | - Issues should be closed when a PR is merged or closed manually by the submitter or maintainer 75 | if it is determined that is not necessary. 76 | 77 | ## Pull Requests 78 | 79 | Like most open source projects, we use Pull Requests (PRs) to track code changes. 80 | 81 | ### Forking 82 | 83 | 1. Fork the [hedera-hts-demo](https://github.com/hashgraph/hedera-hts-demo) repo 84 | 85 | Go to the [project](https://github.com/hashgraph/hedera-hts-demo) page then hit the `Fork` 86 | button to fork your own copy of the repository to your GitHub account. 87 | 88 | 2. Clone the forked repo to your local working directory. 89 | ```sh 90 | $ git clone https://github.com/$your_github_account/hedera-hts-demo.git 91 | ``` 92 | 3. Add an `upstream` remote to keep your fork in sync with the main repo. 93 | ```sh 94 | $ cd hedera-hts-demo 95 | $ git remote add upstream https://github.com/hashgraph/hedera-hts-demo.git 96 | $ git remote -v 97 | 98 | origin https://github.com/$your_github_account/hedera-hts-demo.git (fetch) 99 | origin https://github.com/$your_github_account/hedera-hts-demo.git (push) 100 | upstream https://github.com/hashgraph/hedera-hts-demo.git (fetch) 101 | upstream https://github.com/hashgraph/hedera-hts-demo.git (push) 102 | ``` 103 | 4. Sync your local `master` branch. 104 | ```sh 105 | $ git pull upstream master 106 | ``` 107 | 5. Create a branch to add a new feature or fix issues. 108 | ```sh 109 | $ git checkout -b new-feature 110 | ``` 111 | 6. Make any change on the branch `new-feature` then build and test your codes. 112 | 7. Include in what will be committed. 113 | ```sh 114 | $ git add 115 | ``` 116 | 8. Use [sign-off](#sign-off) when making each of your commits. If you forgot to sign some commits 117 | that are part of the contribution, you can ask [git to rewrite your commit history](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History). 118 | ```sh 119 | $ git commit --signoff -m "Your commit message" 120 | ``` 121 | 9. [Submit](#pr-lifecycle) a pull request. 122 | 123 | ### Sign Off 124 | 125 | The sign-off is a simple line at the end of commit message. All 126 | commits needs to be signed. Your signature certifies that you wrote the code or 127 | otherwise have the right to contribute the material. First, read the 128 | [Developer Certificate of Origin](https://developercertificate.org/) (DCO) to 129 | fully understand its terms. 130 | 131 | Contributors sign-off that they adhere to these requirements by adding a Signed-off-by 132 | line to commit messages (as seen via `git log`): 133 | 134 | ``` 135 | Author: Joe Smith 136 | Date: Thu Feb 2 11:41:15 2018 -0800 137 | 138 | Update README 139 | 140 | Signed-off-by: Joe Smith 141 | ``` 142 | 143 | Use your real name and email (sorry, no pseudonyms or anonymous contributions). 144 | Notice the `Author` and `Signed-off-by` lines match. If they don't your PR will be 145 | rejected by the automated DCO check. 146 | 147 | If you set your `user.name` and `user.email` git configs, you can sign your 148 | commit automatically with `-s` command line option: 149 | 150 | ```sh 151 | $ git commit -s -m 'Update README' 152 | ``` 153 | 154 | ### PR Lifecycle 155 | 156 | Now that you've got your [forked](#forking) branch and [signed off](#sign-off) any commits, you can proceed to submit it. 157 | 158 | 1. **Submitting** 159 | - It is preferred, but not required, to have a PR tied to a specific issue. There can be 160 | circumstances where if it is a quick fix then an issue might be overkill. The details provided 161 | in the PR description would suffice in this case. 162 | - The PR description or commit message should contain a [keyword](https://help.github.com/en/articles/closing-issues-using-keywords) 163 | to automatically close the related issue. 164 | - Commits should be as small as possible, while ensuring that each commit is correct independently 165 | (i.e., each commit should compile and pass tests). 166 | - Add tests and documentation relevant to the fixed bug or new feature. 167 | - We more than welcome PRs that are currently in progress. If a PR is a work in progress, 168 | it should be opened as a [Draft PR](https://help.github.com/en/articles/about-pull-requests#draft-pull-requests). 169 | Once the PR is ready for review, mark it as ready to convert it to a regular PR. 170 | 2. **Triage** 171 | - The maintainer in charge of triaging will apply the proper labels for the issue. 172 | - Add the PR to the correct milestone. This should be the same as the issue the PR closes. 173 | - The maintainer can assign a reviewer or a reviewer can self assign themselves as a reviewer. 174 | 3. **Reviewing** 175 | - All reviews will be completed using the Github review tool. 176 | - A "Comment" review should be used when there are questions about the code that should be 177 | answered, but that don't involve code changes. This type of review does not count as approval. 178 | - A "Changes Requested" review indicates that changes to the code need to be made before they will be 179 | merged. 180 | - For documentation, special attention will be paid to spelling, grammar, and clarity 181 | (whereas those things don't matter *as* much for comments in code). 182 | - Reviews are also welcome from others in the community, especially those who have encountered a bug or 183 | have requested a feature. In the code review, a message can be added, as well as `LGTM` if the PR is 184 | good to merge. It’s also possible to add comments to specific lines in a file, for giving context 185 | to the comment. 186 | - PR owner should try to be responsive to comments by answering questions or changing code. If the 187 | owner is unsure of any comment, reach out to the person who added the comment in Discord. Once all comments 188 | have been addressed, the PR is ready to be merged. 189 | 4. **Merge or Close** 190 | - PRs should stay open until merged or be closed if the submitter has not been responsive for more than 30 days. 191 | This will help keep the PR queue to a manageable size and reduce noise. 192 | 193 | ## Releases 194 | 195 | Hedera uses [Semantic Versioning](https://semver.org) for releases to convey meaning about the 196 | underlying code and what has been modified from one version to the next. We use milestones to 197 | track the progress of a release. Assigning issues to a milestone is on a best effort basis and 198 | we make no guarantees as to when a particular issue will be released. A milestone (and hence 199 | release) is considered done when all outstanding issues/PRs have been closed or moved to another 200 | milestone. 201 | 202 | -------------------------------------------------------------------------------- /src/components/TokenDetailsDialog.vue: -------------------------------------------------------------------------------- 1 | 217 | 289 | 290 | 291 | 320 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/components/NonFungibleComposer.vue: -------------------------------------------------------------------------------- 1 | 234 | 235 | 443 | 444 | 473 | -------------------------------------------------------------------------------- /src/components/Wallet.vue: -------------------------------------------------------------------------------- 1 | 212 | 213 | 470 | 471 | 472 | 488 | -------------------------------------------------------------------------------- /src/components/FungibleComposer.vue: -------------------------------------------------------------------------------- 1 | 346 | 347 | 538 | 539 | 555 | -------------------------------------------------------------------------------- /src/service/tokenService.js: -------------------------------------------------------------------------------- 1 | import { hederaClient, hederaClientForUser } from "./client"; 2 | import { getAccountDetails, notifyError, notifySuccess } from "../utils"; 3 | import state from "../store/store"; 4 | import { EventBus } from "@/eventBus"; 5 | import store from "@/store/store"; 6 | import { getPrivateKeyForAccount } from "@/utils"; 7 | 8 | const { 9 | PrivateKey, 10 | TokenCreateTransaction, 11 | TokenAssociateTransaction, 12 | TokenBurnTransaction, 13 | TokenDeleteTransaction, 14 | TokenDissociateTransaction, 15 | TokenFreezeTransaction, 16 | TokenGrantKycTransaction, 17 | TokenInfoQuery, 18 | TokenMintTransaction, 19 | TokenRevokeKycTransaction, 20 | TransferTransaction, 21 | TokenUnfreezeTransaction, 22 | TokenWipeTransaction, 23 | Hbar, 24 | Status 25 | } = require("@hashgraph/sdk"); 26 | 27 | function issuerClient() { 28 | return hederaClientForUser("Issuer"); 29 | } 30 | 31 | export async function tokenGetInfo(token) { 32 | const client = hederaClient(); 33 | const tokenResponse = token; 34 | try { 35 | const info = await new TokenInfoQuery() 36 | .setTokenId(token.tokenId) 37 | .execute(client); 38 | 39 | tokenResponse.totalSupply = info.totalSupply; 40 | tokenResponse.expiry = info.expirationTime.toDate(); 41 | } catch (err) { 42 | notifyError(err.message); 43 | } 44 | 45 | return tokenResponse; 46 | } 47 | 48 | export async function tokenCreate(token) { 49 | let tokenResponse = {}; 50 | const autoRenewPeriod = 7776000; // set to default 3 months 51 | const issuerAccount = getAccountDetails("Issuer").accountId.toString(); 52 | try { 53 | let additionalSig = false; 54 | let sigKey; 55 | const tx = await new TokenCreateTransaction(); 56 | tx.setTokenName(token.name); 57 | tx.setTokenSymbol(token.symbol.toUpperCase()); 58 | tx.setDecimals(token.decimals); 59 | tx.setInitialSupply(token.initialSupply); 60 | tx.setTreasuryAccountId(token.treasury); 61 | tx.setAutoRenewAccountId(token.autoRenewAccount); 62 | tx.setAutoRenewPeriod(autoRenewPeriod); 63 | 64 | if (token.adminKey) { 65 | sigKey = PrivateKey.fromString(token.key); 66 | tx.setAdminKey(sigKey.publicKey); 67 | additionalSig = true; 68 | } 69 | if (token.kycKey) { 70 | sigKey = PrivateKey.fromString(token.key); 71 | tx.setKycKey(sigKey.publicKey); 72 | additionalSig = true; 73 | } 74 | if (token.freezeKey) { 75 | sigKey = PrivateKey.fromString(token.key); 76 | tx.setFreezeKey(sigKey.publicKey); 77 | additionalSig = true; 78 | tx.setFreezeDefault(token.defaultFreezeStatus); 79 | } else { 80 | tx.setFreezeDefault(false); 81 | } 82 | if (token.wipeKey) { 83 | additionalSig = true; 84 | sigKey = PrivateKey.fromString(token.key); 85 | tx.setWipeKey(sigKey.publicKey); 86 | } 87 | if (token.supplyKey) { 88 | additionalSig = true; 89 | sigKey = PrivateKey.fromString(token.key); 90 | tx.setSupplyKey(sigKey.publicKey); 91 | } 92 | const client = issuerClient(); 93 | 94 | await tx.signWithOperator(client); 95 | 96 | if (additionalSig) { 97 | // TODO: should sign with every key (check docs) 98 | // since the admin/kyc/... keys are all the same, a single sig is sufficient 99 | await tx.sign(sigKey); 100 | } 101 | const response = await tx.execute(client); 102 | const transactionReceipt = await response.getReceipt(client); 103 | 104 | if (transactionReceipt.status !== Status.Success) { 105 | notifyError(transactionReceipt.status.toString()); 106 | } else { 107 | token.tokenId = transactionReceipt.tokenId; 108 | 109 | const transaction = { 110 | id: response.transactionId.toString(), 111 | type: "tokenCreate", 112 | inputs: 113 | "Name=" + 114 | token.name + 115 | ", Symbol=" + 116 | token.symbol.toUpperCase() + 117 | ", Decimals=" + 118 | token.decimals + 119 | ", Supply=" + 120 | token.initialSupply + 121 | ", ...", 122 | outputs: "tokenId=" + token.tokenId.toString() 123 | }; 124 | EventBus.$emit("addTransaction", transaction); 125 | 126 | const tokenInfo = await tokenGetInfo(token); 127 | 128 | tokenResponse = { 129 | tokenId: token.tokenId.toString(), 130 | symbol: token.symbol.toUpperCase(), 131 | name: token.name, 132 | totalSupply: token.initialSupply, 133 | decimals: token.decimals, 134 | autoRenewAccount: issuerAccount, 135 | autoRenewPeriod: autoRenewPeriod, 136 | defaultFreezeStatus: token.defaultFreezeStatus, 137 | kycKey: token.kycKey, 138 | wipeKey: token.wipeKey, 139 | freezeKey: token.freezeKey, 140 | adminKey: token.adminKey, 141 | supplyKey: token.supplyKey, 142 | expiry: tokenInfo.expiry, 143 | isDeleted: false, 144 | treasury: issuerAccount 145 | }; 146 | 147 | // automatically associate, grant, etc... for marketplace 148 | tokenAssociate(token.tokenId, "Marketplace").then(() => { 149 | const marketAccountId = getAccountDetails("Marketplace").accountId; 150 | notifySuccess("token association with marketplace successful"); 151 | if (token.kycKey) { 152 | const instruction = { 153 | tokenId: token.tokenId, 154 | accountId: marketAccountId 155 | }; 156 | tokenGrantKYC(instruction); 157 | } 158 | if (token.freezeKey && token.defaultFreezeStatus) { 159 | const instruction = { 160 | tokenId: token.tokenId, 161 | accountId: marketAccountId 162 | }; 163 | tokenUnFreeze(instruction); 164 | } 165 | }); 166 | // force refresh 167 | await store.dispatch("fetch"); 168 | notifySuccess("token creation successful"); 169 | } 170 | return tokenResponse; 171 | } catch (err) { 172 | notifyError(err.message); 173 | return {}; 174 | } 175 | } 176 | 177 | async function tokenTransactionWithAmount( 178 | client, 179 | transaction, 180 | instruction, 181 | key 182 | ) { 183 | try { 184 | transaction.setTokenId(instruction.tokenId); 185 | if (typeof instruction.accountId !== "undefined") { 186 | transaction.setAccountId(instruction.accountId); 187 | } 188 | transaction.setAmount(instruction.amount); 189 | 190 | await transaction.signWithOperator(client); 191 | await transaction.sign(key); 192 | 193 | const response = await transaction.execute(client); 194 | 195 | const transactionReceipt = await response.getReceipt(client); 196 | if (transactionReceipt.status !== Status.Success) { 197 | notifyError(transactionReceipt.status.toString()); 198 | return { 199 | status: false 200 | }; 201 | } 202 | // force refresh 203 | await store.dispatch("fetch"); 204 | notifySuccess(instruction.successMessage); 205 | return { 206 | status: true, 207 | transactionId: response.transactionId.toString() 208 | }; 209 | } catch (err) { 210 | notifyError(err.message); 211 | return { 212 | status: false 213 | }; 214 | } 215 | } 216 | 217 | async function tokenTransactionWithIdAndAccount( 218 | client, 219 | transaction, 220 | instruction, 221 | key 222 | ) { 223 | try { 224 | transaction.setTokenId(instruction.tokenId); 225 | transaction.setAccountId(instruction.accountId); 226 | 227 | await transaction.signWithOperator(client); 228 | await transaction.sign(key); 229 | 230 | const response = await transaction.execute(client); 231 | 232 | const transactionReceipt = await response.getReceipt(client); 233 | if (transactionReceipt.status !== Status.Success) { 234 | notifyError(transactionReceipt.status.toString()); 235 | return { 236 | status: false 237 | }; 238 | } 239 | 240 | // force refresh 241 | await store.dispatch("fetch"); 242 | notifySuccess(instruction.successMessage); 243 | return { 244 | status: true, 245 | transactionId: response.transactionId.toString() 246 | }; 247 | } catch (err) { 248 | notifyError(err.message); 249 | return { 250 | status: false 251 | }; 252 | } 253 | } 254 | 255 | export async function tokenBurn(instruction) { 256 | instruction.successMessage = 257 | "Burnt " + instruction.amount + " from token " + instruction.tokenId; 258 | const token = state.getters.getTokens[instruction.tokenId]; 259 | const supplyKey = PrivateKey.fromString(token.supplyKey); 260 | const tx = await new TokenBurnTransaction(); 261 | const client = issuerClient(); 262 | const result = await tokenTransactionWithAmount( 263 | client, 264 | tx, 265 | instruction, 266 | supplyKey 267 | ); 268 | if (result.status) { 269 | const transaction = { 270 | id: result.transactionId, 271 | type: "tokenBurn", 272 | inputs: 273 | "tokenId=" + instruction.tokenId + ", Amount=" + instruction.amount 274 | }; 275 | EventBus.$emit("addTransaction", transaction); 276 | } 277 | return result.status; 278 | } 279 | 280 | export async function tokenMint(instruction) { 281 | instruction.successMessage = 282 | "Minted " + instruction.amount + " for token " + instruction.tokenId; 283 | const token = state.getters.getTokens[instruction.tokenId]; 284 | const supplyKey = PrivateKey.fromString(token.supplyKey); 285 | const tx = await new TokenMintTransaction(); 286 | const client = issuerClient(); 287 | const result = await tokenTransactionWithAmount( 288 | client, 289 | tx, 290 | instruction, 291 | supplyKey 292 | ); 293 | if (result.status) { 294 | const transaction = { 295 | id: result.transactionId, 296 | type: "tokenMint", 297 | inputs: 298 | "tokenId=" + instruction.tokenId + ", Amount=" + instruction.amount 299 | }; 300 | EventBus.$emit("addTransaction", transaction); 301 | } 302 | return result.status; 303 | } 304 | 305 | export async function tokenWipe(instruction) { 306 | instruction.successMessage = 307 | "Wiped " + instruction.amount + " from account " + instruction.accountId; 308 | const token = state.getters.getTokens[instruction.tokenId]; 309 | const supplyKey = PrivateKey.fromString(token.wipeKey); 310 | const tx = await new TokenWipeTransaction(); 311 | const client = issuerClient(); 312 | const result = await tokenTransactionWithAmount( 313 | client, 314 | tx, 315 | instruction, 316 | supplyKey 317 | ); 318 | if (result.status) { 319 | const transaction = { 320 | id: result.transactionId, 321 | type: "tokenWipe", 322 | inputs: 323 | "tokenId=" + 324 | instruction.tokenId + 325 | ", AccountId=" + 326 | instruction.accountId + 327 | ", Amount=" + 328 | instruction.amount 329 | }; 330 | EventBus.$emit("addTransaction", transaction); 331 | } 332 | return result.status; 333 | } 334 | 335 | export async function tokenFreeze(instruction) { 336 | const token = state.getters.getTokens[instruction.tokenId]; 337 | const freezeKey = PrivateKey.fromString(token.freezeKey); 338 | const tx = await new TokenFreezeTransaction(); 339 | instruction.successMessage = "Account " + instruction.accountId + " frozen"; 340 | const client = issuerClient(); 341 | const result = await tokenTransactionWithIdAndAccount( 342 | client, 343 | tx, 344 | instruction, 345 | freezeKey 346 | ); 347 | if (result.status) { 348 | const transaction = { 349 | id: result.transactionId, 350 | type: "tokenFreeze", 351 | inputs: 352 | "tokenId=" + 353 | instruction.tokenId + 354 | ", AccountId=" + 355 | instruction.accountId 356 | }; 357 | EventBus.$emit("addTransaction", transaction); 358 | } 359 | return result.status; 360 | } 361 | 362 | export async function tokenUnFreeze(instruction) { 363 | const token = state.getters.getTokens[instruction.tokenId]; 364 | const freezeKey = PrivateKey.fromString(token.freezeKey); 365 | const tx = await new TokenUnfreezeTransaction(); 366 | instruction.successMessage = 367 | "Account " + instruction.accountId + " defrosted"; 368 | const client = issuerClient(); 369 | const result = await tokenTransactionWithIdAndAccount( 370 | client, 371 | tx, 372 | instruction, 373 | freezeKey 374 | ); 375 | if (result.status) { 376 | const transaction = { 377 | id: result.transactionId, 378 | type: "tokenUnFreeze", 379 | inputs: 380 | "tokenId=" + 381 | instruction.tokenId + 382 | ", AccountId=" + 383 | instruction.accountId 384 | }; 385 | EventBus.$emit("addTransaction", transaction); 386 | } 387 | return result.status; 388 | } 389 | 390 | export async function tokenGrantKYC(instruction) { 391 | const token = state.getters.getTokens[instruction.tokenId]; 392 | const kycKey = PrivateKey.fromString(token.kycKey); 393 | const tx = await new TokenGrantKycTransaction(); 394 | instruction.successMessage = 395 | "Account " + instruction.accountId + " KYC Granted"; 396 | const client = issuerClient(); 397 | const result = await tokenTransactionWithIdAndAccount( 398 | client, 399 | tx, 400 | instruction, 401 | kycKey 402 | ); 403 | if (result.status) { 404 | const transaction = { 405 | id: result.transactionId, 406 | type: "tokenGrantKYC", 407 | inputs: 408 | "tokenId=" + 409 | instruction.tokenId + 410 | ", AccountId=" + 411 | instruction.accountId 412 | }; 413 | EventBus.$emit("addTransaction", transaction); 414 | } 415 | return result.status; 416 | } 417 | 418 | export async function tokenRevokeKYC(instruction) { 419 | const token = state.getters.getTokens[instruction.tokenId]; 420 | const kycKey = PrivateKey.fromString(token.kycKey); 421 | const tx = await new TokenRevokeKycTransaction(); 422 | instruction.successMessage = 423 | "Account " + instruction.accountId + " KYC Revoked"; 424 | const client = issuerClient(); 425 | const result = await tokenTransactionWithIdAndAccount( 426 | client, 427 | tx, 428 | instruction, 429 | kycKey 430 | ); 431 | if (result.status) { 432 | const transaction = { 433 | id: result.transactionId, 434 | type: "tokenRevokeKYC", 435 | inputs: 436 | "tokenId=" + 437 | instruction.tokenId + 438 | ", AccountId=" + 439 | instruction.accountId 440 | }; 441 | EventBus.$emit("addTransaction", transaction); 442 | } 443 | return result.status; 444 | } 445 | 446 | async function tokenAssociationTransaction( 447 | transaction, 448 | tokenId, 449 | account, 450 | user, 451 | message 452 | ) { 453 | const client = hederaClientForUser(user); 454 | 455 | const userKey = PrivateKey.fromString(account.privateKey); 456 | 457 | try { 458 | transaction.setTokenIds([tokenId]); 459 | transaction.setAccountId(account.accountId); 460 | 461 | await transaction.signWithOperator(client); 462 | await transaction.sign(userKey); 463 | 464 | const response = await transaction.execute(client); 465 | 466 | const transactionReceipt = await response.getReceipt(client); 467 | if (transactionReceipt.status !== Status.Success) { 468 | notifyError(transactionReceipt.status.toString()); 469 | return { 470 | status: false 471 | }; 472 | } 473 | 474 | // force refresh 475 | await store.dispatch("fetch"); 476 | notifySuccess(message); 477 | return { 478 | status: true, 479 | transactionId: response.transactionId.toString() 480 | }; 481 | } catch (err) { 482 | notifyError(err.message); 483 | return { 484 | status: false 485 | }; 486 | } 487 | } 488 | 489 | export async function tokenAssociate(tokenId, user) { 490 | const account = getAccountDetails(user); 491 | const tx = await new TokenAssociateTransaction(); 492 | const result = await tokenAssociationTransaction( 493 | tx, 494 | tokenId, 495 | account, 496 | user, 497 | "token association successful" 498 | ); 499 | if (result.status) { 500 | const transaction = { 501 | id: result.transactionId, 502 | type: "tokenAssociate", 503 | inputs: "tokenId=" + tokenId + ", AccountId=" + account.accountId 504 | }; 505 | EventBus.$emit("addTransaction", transaction); 506 | } 507 | return result.status; 508 | } 509 | 510 | export async function tokenDissociate(tokenId, user) { 511 | const account = getAccountDetails(user); 512 | const tx = await new TokenDissociateTransaction(); 513 | const result = await tokenAssociationTransaction( 514 | tx, 515 | tokenId, 516 | account, 517 | user, 518 | "token dissociation succesful" 519 | ); 520 | if (result.status) { 521 | const transaction = { 522 | id: result.transactionId, 523 | type: "tokenDissociate", 524 | inputs: "tokenId=" + tokenId + ", AccountId=" + account.accountId 525 | }; 526 | EventBus.$emit("addTransaction", transaction); 527 | } 528 | return result.status; 529 | } 530 | 531 | export async function tokenSwap( 532 | from, 533 | token1To, 534 | token1, 535 | tokenQuantity1, 536 | token2To, 537 | token2, 538 | tokenQuantity2, 539 | hbarTo, 540 | hBars 541 | ) { 542 | const account = getAccountDetails(from); 543 | const client = hederaClientForUser(from); 544 | 545 | try { 546 | const tx = await new TransferTransaction(); 547 | if (token1 !== "" && token1 !== 0 && tokenQuantity1 !== 0) { 548 | tx.addTokenTransfer(token1, account.accountId, -tokenQuantity1); 549 | tx.addTokenTransfer(token1, token1To, tokenQuantity1); 550 | } 551 | if (token2 !== "" && token2 !== 0 && tokenQuantity2 !== 0) { 552 | tx.addTokenTransfer(token2, account.accountId, -tokenQuantity2); 553 | tx.addTokenTransfer(token2, token2To, tokenQuantity2); 554 | } 555 | if (typeof hBars !== "undefined" && hBars !== 0) { 556 | if (from === "Marketplace") { 557 | tx.addHbarTransfer(token1To, new Hbar(-hBars)); 558 | tx.addHbarTransfer(hbarTo, new Hbar(hBars)); 559 | } else { 560 | tx.addHbarTransfer(account.accountId, new Hbar(hBars)); 561 | tx.addHbarTransfer(hbarTo, new Hbar(-hBars)); 562 | } 563 | } 564 | 565 | tx.freezeWith(client); 566 | 567 | // signature only required if transferring from the 'to' address, but 568 | // let's sign anyway for now 569 | //TODO: Only sign if necessary 570 | if (token1To !== "" && token1To !== "0.0.0" && tokenQuantity1 !== 0) { 571 | const sigKey = await PrivateKey.fromString( 572 | getPrivateKeyForAccount(token1To) 573 | ); 574 | await tx.sign(sigKey); 575 | } 576 | if (token2To !== "" && token2To !== "0.0.0" && tokenQuantity2 !== 0) { 577 | const sigKey = await PrivateKey.fromString( 578 | getPrivateKeyForAccount(token2To) 579 | ); 580 | await tx.sign(sigKey); 581 | } 582 | if (hbarTo !== "" && hbarTo !== "0.0.0" && hBars !== 0) { 583 | const sigKey = await PrivateKey.fromString( 584 | getPrivateKeyForAccount(hbarTo) 585 | ); 586 | await tx.sign(sigKey); 587 | } 588 | 589 | const result = await tx.execute(client); 590 | const transactionReceipt = await result.getReceipt(client); 591 | 592 | if (transactionReceipt.status !== Status.Success) { 593 | notifyError(transactionReceipt.status.toString()); 594 | return false; 595 | } else { 596 | // force refresh 597 | await store.dispatch("fetch"); 598 | notifySuccess("tokens transfer successful"); 599 | const transaction = { 600 | id: result.transactionId.toString(), 601 | type: "tokenTransfer", 602 | inputs: "" 603 | }; 604 | EventBus.$emit("addTransaction", transaction); 605 | return true; 606 | } 607 | } catch (err) { 608 | notifyError(err.message); 609 | return false; 610 | } 611 | } 612 | 613 | export async function tokenTransfer( 614 | tokenId, 615 | user, 616 | quantity, 617 | hbar, 618 | destination 619 | ) { 620 | const account = getAccountDetails(user); 621 | const client = hederaClientForUser(user); 622 | try { 623 | const tx = await new TransferTransaction(); 624 | tx.addTokenTransfer(tokenId, account.accountId, -quantity); 625 | tx.addTokenTransfer(tokenId, destination, quantity); 626 | if (hbar !== 0) { 627 | // token recipient pays in hBar and signs transaction 628 | tx.addHbarTransfer(destination, new Hbar(-hbar)); 629 | tx.addHbarTransfer(account.accountId, new Hbar(hbar)); 630 | tx.freezeWith(client); 631 | const sigKey = await PrivateKey.fromString( 632 | getPrivateKeyForAccount(destination) 633 | ); 634 | await tx.sign(sigKey); 635 | } 636 | 637 | const result = await tx.execute(client); 638 | const transactionReceipt = await result.getReceipt(client); 639 | 640 | if (transactionReceipt.status !== Status.Success) { 641 | notifyError(transactionReceipt.status.toString()); 642 | return false; 643 | } else { 644 | // force refresh 645 | await store.dispatch("fetch"); 646 | notifySuccess("tokens transfer successful"); 647 | const transaction = { 648 | id: result.transactionId.toString(), 649 | type: "tokenTransfer", 650 | inputs: 651 | "tokenId=" + 652 | tokenId + 653 | ", from=" + 654 | account.accountId + 655 | ", to=" + 656 | destination + 657 | ", amount=" + 658 | quantity 659 | }; 660 | EventBus.$emit("addTransaction", transaction); 661 | return true; 662 | } 663 | } catch (err) { 664 | notifyError(err.message); 665 | return false; 666 | } 667 | } 668 | 669 | export async function tokenDelete(token) { 670 | const client = issuerClient(); 671 | try { 672 | let tx = await new TokenDeleteTransaction(); 673 | tx.setTokenId(token.tokenId); 674 | 675 | await tx.signWithOperator(client); 676 | if (typeof token.adminKey !== "undefined") { 677 | await tx.sign(PrivateKey.fromString(token.adminKey)); 678 | } 679 | 680 | const response = await tx.execute(client); 681 | 682 | const transactionReceipt = await response.getReceipt(client); 683 | 684 | if (transactionReceipt.status !== Status.SUCCESS) { 685 | notifyError(transactionReceipt.status.toString()); 686 | return false; 687 | } else { 688 | // force refresh 689 | await store.dispatch("fetch"); 690 | notifySuccess("Token deletion successful"); 691 | const transaction = { 692 | id: response.transactionId.toString(), 693 | type: "tokenDelete", 694 | inputs: "tokenId=" + token.tokenId 695 | }; 696 | EventBus.$emit("addTransaction", transaction); 697 | return true; 698 | } 699 | } catch (err) { 700 | notifyError(err.message); 701 | return false; 702 | } 703 | } 704 | --------------------------------------------------------------------------------