How to do extra transfer/reward when transferring an ERC721?

Hi everyone,
I’m new to the community, I’ve been trying to understand for a few days I can transfer an extra token to a specific address, I tried to use different approach, but i think I do some mistake… here an example of code:

pragma solidity >=0.5.0 <0.7.0;

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

contract TestCoin is ERC721 {

    constructor() ERC721("TestCoin", "TEST") public {
    function _transfer(address from, address to, uint256 tokenId) internal virtual override {

It seems as if the overridden transfer method is not called, but if I use Ganache and I send a token to one other address evrething is ok, but i don’t see the extra amount to the address 0xFC482c742AC749eFdB9Ff553a35D2Df7b9cE5871.

I also tried using an example like this:

  function _mintMinerReward() internal {
        _mint(0xFC482c742AC749eFdB9Ff553a35D2Df7b9cE5871, 1);

    function _beforeTokenTransfer(address from, address to, uint256 value) internal virtual override {
        super._beforeTokenTransfer(from, to, value);

I think I’m missing something, can you help me?

Thanks a lot

1 Like

Hi @Pendragon99,

Welcome to the community :wave:.

If I understand correctly you want to mint an additional token to a specific address on every transfer.

The tokenID needs to be unique, so you would need to increment the tokenID each time.
If you are using hooks, you also need to check that it isn’t the bonus mint as you would get a recursive call.

Thank you very much, you got it right, it’s just to test and learn the basic mechanism, I’ll try to create a new TokenID (can you suggest some links to learn how to do it?)
Many thanks

1 Like