-
-
Save casweeney/496e24cab7548d7552b75d2811593bb8 to your computer and use it in GitHub Desktop.
Explains Bytes Code and Init Code
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: 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