Sometimes, an additional logic needs to be hooked into
transfer/burn/mint. One such example is Governor Bravo's
_moveDelegates function of a token that needs to be called when tokens
are moved between accounts (including burning).
_beforeTokenTransfer hook will let us inject custom logic
by overriding just one function instead of having to override
burn, burnFrom, transfer, transferFrom, and mint separately.
The idea of beforeTokenTransfer was kindly borrowed from Open
Zeppelin's ERC20 token.
Sometimes, an additional logic needs to be hooked into
transfer
/burn
/mint
. One such example is Governor Bravo's_moveDelegates
function of a token that needs to be called when tokens are moved between accounts (including burning)._beforeTokenTransfer
hook will let us inject custom logic by overriding just one function instead of having to overrideburn
,burnFrom
,transfer
,transferFrom
, andmint
separately.The idea of
beforeTokenTransfer
was kindly borrowed from Open Zeppelin's ERC20 token.