Skip to content

Instantly share code, notes, and snippets.

@developeruche
Created August 3, 2022 01:11
Show Gist options
  • Save developeruche/04581c1bdfc28095567c2dde392f8fc1 to your computer and use it in GitHub Desktop.
Save developeruche/04581c1bdfc28095567c2dde392f8fc1 to your computer and use it in GitHub Desktop.
Explains Bytes Code and Init Code
// 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