区块链应用--Web3 NFT铸造主页--以太坊--Polygon
01/27
本文最后更新于
2023年01月27日,已超过
797天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
链接请点击上面的标题
今天的这个Web3项目是一个部署在Polygon主网络上的项目,这是一个可以在自己主页铸造生成NFT的项目,可以在Opensea中查看到已经铸造的项目,并且可以在Opensea上出售。
视频(Youtube,Bilibili)
实现功能
- 通过自己的网页铸造并且生成NFT
- 链接小狐狸钱包
- 生成的NFT在Opensea上看到
- 手机观看优化模式
- 手机和PC端均可流畅完成项目
- 前端云部署
- 部署在Polygon主网络上
- 通过程序批量合成NFT所需要的图片
智能合约代码
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
contract CrowdFunding {
struct Campaign {
address owner;
string title;
string description;
uint256 target;
uint256 deadline;
uint256 amountCollected;
string image;
address[] donators;
uint256[] donations;
}
mapping(uint256 => Campaign) public campaigns;
uint256 public numberOfCampaigns = 0;
function createCampaign(address _owner, string memory _title, string memory _description, uint256 _target, uint256 _deadline, string memory _image) public returns (uint256) {
Campaign storage campaign = campaigns[numberOfCampaigns];
require(campaign.deadline < block.timestamp, "The deadline should be a date in the future.");
campaign.owner = _owner;
campaign.title = _title;
campaign.description = _description;
campaign.target = _target;
campaign.deadline = _deadline;
campaign.amountCollected = 0;
campaign.image = _image;
numberOfCampaigns++;
return numberOfCampaigns - 1;
}
function donateToCampaign(uint256 _id) public payable {
uint256 amount = msg.value;
Campaign storage campaign = campaigns[_id];
campaign.donators.push(msg.sender);
campaign.donations.push(amount);
(bool sent,) = payable(campaign.owner).call{value: amount}("");
if(sent) {
campaign.amountCollected = campaign.amountCollected + amount;
}
}
function getDonators(uint256 _id) view public returns (address[] memory, uint256[] memory) {
return (campaigns[_id].donators, campaigns[_id].donations);
}
function getCampaigns() public view returns (Campaign[] memory) {
Campaign[] memory allCampaigns = new Campaign[](numberOfCampaigns);
for(uint i = 0; i < numberOfCampaigns; i++) {
Campaign storage item = campaigns[i];
allCampaigns[i] = item;
}
return allCampaigns;
}
}
感谢Edorh的分享,开源万岁,希望大家能帮助到大家
mint-nft.PNG