Contract Source Code:
File 1 of 1 : FabricContract.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; interface IChildContract { function mint(address to) external; function withdraw() external; function transferOwnership(address newOwner) external; } contract FabricContract { address[] public childContracts; address public owner; modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; } event ChildContractDeployed(address indexed childAddress); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor() { owner = msg.sender; } function createChildContracts(uint256 count) external onlyOwner { for (uint256 i = 0; i < count; i++) { ChildContract child = new ChildContract(owner); childContracts.push(address(child)); emit ChildContractDeployed(address(child)); } } function mintThroughChildren(address to) external onlyOwner { for (uint256 i = 0; i < childContracts.length; i++) { IChildContract(childContracts[i]).mint(to); } } function getChildContracts() external view returns (address[] memory) { return childContracts; } function withdrawFromChildren() external onlyOwner { for (uint256 i = 0; i < childContracts.length; i++) { IChildContract(childContracts[i]).withdraw(); } } function transferOwnership(address newOwner) external onlyOwner { require(newOwner != address(0), "New owner is the zero address"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract ChildContract is IChildContract { address public owner; uint256 public tokenId; mapping(uint256 => address) private tokenOwners; event Mint(address indexed to, uint256 tokenId); event Transfer(address indexed from, address indexed to, uint256 tokenId); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; } constructor(address _owner) { owner = _owner; tokenId = 0; } function mint(address to) external onlyOwner override { tokenId++; tokenOwners[tokenId] = to; emit Mint(to, tokenId); } function transfer(address to, uint256 _tokenId) external { require(tokenOwners[_tokenId] == msg.sender, "Not the token owner"); require(to != address(0), "Invalid recipient"); tokenOwners[_tokenId] = to; emit Transfer(msg.sender, to, _tokenId); } function ownerOf(uint256 _tokenId) external view returns (address) { return tokenOwners[_tokenId]; } function withdraw() external onlyOwner override { uint256 balance = address(this).balance; require(balance > 0, "No funds to withdraw"); // Используем `call` вместо `transfer` (bool success, ) = payable(owner).call{value: balance}(""); require(success, "Transfer failed"); } function transferOwnership(address newOwner) external onlyOwner override { require(newOwner != address(0), "New owner is the zero address"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } // Функция для получения эфира на контракт receive() external payable {} }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.