Browse Source

添加NFT图片

master
yyy 6 months ago
parent
commit
c605a46d3a
  1. 10
      .openzeppelin/bsc-testnet.json
  2. 12
      contracts/NFT.sol
  3. 27
      scripts/deployProxy.ts

10
.openzeppelin/bsc-testnet.json

@ -115,6 +115,16 @@
"address": "0xf13Bdb02610672144381Fc6A3A438B62CB579934", "address": "0xf13Bdb02610672144381Fc6A3A438B62CB579934",
"txHash": "0x33a174a7a830468f0b6eeb9435340801a42685b13aa42b41b43ba056cbdd7b7a", "txHash": "0x33a174a7a830468f0b6eeb9435340801a42685b13aa42b41b43ba056cbdd7b7a",
"kind": "transparent" "kind": "transparent"
},
{
"address": "0x1D321a4FE34310f49F72cf73A0d573Eb3B7CdB03",
"txHash": "0xa4e740f0cc6247881a186717373a5e84f0a2b4c5c66e01b1d2c075c19a1b35e9",
"kind": "transparent"
},
{
"address": "0x9a1baA5b0282dc948Af3011e730da7236060f806",
"txHash": "0x953e6746fa3c3d5efa634a16f7c07cf7d72e32b8b25e12615c645d01f387048e",
"kind": "transparent"
} }
], ],
"impls": { "impls": {

12
contracts/NFT.sol

@ -11,12 +11,14 @@ contract NFT is ERC721Enumerable {
bool first; bool first;
address public pledgeAddress; address public pledgeAddress;
uint256[] public blacks; 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."); require(first == false,"You can only use it once.");
admins.push(msg.sender); admins.push(msg.sender);
deployAddress = msg.sender; deployAddress = msg.sender;
first = true; first = true;
baseURI = uri;
} }
modifier onlyAdmin(){ modifier onlyAdmin(){
@ -62,6 +64,10 @@ contract NFT is ERC721Enumerable {
admins = _admins; admins = _admins;
} }
function setBaseURI(string memory _uri) external onlyAdmin {
baseURI = _uri;
}
function getAdmin() public view returns(address[] memory){ function getAdmin() public view returns(address[] memory){
return admins; return admins;
} }
@ -88,4 +94,8 @@ contract NFT is ERC721Enumerable {
return super._update(to,tokenId,auth); return super._update(to,tokenId,auth);
} }
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return baseURI;
}
} }

27
scripts/deployProxy.ts

@ -9,39 +9,40 @@ async function main() {
const FIL_ADDRESS = process.env.FIL_ADDRESS const FIL_ADDRESS = process.env.FIL_ADDRESS
// const FIL_ADDRESS = fil.target // const FIL_ADDRESS = fil.target
console.log('fil地址:',FIL_ADDRESS); console.log('fil地址:',FIL_ADDRESS);
console.log("開始部署NFT合約"); console.log("開始部署NFT合約");
const NFT = await ethers.getContractFactory("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("NFT合約", nft.target);
console.log("開始部署Pool合約"); console.log("開始部署Pool合約");
const Pool = await ethers.getContractFactory("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("Pool合約", pool.target);
console.log("開始部署Pledge合約"); console.log("開始部署Pledge合約");
const Pledge = await ethers.getContractFactory("Pledge"); const Pledge = await ethers.getContractFactory("Pledge");
const pledge = await upgrades.deployProxy( const pledge = await upgrades.deployProxy(
Pledge, Pledge,
[nft.target,pool.target],
[nft.target, pool.target],
{ initializer: "initialize" } { initializer: "initialize" }
); );
console.log("Pledge合約", pledge.target); console.log("Pledge合約", pledge.target);
console.log('執行初始化設置合約地址'); console.log('執行初始化設置合約地址');
const tx = await nft.setPledgeAddress(pledge.target);
const tx = await nft.setPledgeAddress(pledge.target);
await tx.wait() await tx.wait()
const tx1 = await pool.setPledgeContractAddress(pledge.target); const tx1 = await pool.setPledgeContractAddress(pledge.target);
await tx1.wait() await tx1.wait()
// 測試使用 // 測試使用
console.log('設置成功'); 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() { async function mainUpgradeProxy() {
// 3.1173 // 3.1173
@ -50,7 +51,7 @@ async function mainUpgradeProxy() {
// const Pool = await ethers.getContractFactory("Pool"); // const Pool = await ethers.getContractFactory("Pool");
// const pool = await upgrades.upgradeProxy(poolAddress, Pool); // const pool = await upgrades.upgradeProxy(poolAddress, Pool);
console.log('開始升級'); console.log('開始升級');
const Pledge = await ethers.getContractFactory("Pledge"); const Pledge = await ethers.getContractFactory("Pledge");
const pledge = await upgrades.upgradeProxy(pledgeAddress, Pledge); const pledge = await upgrades.upgradeProxy(pledgeAddress, Pledge);
console.log('升級成功'); console.log('升級成功');

Loading…
Cancel
Save