0

Notice from: https://ethereum.org/token

The mintToken Function:

function mintToken(address target, uint256 mintedAmount) onlyOwner {
    balanceOf[target] += mintedAmount;
    totalSupply += mintedAmount;
    Transfer(0, owner, mintedAmount);
    Transfer(owner, target, mintedAmount);
}

My question is... I'm doing:

Transfer(this, target, mintedAmount);

Instead of:

Transfer(0, owner, mintedAmount);
Transfer(owner, target, mintedAmount);

And its working... is what I'm doing bad practice?

1

The Transfer is just an event that you are triggering. The actual minting is done before that in the lines:

balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;

So, yes, it would work even without calling the event. The point of the event is to allow listening clients (if such exist) to trigger something when a certain event happens within your contract. The example code triggers the event twice - first for creating a token from thin air (address 0) and once for transferring that token to the target.

So, yes, what you're doing is bad practise because anyone listening for events has no idea that you minted tokens, they just notice that you transferred tokens (even if you are using the contract as the origin).

In my opinion the following line might be enough, but there's probably a reason why they chose to recommend two events, so don't trust my judgement too much.

Transfer(0, target, mintedAmount);
0

The Transfer call is just an event trigger to notify anyone listening to your contract. The problem with calling it only one time is that the listener can't tell the difference between minted tokens and simply transferred tokens (a buy function call, for example). That's probably the reason why they call Transfer twice; one from 0 to the owner, and another from the owner to the target.

My suggestion would be to create a specific event for minting, like:

event Mint(address target, uint256 mintedAmount);

and calling it instead of Transfer in the end of your mintToken function:

Mint(target, mintedAmount);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.