From c605a46d3ae93b0d1d0665e7348ada7da5e89490 Mon Sep 17 00:00:00 2001 From: yyy <1174643184@qq.com> Date: Sat, 18 May 2024 21:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0NFT=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .openzeppelin/bsc-testnet.json | 10 ++++++++++ contracts/NFT.sol | 12 +++++++++++- scripts/deployProxy.ts | 27 ++++++++++++++------------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.openzeppelin/bsc-testnet.json b/.openzeppelin/bsc-testnet.json index 21b855f..3a1eb12 100644 --- a/.openzeppelin/bsc-testnet.json +++ b/.openzeppelin/bsc-testnet.json @@ -115,6 +115,16 @@ "address": "0xf13Bdb02610672144381Fc6A3A438B62CB579934", "txHash": "0x33a174a7a830468f0b6eeb9435340801a42685b13aa42b41b43ba056cbdd7b7a", "kind": "transparent" + }, + { + "address": "0x1D321a4FE34310f49F72cf73A0d573Eb3B7CdB03", + "txHash": "0xa4e740f0cc6247881a186717373a5e84f0a2b4c5c66e01b1d2c075c19a1b35e9", + "kind": "transparent" + }, + { + "address": "0x9a1baA5b0282dc948Af3011e730da7236060f806", + "txHash": "0x953e6746fa3c3d5efa634a16f7c07cf7d72e32b8b25e12615c645d01f387048e", + "kind": "transparent" } ], "impls": { diff --git a/contracts/NFT.sol b/contracts/NFT.sol index 597e6f1..0325212 100644 --- a/contracts/NFT.sol +++ b/contracts/NFT.sol @@ -11,12 +11,14 @@ contract NFT is ERC721Enumerable { bool first; address public pledgeAddress; uint256[] public blacks; + string public baseURI; - constructor(string memory name,string memory symbol) ERC721(name,symbol) { + constructor(string memory name,string memory symbol,string memory uri) ERC721(name,symbol) { require(first == false,"You can only use it once."); admins.push(msg.sender); deployAddress = msg.sender; first = true; + baseURI = uri; } modifier onlyAdmin(){ @@ -62,6 +64,10 @@ contract NFT is ERC721Enumerable { admins = _admins; } + function setBaseURI(string memory _uri) external onlyAdmin { + baseURI = _uri; + } + function getAdmin() public view returns(address[] memory){ return admins; } @@ -88,4 +94,8 @@ contract NFT is ERC721Enumerable { return super._update(to,tokenId,auth); } + function tokenURI(uint256 tokenId) public view override returns (string memory) { + return baseURI; + } + } diff --git a/scripts/deployProxy.ts b/scripts/deployProxy.ts index 88f1710..1339e98 100644 --- a/scripts/deployProxy.ts +++ b/scripts/deployProxy.ts @@ -9,39 +9,40 @@ async function main() { const FIL_ADDRESS = process.env.FIL_ADDRESS // const FIL_ADDRESS = fil.target console.log('fil地址:',FIL_ADDRESS); - + console.log("開始部署NFT合約"); const NFT = await ethers.getContractFactory("NFT"); - const nft = await NFT.deploy("MyNFT", "MNFT"); + const baseURI = "ipfs://QmQpgq4FvXNHZfoytpiwk617Nozmeu7iMiyiSzthVg1ZV7/metadata.json" + const nft = await NFT.deploy("SOFIL NFT", "SFSC", baseURI); console.log("NFT合約", nft.target); console.log("開始部署Pool合約"); const Pool = await ethers.getContractFactory("Pool"); - const pool = await upgrades.deployProxy(Pool,[FIL_ADDRESS,nft.target],{ initializer: "initialize" }); + const pool = await upgrades.deployProxy(Pool, [FIL_ADDRESS, nft.target], { initializer: "initialize" }); console.log("Pool合約", pool.target); - + console.log("開始部署Pledge合約"); const Pledge = await ethers.getContractFactory("Pledge"); const pledge = await upgrades.deployProxy( Pledge, - [nft.target,pool.target], + [nft.target, pool.target], { initializer: "initialize" } ); console.log("Pledge合約", pledge.target); - + console.log('執行初始化設置合約地址'); - const tx = await nft.setPledgeAddress(pledge.target); + const tx = await nft.setPledgeAddress(pledge.target); await tx.wait() const tx1 = await pool.setPledgeContractAddress(pledge.target); await tx1.wait() // 測試使用 console.log('設置成功'); - console.log('NFT的質押合約地址',await nft.pledgeAddress()); - console.log('Pool的質押合約地址',await pool._pledgeContractAddress()); - console.log('质押时间',await pledge.dayTime()); - -} + console.log('NFT的質押合約地址', await nft.pledgeAddress()); + console.log('Pool的質押合約地址', await pool._pledgeContractAddress()); + console.log('质押时间', await pledge.dayTime()); + +} async function mainUpgradeProxy() { // 3.1173 @@ -50,7 +51,7 @@ async function mainUpgradeProxy() { // const Pool = await ethers.getContractFactory("Pool"); // const pool = await upgrades.upgradeProxy(poolAddress, Pool); console.log('開始升級'); - + const Pledge = await ethers.getContractFactory("Pledge"); const pledge = await upgrades.upgradeProxy(pledgeAddress, Pledge); console.log('升級成功');