Skip to content

Instantly share code, notes, and snippets.

@casweeney
Forked from developeruche/btyesmanager.sol
Created August 3, 2022 15:02
Show Gist options
  • Select an option

  • Save casweeney/496e24cab7548d7552b75d2811593bb8 to your computer and use it in GitHub Desktop.

Select an option

Save casweeney/496e24cab7548d7552b75d2811593bb8 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