OpenZeppelin / OpenZeppelin/openzeppelin-contracts
Function beforeTokenTransfer
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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