Solidity
用合約創建合約
我想創建一個可以自己創建契約的契約
我發現這樣的東西
pragma solidity ^0.5.0; contract DaughterContract { string public name; uint public age; constructor( string memory _daughtersName, uint _daughtersAge ) public { name = _daughtersName; age = _daughtersAge; } } contract MomContract { string public name; uint public age; DaughterContract public daughter; constructor( string memory _momsName, uint _momsAge, string memory _daughtersName, uint _daughtersAge ) public { daughter = new DaughterContract(_daughtersName, _daughtersAge); name = _momsName; age = _momsAge; } }
但它只在我硬編碼女兒契約時才有效而且它只有效一次
我想創建一個能夠通過呼叫函式創建多個女兒的母契約
像這樣的東西
應該改變什麼
MomContract
僅在其建構子上部署daughter
合約,該建構子僅執行一次,您應該有一個可以多次呼叫的函式,以便您隨意部署daughter
。