1. 程式人生 > >區塊鏈以太坊DApp高薪實戰有感

區塊鏈以太坊DApp高薪實戰有感

  區塊鏈給我的感覺就是記賬簿。在區塊鏈系統中,每個人都可以來進行記賬,系統會選擇記賬最快最好的人,把這個人所記錄的內容寫到賬本,並將這賬本內容發給系統內所有人備份。
  區塊鏈領域的高技術性含量和極度稀缺性在從業者薪資上得到反映,區塊鏈從業者平均年薪達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設計
雙層token設計

總結:

1.痛點分析是區塊鏈系統設計的必要步驟
2.好的經濟系統有助於系統未來的良性發展