Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 1.39 KB

Contract Type Cont..md

File metadata and controls

56 lines (47 loc) · 1.39 KB

Every contract defines its own type. Contracts can be explicitly converted to and from the address type. Contract types do not support any operators. The members of contract types are the external functions of the contract including any state variables marked as public.


Slide Screenshot

083.jpg


Slide Deck

  • type(X)
  • X -> Contract
  • type(C).name -> Contract Name
  • type(C).creationCode
  • type(C).runtimeCode

References


Code Examples

contract C {
			string public nameAccessor = type(C).name;
			string public constant constantNameAccessor = type(C).name;

			function name() public virtual returns (string memory) {
				return type(C).name;
			}
		}
contract D is C {
	function name() public override pure returns (string memory) {
		return type(D).name;
	}
	function name2() public pure returns (string memory) {
		return type(C).name;
}
function getCreationCode() public returns(bytes memory){
        address addr;
        bytes memory code = type(F).creationCode;
        return code;
    }

}

contract F {
    constructor() public payable {}

    function destroy(address payable inheritor) external {
        selfdestruct(inheritor);
    }
}