OpenZeppelin / OpenZeppelin/openzeppelin-contracts

Function beforeTokenTransfer

Open
#5,146 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Solidity
Stars
27.2k
Forks
12.4k
Avg merge
2d 19h
Merged PRs (30d)
33

Description

Hello everybody,

I m new here and in Solidity and I try to learn. I have an issue with this function (_beforeTokenTransfer), here is the code :


pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract SoulboundToken is ERC721 {
uint256 public nextTokenId;

mapping(uint256 => bool) public soulbound;

constructor() ERC721("SoulboundToken", "MTK") {}

function mint(address to) public {
    _mint(to, nextTokenId);
    soulbound[nextTokenId] = true;
    nextTokenId++;
}

// Override the transfer functions to prevent transferring of SBTs
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override {
    require(from == address(0), "SBTs are non-transferable");
    super._beforeTokenTransfer(from, to, tokenId);
}

}


Remix or VScode send me an error : "Function has override specified but does not override anything"

I don't understand why and how can I fix it

Could you please help me e-and explain me what to do and what is the matter ?

Thank you very much

William

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by checking the OpenZeppelin Contracts version used by the import, then compare its ERC721 transfer-hook signature with the _beforeTokenTransfer override shown in the issue. Confirm the version-compatible extension point and verify that the SoulboundToken example compiles in Remix or VSCode without the override error.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.