Ming-der Wang, twitter @mingderwang
ming@Log4Analytics.com
11/26/2016 9:30-12am
Blockchain Summit 2016, Taipei
王銘德
Taipei Ethereum
那什麼是 "智能合約"? - Smart Contracts
如何在 Ethereum 網路上開發應用?
也就是寫一個所謂的"智能合約“
注意! 它名字取的不好 (既沒有A.I. 也沒有法律效用)
例如:
你至少要安裝一個 Ethereum Wallet
程式編輯與編譯, 可以用網路版
或用你最喜歡的編輯器 vim 也行
最高竿的直接用 web3.js 在 Chrome debugger 裡用 CLI 指令集直接執行也行.
也可用 devtool 介面
Ethereum Wallet
Solidity Realtime Compiler
Chrome devtool
contract mortal {
address owner;
function mortal() {
owner = msg.sender; }
function kill() {
if (msg.sender == owner)
selfdestruct(owner); }
}
contract helloworld is mortal {
/* helloworld 就會繼承了 mortal 的 kill 功能*/
string storeData;
function set(string x) {
storeData = x; }
function get() constant returns (string data) {
return storeData; }
}
bool
int8, int16, int24 ... int256
uint8, uint16, ... uint256
uint and int are aliases for uint256 and int256,
address
string
bytes1, bytes2, bytes3, ..., bytes32.
byte is an alias for bytes1
struct Funder { address addr; uint amount; }
int8 y = -3; uint x = uint(y);
uint20 x = 0x123; var y = x;
// y will be unit20 too
uint32 a = 0x12345678; uint16 b = uint16(a); // b will be 0x5678 now
contract MyToken { /* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
function MyToken() {
balanceOf[msg.sender] = 21000000; }
}
contract C { function f(uint len) { uint[] memory a = new uint[](7); bytes memory b = new bytes(len);// memory // Here we have a.length == 7 and b.length == len a[6] = 8; } }
contract Sharer { function sendHalf(address addr) returns (uint balance) { if (!addr.send(msg.value/2)) throw; // also reverts the transfer to Sharer return this.balance; } }
address holds a 20 byte value (size of an Ethereum address). Address types also have members, like send()
address x = 0x123; address myAddress = this; if (x.balance < 10 && myAddress.balance >= 10) x.send(10);
All contracts inherit the members of address, so it is possible to query the balance of the current contract using this.balance.
address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName"); nameReg.call(bytes4(sha3("fun(uint256)")), a);
[ { "constant": false, "inputs": [], "name": "kill", "outputs": [], "type": "function" }, { "constant": false, "inputs": [ { "name": "x", "type": "string" } ], "name": "set", "outputs": [], "type": "function" }, { "constant": true, "inputs": [], "name": "get", "outputs": [ { "name": "data", "type": "string", "value": "hello CCLiang" } ], "type": "function" } ]
跟你的 Contract Address
寄給他們 Contract JSON
點擊
Contract Address
點擊
http://dapps.ethercasts.com/
https://hack.ether.camp/
Ethereum-based
Bitcoin-based
web3.js
solc (solidity 編譯器)
Truffle
Embark
Dapple & Dappsys
Ethereum-based
歡迎參加 EtherTW.slack.com 線上討論
https://goo.gl/S6nhKv <---- 加入slack
Taipei Ethereum