Dapp開發教程一Asch Dapp
阿新 • • 發佈:2018-12-19
Asch官網文件好像沒人維護似得,有好多問題,經本人多次嘗試,順利解決問題,遂記錄下來。
1.下載asch原始碼
git clone https://github.com/AschPlatform/asch.git
2.編譯原始碼
cd asch
npm install
3.這時啟動會發現無法同步區塊,升級到最新版本並啟動就可以了
./aschd upgrade
node app.js
此時會發現控制檯在產生區塊 http://localhost:4096/api/blocks/getHeight 可以檢視區塊高度 http://localhost:4096 可以開啟登入頁,登入localnet 的創世區塊會有1億初始XAS,創世賬戶主密碼為:stone elephant caught wrong spend traffic success fetch inside blush virtual element
4.安裝asch-cli
cd ..
git clone https://github.com/AschPlatform/asch-cli
cd asch-cli
npm install
5.生成新賬戶
./asch-cli/bin/asch-cli crypto -g
? Enter number of accounts to generate 5
隨後會生成5賬戶,包含地址和公私鑰
6.生成應用模版
mkdir manage-money-matters cd manage-money-matters ../asch-cli/bin/asch-cli chain -c Copying template to the current directory ... ? Enter chain name manage-money-matters ? Enter chain description cs ? Enter chain link https://manage-money-matters.zip ? Enter chain icon url https://manage-money-matters.png ? Enter public keys of chain delegates - hex array, use ',' for separator d2d23d27dd530b0461cfcb762307e3fba8545011d1cdc78fc6b9b45fdc53d2d6,9d585f4bad66 c7b56c74826767ca3aa10961ea6c70a66ecc7593d3bebb517552,f98e28f0220edcaca0ae9f62010436bc79ab237346550a103665dada166f30b2,a43dc3d390fb44b882b8178627f0e417c d92a6c89a3cd63e7735e92871a1cd78,474a8257c06ec5a9df47a40c099fc6f36496f2a2efc912a71466bb92874a1cff ? How many delegates are needed to unlock asset of a chain? 3 Chain meta information is saved to ./chain.json ...
7.生成創世區塊
不發行資產的情況:
../asch-cli/bin/asch-cli chain -g
? Enter master secret of your genesis account [hidden]
? Do you want publish a inbuilt asset in this chain? No
New genesis block is created at: ./genesis.json
發行資產的情況
../asch-cli/bin/asch-cli chain -g ? Enter master secret of your genesis account [hidden] ? Do you want publish a inbuilt asset in this chain? Yes ? Enter asset name, for example: BTC, CNY, USD, MYASSET CNY ? Enter asset total amount 100000000 ? Enter asset precision 8 New genesis block is created at: ./genesis.json
8.註冊應用到區塊鏈
利用 asch-cli 提供的 registerchain來完成應用到區塊鏈的註冊。 要選擇一個有 XAS 的賬戶,這裡我們使用創世賬戶
../asch-cli/bin/asch-cli -H 127.0.0.1 -P 4096 registerchain -e "stone elephant caught wrong spend traffic success fetch inside blush virtual element" -f chain.json
當釋出到主鏈時用如下命令
../asch-cli/bin/asch-cli -H <mainnet host> -P <mainnet port> -M registerchain -e "<your secret>" -f chain.json
此時進客戶端檢視,會顯示
9.部署應用
在正式部署應用之前,我們需要先修改 config.json ,新增之前生成的受託人以及 peers。其中 peers 裡的 ip 要改成自己伺服器的 IP 地址
{
"secrets": [
"embrace knee throw alter forward brother lift swarm dizzy accident cliff license",
"bonus symptom climb merit critic admit prevent eye decade entry brick question",
"million deputy search good attract employ office glance elegant brand bacon loud",
"garage glide connect ketchup circle dish speak drive device whale carbon unknown",
"tobacco wine monster mom rapid sting car hole amazing aisle arena aisle"
],
"peers":[{"ip":"127.0.0.1","port":4097}]
}
然後執行命令:
cd ..
cp -r manage-money-matters asch/chains/
cd asch
node app.js或./aschd start