成都创新互联网站制作重庆分公司

Solidityinterface怎么使用

本篇内容主要讲解“Solidity interface怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Solidity interface怎么使用”吧!

阿巴嘎ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

以太坊网络把在网络上读与写数据进行了区分,写数据被称作交易(transaction),读数据被称作调用(call)。

使用工具:remix IDE —browser-based

场景:两个合约分别部署在不同的地址,相互间的调用 数据交互操作

第一个合约:Doug.sol代码如下:

pragma solidity ^0.4.19;
contract Doug{
    mapping (bytes32 => uint) public contracts;
    function Doug() {
        contracts['hww'] = 1;
        contracts['brian'] = 2;
        contracts['zzy'] = 7;
    }
    
    function getDougName(string _name) public view returns(string) {
        return _name;
    }
    
     function getDougAge(uint _age) public pure returns(uint) {
        return 3 ** _age;
    }
}

第二个合约 myContract.sol 代码如下:

pragma solidity ^0.4.19;

contract DogInterface {
    function getDougAge(uint _age) returns (uint);
    function contracts(bytes32 name) returns (uint);
}

contract main{
    
    event FetchContract(address dogInterfaceAddress, address sender, bytes32 name);
    
    address DOUG;
    
    address dogInterfaceAddress = 0x3e6494333ae0e929ade0eb9a19fb02632b8e07cf;
    DogInterface dogContract = DogInterface(dogInterfaceAddress);
          
    function setDOUG(address _doug) {
        DOUG = _doug;
    }
    
    function dougOfage(uint _age) public view returns(uint) {
        
        uint num =  dogContract.getDougAge(_age);
        return _age+num;
        //   return num;
    }
    
    function uintOfName(bytes32 _name)  returns (uint) {
        
        dogContract.contracts(_name);
        FetchContract(dogInterfaceAddress, msg.sender, _name);
       
    }
    
    // function getTest(string _name) public view returns(string) {
    //     string memory newName = _name ;
    //     DogInterface(DOUG).getDougName(newName);
    //     return newName;
    // }
}

执行结果:

  Solidity interface怎么使用

到此,相信大家对“Solidity interface怎么使用”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


名称栏目:Solidityinterface怎么使用
本文URL:http://cxhlcq.com/article/gcdhop.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部