一、智能合約入門(一)用Remix寫一個水龍頭合約
1、合約代碼
//沒有“^”則表示指定版本
pragma solidity ^0.4.19;
//Our first contract is faucet!
contract Faucet {
//Give our ether to anyone who asks
function withdraw(uint withdraw_amount) public {
//Limit withdraw amount
require(withdraw_amount <= 1000000000000000000);
//send the amount to the address that requested it表示sender調用transfer函數
msg.sender.transfer(withdraw_amount);
}
//accept any incoming amount
function () public payable {}
}
2、解除waring提醒報錯
3、合約版本選擇
4、合約部署
二、智能合約入門(二)水龍頭合約改進
1、合約交互:給合約地址發送以太
複製合約地址,在metamask上發送
2、合約交互:模擬水龍頭髮幣,將合約內的以太提到自己賬戶
三、總結
以上內容來自尚硅谷的教學視頻,對熟悉metamask、solidity IDE比較有幫助。