ApproveAndCall function for ERC20

Due to one of the known problems of ERC20 EventHandling standard, there is no token receiving processing function in the token contract, smart contract will not be able to record how many, when and from whom tokens were received. This leads to the irretrievable loss of a huge amount of money.

Since it was not possible to send tokens directly to contracts, it was necessary to do it in 2 stages: Approve and TransferFrom. Approve – means to approve a certain number of tokens for withdrawal to a certain wallet. TransferFrom – means to transfer tokens approved for withdrawal.

This leads to the following set of actions:

1) Tokens holder initiates Approve of his tokens to smart contract’s address.

2) Tokens holder initiates a function in the contract, within which TransferFrom is performed to the contract address and the received tokens are successfully processed by the contract.

As you can see, everything is quite complicated and is carried out only in two transactions. The introduction of function ApproveAndCall into tokens ERC20 became a solution to smart contracts operation. The additional function ApproveAndCall allows you to simplify the above procedure and do it by only 1 transaction: initiation of the function ApproveAndCall inside which both Approve tokens and transferFrom will occur.

Example of ApproveAndCall implementing in code:

… As you can see, the contract must have the receiveApproval function for sending tokens to a smart contract. The transaction is made in one stage: initiation of the ApproveAndCall function in the token contract with the smart contract’s address where the funds are sent (spender), the number of tokens sent (amount) and additional data, if required (extraData).

If you have any questions or are interested in the development/audit of smart contracts, please contact us and we will answer all your questions.

Sincerely, Grox Solutions.

Articles. Public audits

TronGuru AUDIT

Audit of the TronGuru Smart-Contract

Read more


Audit of the Trony Smart-Contract

Read more


Security audit of the TRONies smart-contract

Read more


Security audit of the TronEx3 smart-contract

Read more

TronMatrix AUDIT

Security audit of the TronMatrix smart-contract

Read more


Security audit of the TRONPROM smart-contract

Read more


Security audit of the TRX-IN-BANK smart-contract

Read more

TRONex Audit

Security audit of the TRONex smart-contract

Read more


Token is a certain unit of value in the blockchain...

Read more

ICO (CrowdSale)

ICO – Initial Coin Offering or initial coin placement, by...

Read more

ERC20 standard issues

Despite the widespread use, the standard of token ERC20 has...

Read more

ApproveAndCall function for ERC20

Due to one of the known problems of ERC20 EventHandling...

Read more

Example of Smart Contract operation

Since the idea of Smart Contracts was mostly spread in...

Read more

Application of Smart Contracts

Smart contract technologies are still new and it is possible...

Read more

Audit of «Neuromachine Eternal»

Public Audit of NRM Smart Contract

Read more
Load more
To close