NFT 102. BattleCats

閱讀時間約 10 分鐘

1. Create a new file "BattleCats"

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.23;

import"./ERC721.sol";

contract SuperMarioWorld is ERC721 {

string public name;
string public symbol;
uint256 public tokenCount;

constructor(string memory _name, string memory _symbol){
name = _name;
symbol = _symbol;
}

// tokenURI
// mint
// supportsInterface
}

2. Adding TokenURI

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.23;

import"./ERC721.sol";

contract SuperMarioWorld is ERC721 {

string public name;
string public symbol;
uint256 public tokenCount;

mapping(uint256 => string) private _tokenURIs;

constructor(string memory _name, string memory _symbol){
name = _name;
symbol = _symbol;
}

// Returns a URL that points to the metadata
function tokenURI(uint256 tokenId) public view returns (string memory) {
require(_owners[tokenId] != address(0), "TokenId does not exist");
return _tokenURIs[tokenId];
}

// mint
// supportsInterface
}


3. Adding Mint

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.23;

import"./ERC721.sol";

contract SuperMarioWorld is ERC721 {

string public name;
string public symbol;
uint256 public tokenCount;

mapping(uint256 => string) private _tokenURIs;

constructor(string memory _name, string memory _symbol){
name = _name;
symbol = _symbol;
}

// Returns a URL that points to the metadata
function tokenURI(uint256 tokenId) public view returns (string memory) {
require(_owners[tokenId] != address(0), "TokenId does not exist");
return _tokenURIs[tokenId];
}

// Creates a new NFT inside our collection
function mint(string memory _tokenURI) public {


tokenCount += 1; //tokenId
_balances[msg.sender] += 1;
_owners[tokenCount] = msg.sender;
_tokenURIs[tokenCount] = _tokenURI;

emit Transfer(address(0), msg.sender, tokenCount);
}

// supportsInterface
}


4. Updating ERC165 Interface

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.23;

import"./ERC721.sol";

contract SuperMarioWorld is ERC721 {

string public name; // ERC721 Metatdata
string public symbol; // ERC721 Metatdata
uint256 public tokenCount;

mapping(uint256 => string) private _tokenURIs;

constructor(string memory _name, string memory _symbol){
name = _name;
symbol = _symbol;
}

// Returns a URL that points to the metadata
function tokenURI(uint256 tokenId) public view returns (string memory) { // ERC721 Metatdata
require(_owners[tokenId] != address(0), "TokenId does not exist");
return _tokenURIs[tokenId];
}

// Creates a new NFT inside our collection
function mint(string memory _tokenURI) public {


tokenCount += 1; //tokenId
_balances[msg.sender] += 1;
_owners[tokenCount] = msg.sender;
_tokenURIs[tokenCount] = _tokenURI;

emit Transfer(address(0), msg.sender, tokenCount);
}

function supportsInterface(bytes4 interfaceId) public override returns(bool){
return interfaceId == 0x80ac58cd || interfaceId == 0x5b5e139f;
}


5. Creating Metadata

  1. create a new folder "Metatdata" and move the picture "cat bros" and "bean cats" inside the folder.
  2. creat a file "BeanCats.json" and "CatBros.json" in the folder "Metadata"


6. Uploading BattleCats

  1. Pinata
  2. upload the image(metadata), and copy the CIP
  1. paste into the json file, "image":https://ipfs.io/ipfs/Qmeu3GmtGRS5S9WakQrssZytQr5VSuL4G9mxFG46gu5jgB",
  2. upload the file "CatBros.json" to piñata as well

7. Configuring Hardhat

  1. open the file, "hardhat config.js"
  2. create a .env file
  3. terminal run "npm install dotenv"


8. Getting A Private Key and RPC

  1. go to Vanity ETH, scroll down and click "generate"
  2. double click the private key
  3. Polygon RPC: https://rpc-mumbai.maticvigil.com/

9. Updating Deploy Script

  • open the file "deploy.js" in the folder "scripts"

10. Deploy CatBros

真哭哭 卡關>^<



[Reference]

Eattheblocks - NFT 101

Eattheblocks - GitHub

Bean Cat-The Battle Cats by Aauroz on DeviantArt

The Battle Cats Cat Bros cursor – Custom Cursor



尋大神腳印, 亦步亦趨。
留言0
查看全部
發表第一個留言支持創作者!
從 Google News 追蹤更多 vocus 的最新精選內容