Hi this is my code :
in final code , i will use oracol’s random number for set Stats.
// SPDX-License-Identifier: Leluk911
pragma solidity 0.8.7;
import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";
contract MyNft is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("NftCat", "NFC") {}
struct Cat {
uint256 Id;
uint8 color1;
uint8 color2;
uint8 color3;
uint8 power;
uint8 lifepoint;
uint8 stamina;
uint8 speed;
}
Cat[] public Cats;
function mint(
address to,
uint8 _color1,
uint8 _color2,
uint8 _color3,
uint8 _power,
uint8 _lifepoint,
uint8 _stamina,
uint8 _speed
) external virtual {
uint256 newItemId = _tokenIds.current();
Cat memory NewCat = Cat(
newItemId,
_color1,
_color2,
_color3,
_power,
_lifepoint,
_stamina,
_speed
);
Cats.push(NewCat);
_mint(to, newItemId);
}
function wiewStat(uint256 _tokenId)
public
view
virtual
returns (Cat memory)
{
return Cats[_tokenId];
}
// this transaction must approve
function transferNft(address _to, uint256 _tokenId) external virtual {
_transfer(msg.sender, _to, _tokenId);
}
}