Adding Transfer Notifications

Mar 12, 2024 11:28:29 PM

What are Transfer Notifications?

We need to use events to notify the network and other applications about the state changes. One important event is the 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.

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.

The transfer event uses the following parameters:

  • from_address: The of the . 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.

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.