Last active
March 16, 2022 17:46
-
-
Save rpaskin/6a86c1713695b6fe05146e7b878d664a to your computer and use it in GitHub Desktop.
Solidity contract call contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
// Adapted from https://ethereum.stackexchange.com/questions/45277/calling-one-contract-to-another-contract-method | |
contract Base { | |
uint public dataA; | |
bytes4 public dataB; | |
function setAB(uint a, bytes4 b) public { | |
dataA = a; | |
dataB = b; | |
} | |
function getA() public view returns(uint) { | |
return dataA ; | |
} | |
function getB() public view returns(bytes4) { | |
return dataB ; | |
} | |
} | |
contract Extra { | |
Base base; | |
function Extra() public { | |
base = new Base(); | |
} | |
function getBaseAddres() public view returns(address) { | |
return address(base); | |
} | |
function baseGetA() public view returns(uint) { | |
return base.getA(); | |
} | |
function baseGetB() public view returns(bytes4) { | |
return base.getB(); | |
} | |
function baseSetAB(uint a, bytes4 b) public returns(bool success) { | |
base.setAB(a,b); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment