區塊鏈給我的感覺就是記賬簿。在區塊鏈系統中,每個人都可以來進行記賬,系統會選擇記賬最快最好的人,把這個人所記錄的內容寫到賬本,並將這賬本內容發給系統內所有人備份。
區塊鏈領域的高技術性含量和極度稀缺性在從業者薪資上得到反映,區塊鏈從業者平均年薪達34.09萬元,超過AI人工智能領域平均年薪,居薪酬排行榜首位。在2018年區塊鏈大爆發但專業人才少,所以很感興趣的從漸進式構建從原理到實戰。
一、 geth客戶端
1.geth私有鏈搭建
1.1geth的安裝
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa: ethe reum/ethereum
sudo apt-get update
sudo apt-get install ethe reum
1.2配置創世塊文件
①創建一個名爲genesis.json的文件,寫入圖片中的代碼
{
"config": {
"chainId": 18,//參數配置相同
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x2",//挖礦難度
"extraData" : "",
"gasLimit" : "0x2fefd8",// gasLimit上限
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
②初始化創世節點並設置data目錄啓動節點
geth –datadir ./data init gensis.json
geth – datadir ./data –network 15 – port 30303 –rpc – rpcaddr 0.0.0 – rpcport 8545 – rpcapi ‘db,net,eth,web3,personal’
--rpccorsdomain ‘*’ –nat “any” –nodiscover console
1.3賬戶管理
①創建賬號
Personal.newAccount(“123”)
②查看賬號
Eth.accounts
③查看餘額
Eth.getBalance(eth.accounts[0])
1.4啓動挖礦
①啓動挖礦miner.start()
②停止挖礦miner.stop()
2.geth的操作命令
二、 智能合約的編寫及調試技巧
2.1 博彩行業的痛點分析
- 賴賬
- 假球
- 舞弊、欺詐
比特幣是數字貨幣;數字資產。博彩行業是數字資產中的一種,區塊鏈解決數字資產的問題非常合適
2.1.1 區塊鏈解決痛點
- 公開透明
- 不可篡改
- 智能合約交割
- 加密保護
2.2 足彩合約的開發
2.2.1常見以太坊應用架構
2.2.2核心功能與角色
①CTO:創建遊戲
②玩家:下注
③CTO:遊戲開獎
2.3合約開發
soccer.sol
pragma solidity^0.4.20;
contract betsoccer {
address cto;
struct Game {
string hostTeam;
string guestTeam;
uint16 point;
}
Game public game;
struct Player {
address addr;
uint amout;
}
Player[] public teamsA;
Player[] public teamsB;
uint totalTeamA;
uint totalTeamB;
bool canReset;
//構造函數和設置
function soccergame(address _cto)payable public {
cto = _cto;
canReset = true;
}
function setGame(string A,string B,uint16 pk)public {
assert(canReset);
assert( msg.sender == cto);//must cto
game.hosetTeam = A;
game.guestTeam = B;
game.point = pk;
canReset = false;
totalTeamB = 0;
totalTeamA = 0;
}
//下注函數
function bet(bool aORb)public payable{
assert( msg.value > 0);
Player memory player = Player(msg.sender,msg.value);
if( aORb ){
//host
teamsA.push(player);
totalTeamA += msg.value;
}
else{
teamsB.push(player);
totalTeamB += msg.value;
}
}
//開獎函數,只有CTO可以開獎
function openGame( uint8 scoreA, uint8 scoreB)public payable{
assert( msg.sender == cto);
//who win? A=1B=0,50
if( scoreA *100 > scoreA *100 + game.point){
//host win
for(i=0;i< teamsA.length;i++){
player = teamsA[i];
player.addr.transfer(90*totalTeamB * player.amount/totalTeamA/100 + player.amount);
}
cto.transfer(totalTeamB * 10 /100);
}
else{
for(i=0;i< teamsA.length;i++){
player = teamsB[i];
player.addr.transfer(90*totalTeamA * player.amount/totalTeamB/100 + player.amount);
}
cto.transfer(totalTeamA * 10 /100);
}
}
}
DApp一定要做角色分析
Solidity語法相對簡單,但是要多考慮安全
三、版權交易系統設計
3.1版權加以系統的痛點
背景:一個攝影師社交網絡,攝影師在其中分享照片,攝影師對照片進行評價,挑選出最優秀的作品,媒體和企業在其中發下你有價值的照片並且購買版權
痛點:
- 收入模式不明確,長期處於虧損狀態
- 盜版發現和認定困難,賠償金追索成本高昂
- 社交平臺屬性對優質照片的挑選和確認構成限制
- 社區發展進入瓶頸期,需要新的模式
3.2版權交易系統的設計
3.2.1 區塊鏈系統的解決思路
- 金融圈裏平民化
- 消除信息不對稱
- 提升流動性
- 跨邊界強協作
3.2.2 角色分析
- Photographer
- Curator
- Buyer
- Governor
- Investor
3.2.3 角色激勵設計
角色 | 激勵行爲 | 懲罰行爲 |
---|---|---|
Photographer | 拍攝優秀圖片 | 盜用、刷單 |
Curator | 點贊、評論 | 點贊、評論 |
Buyer | 投資眼光精準 | 惡意炒作 |
Governor | 公正公平 | 暗箱操作、腐敗 |
Investor | 投資眼光精準 | 惡意炒作 |
3.2.4 雙層token設計
總結:
1.痛點分析是區塊鏈系統設計的必要步驟
2.好的經濟系統有助於系統未來的良性發展