本篇可以认为是 第85篇 笔记-用合约创建合约 的续篇;
介绍在工厂模式下,如何随意创建并管理新合约;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract Car {
address public owner;
string public model;
address public carAddr;
constructor(address _owner, string memory _model) payable {
owner = _owner;
model = _model;
carAddr = address(this);
}
}
contract CarFactory {
Car[] public cars;
function create(address _owner, string memory _model) public {
Car car = new Car(_owner, _model);
cars.push(car);
}
function createAndSendEther(address _owner, string memory _model)
public
payable
{
这篇笔记详细阐述了如何在以太坊区块链中使用工厂模式来灵活地创建和管理智能合约,作为之前关于合约创建话题的延续。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



