1. 程式人生 > >區塊鏈2.0以太坊智慧合約solidity之helloworld

區塊鏈2.0以太坊智慧合約solidity之helloworld

由於只能合約是放在區塊鏈上面的程式碼,這給我們的除錯帶來了很多的困難,還好有線上的編譯器:

https://remix.ethereum.org

第一個程式碼:
pragma solidity ^0.4.4;
contract Counter {
uint count = 0;
address owner;


constructor() public
{
  owner = msg.sender;  
}


function increment() public {
uint step = 10;
if (owner == msg.sender) {
count = count + step;
}
}
function getCount() constant public returns (uint)  {
return count;
}
function kill() public {

if (owner == msg.sender) {
selfdestruct(owner);
}
}

}

第一行代表solidity的版本,^代表向上相容版本5.0

第二行contract Counter為一個智慧合約類物件

第三行、四行為屬性:

uint count = 0;

address owner;

下面是三個函式,其中建構函式為:

constructor() public
{
  owner = msg.sender;  

}








網址:http://www.qukuailianxueyuan.io/



欲領取造幣技術與全套虛擬機器資料

區塊鏈技術交流QQ群:756146052  備註:CSDN

尹成學院微信:備註:CSDN