基于 ERC721 标准
uint256 MAX_SUPPLY
uint256 PRICE
uint256 MAX_PER_MINT
string baseTokenURI
constructor(string _name, string _symbol) public
error Unauthorized()
error NotEnoughNFTs()
error NotEnoughEtherPurchaseNFTs()
error CannotMintSpecifiedNumber()
error CannotZeroBalance()
function _baseURI() internal view virtual returns (string)
Base URI for computing {tokenURI}. If set, the resulting URI for each
token will be the concatenation of the baseURI
and the tokenId
. Empty
by default, can be overridden in child contracts.
function setBaseURI(string _baseTokenURI) public
function tokenURI(uint256 tokenId) public view returns (string)
See {IERC721Metadata-tokenURI}.
function mint(uint256 _count) public payable returns (uint256)
铸造NFT
Name | Type | Description |
---|---|---|
_count | uint256 | 铸造数量 |
function reserveNFTs(uint256 _count) public
预留NFT
Name | Type | Description |
---|---|---|
_count | uint256 | 保留NFT数量 |
function getTokensOfOwner(address _owner) external view returns (uint256[])
获取一个特定账户所拥有的所有代币
Name | Type | Description |
---|---|---|
_owner | address | 拥有者 |
function withdraw() external
提取合约余额
公共合约,提供植物基础功能
event PlantWatered(uint256 plantId, uint8 waterAmount)
event LightProvided(uint256 plantId, uint8 lightDuration)
event PlantGrown(uint256 plantId, enum PlantBase.PlantStage newStage)
event PlantHarvested(uint256 plantId, address reciver)
event PlantTransferred(uint256 plantId, address form, address to)
enum PlantSpecies {
Tree,
Flower,
Shrub
}
struct PlantMetadata {
string plantName;
enum PlantBase.PlantSpecies plantSpecies;
}
struct Plant {
uint8 waterLevel;
uint8 lightLevel;
bool isAlive;
enum PlantBase.PlantStage currentStage;
struct PlantBase.PlantMetadata metadata;
}
enum PlantStage {
Seed,
Sprout,
Mature,
Flower,
Harvest
}
mapping(uint256 => struct PlantBase.Plant) plantMap
mapping(address => uint256[]) userPlantIds
function createPlant(string plantName, enum PlantBase.PlantSpecies plantSpecies) external returns (uint256)
创建植物并返回植物ID
Name | Type | Description |
---|---|---|
plantName | string | 植物名称 |
plantSpecies | enum PlantBase.PlantSpecies | 植物品种 |
function getUserPlantIds() external view returns (uint256[])
获取用户地址拥有的植物ID数组
function getPlantIds() external view returns (uint256[])
获取植物ID集合
function getPlantStatus(uint256 plantId) public view returns (string, enum PlantBase.PlantSpecies, uint8, uint8, bool, enum PlantBase.PlantStage, uint256)
获取植物状态信息
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
function waterPlant(uint256 plantId, uint8 waterAmount) public
给植物浇水
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
waterAmount | uint8 | 水量 |
function provideLight(uint256 plantId, uint8 lightDuration) public
提供光照
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
lightDuration | uint8 | 光照时长 |
function _updatePlantStatus(uint256 plantId, uint8 waterAmount, uint8 lightDuration) internal
合并状态更新操作,减少 gas 消耗
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
waterAmount | uint8 | 水量 |
lightDuration | uint8 | 光照时长 |
function _growPlant(uint256 plantId) internal
促使植物生长
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
function _checkPlantHealth(uint256 plantId) internal
检查植物是否健康,如果水分或光照不足,植物将死亡
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
function _isPlantOwner(address userAddress, uint256 plantId) internal view returns (bool)
检查用户是否拥有指定植物
Name | Type | Description |
---|---|---|
userAddress | address | 用户地址 |
plantId | uint256 | 植物ID |
function harvestPlant(uint256 plantId) public
收获植物
Name | Type | Description |
---|---|---|
plantId | uint256 | plant id |
function transferPlant(address to, uint256 plantId) public
以下为交易植物功能
Name | Type | Description |
---|---|---|
to | address | to |
plantId | uint256 | plantId |
function _removePlantOwnership(address from, uint256 plantId) internal
function _addPlantOwnership(address to, uint256 plantId) internal
摇钱树植物的实现
结构体,用于组织创建植物时的参数
struct PlantCreationParams {
uint256 customAttribute;
string color;
string shape;
uint8 growthSpeed;
string name;
}
struct MoneyTree.PlantCreationParams plantAttributes
constructor(struct MoneyTree.PlantCreationParams params) public
构造函数,初始化摇钱树
Name | Type | Description |
---|---|---|
params | struct MoneyTree.PlantCreationParams | 创建植物的参数 |
乒乓菊植物的实现
struct PlantCreationParams {
uint256 customAttribute;
string color;
string shape;
uint8 growthSpeed;
string name;
}
struct PingPongChrysanthemum.PlantCreationParams plantAttributes
constructor(struct PingPongChrysanthemum.PlantCreationParams params) public
构造函数,初始化乒乓菊
Name | Type | Description |
---|---|---|
params | struct PingPongChrysanthemum.PlantCreationParams | 创建植物的参数 |
七日花植物的实现
struct PlantAttributes {
uint256 customAttribute;
string color;
string shape;
uint8 growthSpeed;
string name;
}
struct SevenDayFlower.PlantAttributes plantAttributes
constructor(struct SevenDayFlower.PlantAttributes params) public
构造函数,初始化
Name | Type | Description |
---|---|---|
params | struct SevenDayFlower.PlantAttributes | 创建植物的参数 |
统一处理
struct Result {
uint256 value;
string message;
}
function createResult(uint256 _value, string _message) internal pure returns (struct ResultLibrary.Result)
公共合约,提供植物基础功能
struct PlantMetadata {
string plantName;
string plantSpecies;
uint256 creationTime;
}
struct Plant {
uint8 waterLevel;
uint8 lightLevel;
bool isAlive;
enum ElectronicPlantBase.PlantStage currentStage;
struct ElectronicPlantBase.PlantMetadata metadata;
}
enum PlantStage {
Seed,
Sprout,
Mature,
Flower
}
mapping(uint256 => struct ElectronicPlantBase.Plant) plantMap
event PlantWatered(uint256 plantId, uint8 waterAmount)
事件,记录植物被浇水情况
Name | Type | Description |
---|---|---|
plantId | uint256 | plantId |
waterAmount | uint8 | 水量 |
event LightProvided(uint256 plantId, uint8 lightDuration)
事件,记录植物被提供光照情况
Name | Type | Description |
---|---|---|
plantId | uint256 | plantId |
lightDuration | uint8 | 光照时长 |
event PlantGrown(uint256 plantId, enum ElectronicPlantBase.PlantStage newStage)
事件,记录植物生长阶段变化
Name | Type | Description |
---|---|---|
plantId | uint256 | plantId |
newStage | enum ElectronicPlantBase.PlantStage | newStage |
modifier plantExists(uint256 plantId)
修饰器,确保植物存在
Name | Type | Description |
---|---|---|
plantId | uint256 | plantId |
function _checkPlantHealth(uint256 plantId) internal
内部方法,检查植物健康状况
Name | Type | Description |
---|---|---|
plantId | uint256 | plantId |
function getPlantStatus(uint256 plantId) public view returns (string, string, uint8, uint8, bool, enum ElectronicPlantBase.PlantStage, uint256)
获取植物状态信息
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
Name | Type | Description |
---|---|---|
[0] | string | plantName 植物名称 |
[1] | string | plantSpecies 植物品种 |
[2] | uint8 | waterLevel 水分级别 |
[3] | uint8 | lightLevel 光照级别 |
[4] | bool | isAlive 植物是否存活 |
[5] | enum ElectronicPlantBase.PlantStage | currentStage 当前生长阶段 |
[6] | uint256 | creationTime 植物创建时间 |
function waterPlant(uint256 plantId, uint8 waterAmount) public
给植物浇水
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
waterAmount | uint8 | 水量 |
function provideLight(uint256 plantId, uint8 lightDuration) public
提供光照
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
lightDuration | uint8 | 光照时长 |
function growPlant(uint256 plantId) public
促使植物生长
Name | Type | Description |
---|---|---|
plantId | uint256 | 植物ID |
function createPlant(string plantName, string plantSpecies, uint256 creationTime) external returns (uint256)
创建植物并返回植物ID
Name | Type | Description |
---|---|---|
plantName | string | 植物名称 |
plantSpecies | string | 植物品种 |
creationTime | uint256 | 植物的创建时间 记录植物合约创建的时间戳 |
function getPlantIds() external view returns (uint256[])
获取植物ID集合