0

I wonder what is the purpose of these functions? could you please provide me with some examples.

function burn(uint256 _value) returns (bool success) {
        if (balanceOf[msg.sender] < _value) throw;            // Check if the sender has enough
        if (_value <= 0) throw; 
        balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value);                      // Subtract from the sender
        totalSupply = SafeMath.safeSub(totalSupply,_value);                                // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }

function freeze(uint256 _value) returns (bool success) {
    if (balanceOf[msg.sender] < _value) throw;            // Check if the sender has enough
    if (_value <= 0) throw; 
    balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value);                      // Subtract from the sender
    freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value);                                // Updates totalSupply
    Freeze(msg.sender, _value);
    return true;
}

function unfreeze(uint256 _value) returns (bool success) {
    if (freezeOf[msg.sender] < _value) throw;            // Check if the sender has enough
    if (_value <= 0) throw; 
    freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value);                      // Subtract from the sender
    balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
    Unfreeze(msg.sender, _value);
    return true;
}
2

Burn:

up to the developer define the functionality

Can transfer to address(0) or deduct the number of tokens from the balance

Thanks, Richard!

Freeze: lock up funds so they can't be used

Unfreeze: unlocked previously locked up funds so they can be used again

| improve this answer | |
  • 1
    The burn() for an ERC-20 token just deducts the amount to burn from the user's balance (and total supply) - it doesn't send them anywhere :-) – Richard Horrocks Feb 14 '18 at 19:03
  • @Richard Horrocks so it used to deduct an amount of tokens from a user, I undestand that the purpose will be to deduct any remaining amount of the already created tokens? – kos_tsak Feb 14 '18 at 19:10
  • Yep, that's correct. (Like "burning money".) – Richard Horrocks Feb 14 '18 at 19:11
  • 1
    ERC-20 wallets don't hold tokens :-) The "tokens" are just a number inside the ERC-20 contract. The wallet works by checking the smart contract for the value associated with your address, and reporting it back to you. So it looks like your tokens are in your wallet, but they aren't. – Richard Horrocks Feb 14 '18 at 19:20
  • 1
    If you're the owner of the contract, and the modifiers are set up in such a way, then you can burn as many tokens as you like. But it'll depend on how you've coded your contract. – Richard Horrocks Feb 14 '18 at 19:21
0
function burn(uint256 _value) returns (bool success) {
        if (balanceOf[msg.sender] < _value) throw;            // Check if the sender has enough
        if (_value <= 0) throw; 
        balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value);                      // Subtract from the sender
        totalSupply = SafeMath.safeSub(totalSupply,_value);                                // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }

The function burns YOUR token. It's not true what @Richard Horrocks wrote. You can only burn your own tokens and not from others. For example if you are making an ICO and own all token, you pay out the token that are sold. Some would keep the remaining, not sold, token and that would give you some power you maybe do not deserve. With this burn function you would simply remove the _value (that you enter before) from your balance without it getting transferred to someone else. It's like calculating 10-5. It's 5 but the other 5 is simply gone. With this function you can't burn from others than your token balance.

In my opinion both freeze and unfreeze make no sense. There is no limit at all for example about how long you want to freeze them. Those functions seem useless for me.

| improve this answer | |
  • So the function the way it is, removes any remaining tokens that are on the owner's balance, instead of freeze unfreeze functions, maybe should be better to use a function to lock the tokens? – kos_tsak Feb 17 '18 at 11:48
  • Yes, the function just removes the balance and the user can get it back with unfreeze. But there is no sense as it would be just wasting of gas. It would be other, if the function for example locks the amount for some days or like this. Or the function would also make sense (but then would be very dangerous) if it freezes the funds of other users and only owner could run it. – dkb Feb 17 '18 at 13:19
  • I am playing around with some contracts, and i have seen the following, an AdminWallet address is used that the tokens are sent from to the asking address, the funds(ether) aggregated on the contract's address and there is a different owners' address with no funds(ether), which normally the ether should be going to in the first place and not to be kept on the contract's address, why would someone do that? – kos_tsak Feb 18 '18 at 0:13
  • I do not exactly understand what you mean but when someone sends funds to a contract address, it is not instantly on the owners address. To be exact, if there is no "withdraw" function or any function that pays the ethers instantly to someone (the owner address), the ethers sent to the contract will be lost forever. – dkb Feb 18 '18 at 14:22
  • with my wallet I sent 1 ether to a contract address, the address that it seems to be sending the tokens is 0x0000000000000000000000000000000000000000 to my wallet address. But the ether is kept on the contract's address balance rather than the owners address. – kos_tsak Feb 18 '18 at 20:01

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.