Skip to content

Instantly share code, notes, and snippets.

@apoorvlathey
Created May 24, 2021 05:33
Show Gist options
  • Save apoorvlathey/e75deb2aeb94558798e51a5b767c548a to your computer and use it in GitHub Desktop.
Save apoorvlathey/e75deb2aeb94558798e51a5b767c548a to your computer and use it in GitHub Desktop.
Contract that allows to deploy any arbitrary contract by just passing its initcode as function argument
// For reference: https://twitter.com/nanexcool/status/1396667368017997829
pragma solidity ^0.5.7;
contract DeployContract {
function deploy(bytes memory code) public returns(address addr) {
assembly {
addr := create(0, add(code, 0x20), mload(code))
if iszero(extcodesize(addr)) {
revert(0,0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment