一、智能合约入门(一)用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比较有帮助。