0

I am learning solidity and have decided to program my own ERC-20 token. I have inherited the ERC-20 Open Zeppelin standard, but would like to add some functionality that calculates 5% of every transfer, and then burns that amount from the total supply. Here is what I have so far:

enter image description here

  1. I have created two functions: calculateBurnAmount, and burn. These functions calculate 5% of the amount being transferred, and then call the OpenZeppelin burn function while passing it that amount.
  2. In order for the smart contract to "know" to burn tokens on transfer, they have to be called in the transfer function itself, correct? Did I correctly implement this by listing the transfer function and then calling the two burn functions in the logic body?
New contributor
e n is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

In transfer function first calculate amountToBurn then subtract it from amount to get amountToTransfer.

uint256 amountToBurn = calculateBurnAmount(amount);
uint256 amountToTransfer = amount - amountToBurn;
_transfer(_msgSender(), recipient, amountToTransfer);
_burn(_msgSender(), amountToBurn);

remove burn function

2
  • Hello thank you: I made the changes you suggested. DO lines 29 and 30 make sense? Also do I need to edit the transferFrom function to burn from sender and NOT msg.sender?
    – e n
    2 days ago
  • All balance checks are controlled by OpenZeppline ERC20 in _transfer function, and transferFrom also use _transfer function yesterday

Your Answer

e n is a new contributor. Be nice, and check out our Code of Conduct.

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.