1

hello I'm writing a contract and got this error in my function.

function mintCardNFT(uint _cardIndex) external {
  uint256 newItemId = _tokenIds.current();
  _safeMint(msg.sender, newItemId);

nftHolderAttributes[newItemId] = CardAttributes({
  cardIndex: _cardIndex,
  name: defaultCards[_cardIndex].name,
  imageURI: defaultCards[_cardIndex].imageURI,
  alignments: defaultCards[_cardIndex].alignments,
  power: defaultCards[_cardIndex].power,
  maxPower: defaultCards[_cardIndex].maxPower,
  resistance: defaultCards[_cardIndex].resistance,
  income: defaultCards[_cardIndex].income
});

console.log("Minted NFT w/ tokenId %s and cardIndex %s", newItemId, _cardIndex);

nftHolders[msg.sender] = newItemId;

_tokenIds.increment();}

solidity version is 0.8.1 in hardhat.config and ^0.8.1 in contract.

everything looks normal to me. Merci!

plastik
  • 23
  • 1
  • 6

1 Answers1

0

You're trying to invoke a function _safeMint() but this function is not declared.

Most likely you forgot to derive your contract from the OpenZeppelin ERC721.

pragma solidity ^0.8;

// import the OpenZeppelin `ERC721` contract
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

// derive your contract from the imported `ERC721` contract
contract MyCollection is ERC721 {
    // call the parent constructor
    constructor() ERC721("MyCollection", "MyC") {}

    function mintCardNFT() external {
        // now the `_safeMint()` function is available
        _safeMint(msg.sender, 1);
    }
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • actually I import it. but I see right now I did a silly mistake, thanks for your comment. my mistake was not adding is ERC721 when define contract. I guess I should delete this question – plastik Mar 10 '22 at 08:10
  • @MertTopkaya These things happen. :) Do not delete the question, it might help others with the same issue. – Petr Hejda Mar 10 '22 at 08:43