// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.20;
contract Token1{
uint256 public value;
constructor(uint256 _value) {
value = _value;
}
}
contract TokenFactory1 {
event ContractCreated(address indexed newContract);
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly {
result := mload(add(source, 32))
}
}
/// 使用 create2 创建合约
function createContract(string memory ss,uint _x) external{
bytes32 _salt=stringToBytes32(ss);
Token1 _contract = new Token1{salt: _salt}(_x);
emit ContractCreated(address(_contract));
}
///计算被部署合约地址
function getContractAddr(string memory ss, bytes memory bytecode) external view returns(address){
06-10
3654

09-09
2586
