Adding Transfer Notifications

Apr 29, 2024 11:46:57 PM

What are Transfer Notifications?

Blockchain events notify the network and other applications about state changes. One important event is the NEP-17 Transfer event. This event is used to notify the network when tokens are transferred.

NEP-17 Transfer Event

The NEP-17 standard defines the Transfer event must be fired when tokens are transferred, including when new tokens are created or destroyed.

  • The Transfer event must be used even if the amount is zero.
  • The event must be triggered before calling payment callbacks.

The transfer event uses the following parameters:

  • from_address: The address of the sender. In this case, it’s null because the tokens are being minted.
  • to_address: The address of the receiver. In this case, it’s the contract owner.
  • amount: The amount of tokens being transferred. In this case, it’s the total supply.

Adding the Transfer Event

Since we are minting all the tokens during deployment, we need to fire the Transfer event to notify the network that the tokens have been created and assigned to the contract owner.

Let’s add the Transfer event to our smart contract. Update your code to import and fire the Transfer event after the tokens are minted to the contract owner.

Coin.py

Testing the Transfer Event

Reset the blockchain and click on Deploy Local above your deploy method. You should see the Transfer event in the output.

This event will also be used later when we implement the transfer method.