【合约外部调用】solidity语言是一个合约调用另外一个合约【同一个区块链网络】的方法【使用接口声明关系】

solidity官方时间库:https://github.com/pipermerriam/ethereum-datetime 

一个如何调用主网智能合约的方法案例!(此案例用Rinkeby测试网络部署)

这里接口的作用:只是用来声明需要调用的方法!

一个如何调用主网智能合约的方法案例!


pragma solidity >=0.5.0 <0.7.0;

interface DateTime {
    function getDay(uint timestamp) view external returns (uint16);
}

contract Collection {
    // 必须把当前合约部署的网络和0x92482Ba45A4D2186DafB486b322C6d0B88410FE7同一个网络
    DateTime time = DateTime(0x92482Ba45A4D2186DafB486b322C6d0B88410FE7);
    uint target = 100 ether;
    uint percentage = 1;
    uint16 private datatime;

    constructor() public {

    }

    function() external payable{
        // 这里实现代币自动兑换
    }
    
    function test_time() public view returns(uint16){
        return time.getDay(1554710705);
    }
}

参考别人的分析:https://blog.csdn.net/lj900911/article/details/83037691

interface Token {
    // 普通转账(禁止冻结账号交易))
    function transfer(address to, uint256 value) external returns (bool);
    function balanceOf(address owner) external view returns (uint256);
}

contract Collection {
    using UintEther for uint;
    address private admin_account;
    Token private token;
    uint private target;
    uint private percentage;
    
    event SendToken(address sender,uint value);

    constructor(address token_contract) public {
        admin_account = msg.sender;
        target = 10 ether;
        percentage = 1;
        token = Token(token_contract);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43343144/article/details/88951698
今日推荐