Skip to content

Instantly share code, notes, and snippets.

@elijahboston
Created October 18, 2023 14:58
Show Gist options
  • Save elijahboston/8d42f5a75984239ea5dc2041e09cca70 to your computer and use it in GitHub Desktop.
Save elijahboston/8d42f5a75984239ea5dc2041e09cca70 to your computer and use it in GitHub Desktop.
contract factory contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// _____ _ _ _ _ _____ _
// / ___| | | | | | | |_ _| | |
// \ `--.| |_ ___ __ _| | |_| |__ | | ___ ___| |_
// `--. \ __/ _ \/ _` | | __| '_ \| |/ _ \/ __| __|
// /\__/ / || __/ (_| | | |_| | | | | __/\__ \ |_
// \____/ \__\___|\__,_|_|\__|_| |_\_/\___||___/\__|
//
// http://stealthtest.com
contract StealthTestContractFactory {
event ContractDeployed(address contractAddress);
function deployContract(bytes memory bytecode, bytes32 salt) public returns (address) {
address addr;
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}
require(addr != address(0), "Contract deployment failed");
(bool success,) = addr.call(abi.encodeWithSignature("transferOwnership(address)", msg.sender));
require(success, "Ownership transfer failed");
emit ContractDeployed(addr); // Emit the event
return addr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment