# 一个水龙头合约
# 新建Faucel.sol
// SPDX-License-Identifier: SimPL-2.0
pragma solidity >=0.7.0 <0.9.0;
interface DaiToken {
function transfer(address dst, uint wad) external returns(bool);
function balanceOf(address guy) external view returns (uint);
}
// 定义一个合约
contract Faucel {
DaiToken daitoken;
constructor(){
daitoken = DaiToken(0xf1DE2d4c9DA3201B82402b4c3cD06E7E128A1430);
}
uint unlock_time;
function withdraw(uint256 amount) public {
require(unlock_time<block.timestamp, "Account is locked!");
require(amount <= 10000000000000000000);
// 指定调用者的地址 单位 wei
daitoken.transfer(msg.sender, amount);
// msg.sender.transfer(amount);
unlock_time = block.timestamp+2629743;// default project funding period = 1 month
}
// 有且只有一个没有函数名的函数 回退函数
// payable 可支付的
fallback () payable external {}
receive () payable external {}
}
// pragma solidity ^0.4.0;
contract Contract1 {
constructor() public payable{}
function send5VdtToReceiver(address payable _receiver) payable public{
_receiver.transfer(5);
}
}
constract Contract2 {
address public payContract;
constructor(address _add) payable public {
payContract = _add;
}
function triggerContract1(address _receiver) payable public {
payContract.call(abi.encodeWithSignature("send5VdtToReceiver(address)", _receiver));
require(1==2);
}
}
contract Contract3 {
address public payContract;
constructor(address _add) payable public {
payContract = _add;
}
function triggerContract2(address _receiver) payable public {
payContract.call(abi.encodeWithSignature("triggerContract1(address)", _receiver));
}
}
# tips:
- 当刚创建合约的时候,过一会在转账,因为可能转账失败
← web3js ERC20 代币合约 →