Solidity smart contracts call smart contracts

Source: https://medium.com/@blockchain101/calling-the-function-of-another-contract-in-solidity-f9edfa921f4c

Contract 1:

pragma solidity ^ 0.4 . 18 ;
contract Deployed {
    uint  public a = 1 ;
    
    function setA(uint _a) public returns (uint) {
        a = _a;
        return a;
    }
    
}

 

Contract two calls contract one:

pragma solidity ^ 0.4 . 18 ;
contract Deployed {
    
    function setA(uint) public returns (uint) {}
    
    function a() public pure returns (uint) {}
    
}
contract Existing  {
    
    Deployed dc;
    
    function Existing(address _t) public {
        dc = Deployed(_t);
    }
 
    function getA() public view returns (uint result) {
        return dc.a();
    }
    
    function setA(uint _val) public returns (uint result) {
        dc.setA (_val);
        return _val;
    }
    
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325145175&siteId=291194637