Hi @cjd9s,
Welcome to the community
Hooks allow you lots of flexibility in modifying the behaviour of a token by allowing you to execute functionality, in the case of the _beforeTokenTransfer
hook, you can execute functionality before the token is transferred.
You could restrict transfer (other than minting) to only registered candidates, you could mint another token to signify that the original holder has voted, you could prevent transfer outside of specific voting times, you could emit a vote event.
If you don’t need to use hooks, then you don’t need to include the function in your child contract.
An example is shown below (though I have only left comments rather than actually do anything in the hook):
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
import "@openzeppelin/contracts/presets/ERC721PresetMinterPauserAutoId.sol";
contract MyToken is ERC721PresetMinterPauserAutoId {
constructor()
public
ERC721PresetMinterPauserAutoId(
"My Token",
"TKN",
"https://example.com/api/token/"
)
{}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override(ERC721, ERC721Pausable) {
super._beforeTokenTransfer(from, to, tokenId);
// do stuff before every transfer
// e.g. check that vote (other than when minted)
// being transferred to registered candidate
}
}