Skip to content

Instantly share code, notes, and snippets.

@y12studio
Last active December 24, 2019 08:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save y12studio/f142cd9789c7d396d8f7 to your computer and use it in GitHub Desktop.
Save y12studio/f142cd9789c7d396d8f7 to your computer and use it in GitHub Desktop.
Ethereum以太坊智能合約環境說明

簡介

目前智能合約(智約)使用以太坊測試網部署測試,以智約驗證概念為主,未來可望新增Linux基金會的HyperLedger專案的商轉網路,或是外掛比特幣網路側鏈的Rootstock平台網路,就2016年來看,智約概念驗證可用網路裡以太坊較主流,次起智約網路預計2017年才會明朗。

Ethereum Project https://ethereum.org/

Hyper Ledger Foundation https://www.hyperledger.org/

環境設定

  1. 下載最新錢包軟體 https://github.com/ethereum/mist/releases
  2. 開啟軟體後切換到develop-network-testnet,等待同步完成,過程視網路電腦硬體條件數小時不等。

取得測試ETH

使用以太坊的測試網路進行智約運作需要測試網專用ETH,測試用ETH專供測試用並無任何市場價值,需要測試用ETH可到下面連結填入帳號地址取得少數量測試幣。https://zerogox.com/ethereum/wei_faucet

自製代幣發行

參考 https://www.ethereum.org/token

注意Token還未有標準語法,所以智約轉帳寫transfer()或是transxx()都可以執行,只是考慮到Mist等錢包可以直接發送較方便,建議採用目前常用的寫法。Token standard · Issue #20 · ethereum/EIPs ethereum/EIPs#20

交換測試

雙方互相發送各自發行代幣進行交換測試。對方在Mist錢包要看到別人的客制代幣有兩種方式,Contracts頁面的+WATCH CONTRACT(WC)跟+WATCH TOKEN(WT),WT只要提供地址就可以,WC還需要加上JSON Interface的資料,兩個設定差別在於WC可以操作更多智約功能例如買進賣出等,而WT只能執行標準轉帳查餘額等功能。

自製代幣交換測試成功後,有一次機會中0.1ETH,細節請上 https://y12.slack.com 討論,slack為封閉邀請制請提供電郵以利發送邀請,聯絡資料參閱 https://github.com/y12studio

Y12測試網智能合約

YRT2代幣

發送加入隨機值,發送100.00可能出現100.00-100.99。

Solidity Source https://gist.github.com/y12studio/8e9ec71ed006dfec36bb

Contract JSON Interface https://gist.github.com/y12studio/b52c7ef5c191e5e4059d

Address 0x95e6E3FeDd7D905c059ECeB4385B60B08A203694

YRT3代幣

測試網發行,發送買賣代幣植入隨機行為,買賣預設ETH/YRT3=10000.00。

Solidity Source https://gist.github.com/y12studio/6ac0cebdc43d0ea504da

Contract JSON Interface https://gist.github.com/y12studio/f2f15b0a38208a3973f1

Address 0xFb7149757DD34B669faf1cCAD1A2B5656Ce12bFC

YSOA1競標約

競標約起於2016-03-19 21:20 UTC+8:00,10天後終止,每次下標成功轉帳到合約會觸發退款,合約內只保持最高標資金,前一最高標的資金會被退回原發送地址,退款由成功下標觸發不需其他人介入,約滿才能人工觸發讓合約資金轉入當初設定標金地址。

Solidity Source https://gist.github.com/y12studio/bcc475ab5f9cbbf11298

JSON Interface https://gist.github.com/y12studio/34960642eafe2341275b

Address 0x1bA4a8C6Ee4B5d69EeA6B3066d50D802991A5A7E

YSOA2

改自YSOA1增加費率設定,競標約起於2016-03-21 11:30 UTC+8:00,30天後終止,下標成功轉帳到合約會觸發前標扣除費用後退款,新增rescueBlanceDevOnly開發專用功能,用來避開合約寫錯卡死時可全額轉出。

Solidity Source https://gist.github.com/y12studio/725d5dd9a06a6cdfe7b1

JSON Interface https://gist.github.com/y12studio/151660f4c091d9c7b1c2

Address 0xAb3fD66813C78E56EB4590672Af57B5071f18049

YSOA3

改自YSOA3增加隨機費率設定,競標約起於2016-03-21 17:20 UTC+8:00,30天後終止,新增0-100隨機數,扣費用前如隨機數小於設定luckPercent時不收費用。

Solidity Source https://gist.github.com/y12studio/05887d050c3a951ff875

JSON Interface https://gist.github.com/y12studio/937e5d67e7a718f6dd8e

Address 0x51fc3B4328A355706359B57dAb6f8d52DFc65c86

Y12 Safe Remote Purchase

1.賣家建立合約並放入價值商品2倍ETH當押金。 2.買家確認賣家合約押金無誤,confirmPurchase()轉入與賣家等值押金。 3.買家收到貨物後確認,confirmReceived()賣家收回押金加價金,買家收回押金減去價金。

YSRP1

https://gist.github.com/y12studio/ff5b3f96b72632bfdf72

Y12 Marriage Contract 智能婚約

YMC1

親友於確認婚約後可存入紅包,解約後可自動轉回一半紅包不需第三方介入。

Source https://gist.github.com/y12studio/51f31f11f2dd20140019

JSON Interface https://gist.github.com/y12studio/2097761fdf2688f87fad

Address 0xDd4C729A89B6c131c397DD80e97Da2F4Bc83df25

YMC2 智能證券化婚約

親友於確認婚約後可存入紅包並取回可贖回一半的股份,該股份可以轉讓,於解約後領回一半紅包。

Source https://gist.github.com/y12studio/bcf9dd4ce1792a897953

JSON Interface https://gist.github.com/y12studio/13063e13d7390292a0df

Address 0xFdB1E938E0b0bf63D595fe17115cA31d7390395D

YMC3 Y12 Marriage Contract 3 with GovOracle

政府驗證服務智能婚約,發起婚約前需先確認發起人當下婚姻狀態。

Source https://gist.github.com/y12studio/383ead51a3193cba33d7bc15defa48bb

Y12 Oraclize Testnet

Oraclize http://docs.oraclize.it/

YOT1

取得美元報價可用來錨定價格,例如代幣儲備不足可設計需補充,不足額多久直接清算退ETH給持代幣者。

Source https://gist.github.com/y12studio/eba0b90e789455137ab3

JSON Interface https://gist.github.com/y12studio/f08612cba748f9546531

Address 0x4848d75608C4a52d2681d1A24483bc7757143184

Y12 RealityKey

Ethereum (also Eris and other EVM-based platforms) https://www.realitykeys.com/developers/resources#ethereum

YRK1

Address 0xe60ebA553897D1cDe86836c9C9E3ED3dD1727aC1

Source https://gist.github.com/y12studio/bfff0c442c662310a458

JSON Interface https://gist.github.com/y12studio/33167268a8425a3b241e

YES/NO 1 Bitcoin to be at least 200 US Dollar on March 4, 2016 https://www.realitykeys.com/exchange/7508

Reality key json https://www.realitykeys.com/api/v1/exchange/7508?accept_terms_of_service=current

代幣參考範例

發送隨機加上0-100單位 RandomToken https://gist.github.com/y12studio/8e9ec71ed006dfec36bb

Tokens/Standard_Token.sol https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/Standard_Token.sol

其他合約範例

Solidity by Example http://solidity.readthedocs.org/en/latest/solidity-by-example.html

develop console

RandomToken Example

caddr=[Mist Contracts - Copy Address]
ABI=[Mist Contracts - Show Interface]
ydao2=web3.eth.contract(ABI).at(caddr);
ydao2.owner()
ydao2.balanceOf(ydao2.owner()).toString()
ydao2.buyPrice().toString()
b=web3.eth.getBalance(caddr)
web3.fromWei(b,'ether').toString()
ydao2.randomGen(100).toString()
ydao2.randomGen().toString()
web3.eth.accounts
ydao2.buyPrice().toString()
ydao2.setPrices(10000,20000,{from:web3.eth.accounts[1]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment