Created
August 3, 2022 01:11
-
-
Save developeruche/04581c1bdfc28095567c2dde392f8fc1 to your computer and use it in GitHub Desktop.
Explains Bytes Code and Init Code
This file contains 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: MIT | |
pragma solidity ^0.8.13; | |
contract ByteCodeManager { | |
function getBytecode(address _owner, uint _foo) public pure returns (bytes memory) { | |
bytes memory bytecode = type(TestContract).creationCode; | |
return abi.encodePacked(bytecode, abi.encode(_owner, _foo)); | |
} | |
function getInitCode() public pure returns (bytes memory) { | |
bytes memory bytecode = type(TestContract).creationCode; | |
return bytecode; | |
} | |
} | |
contract TestContract { | |
address public owner; | |
uint public foo; | |
constructor(address _owner, uint _foo) payable { | |
owner = _owner; | |
foo = _foo; | |
} | |
function getBalance() public view returns (uint) { | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment