1

This is my first question here so please bear with me.

I have deployed my first token on test network. I was reading about how to improve Token contracts and stumbled upon this sample file.

This file looked very neatly written but at the same time raised some questions.

https://github.com/bitfwdcommunity/Tutorials/blob/master/Tutorial%201/tutorial1_contract.sol

Can someone please confirm me following: -

1) These are functions to safely perform math operations, Right?

contract SafeMath { }

2) What is the use of ApproveAndCallFallBack ?

contract ApproveAndCallFallBack {
    function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}

3) What is this contract Owned ? I dont get it.

contract Owned {
}

Please help. Thanks

1 Answer 1

1

1.) Yes its used to prevent integers from overflowing or other invalid inputs that could cheat system or cause errors.

2.) ApproveAndCallFallBack is an interface that is used to make calls to other contract that have implementation of receiveApproval function.

As you can see here:

function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        Approval(msg.sender, spender, tokens);
        ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
        return true;
}

Its used to make call to external contract where spender is address of that contract.

3.) Owned is used for functions that have restricted access, every function that have modifier onlyOwner for example here its used for transferAnyERC20Token function, can be accessed only by address that is stored in owner variable. Which is at start address that deployed contract, and later can be changed from that address using functions transferOwnership and acceptOwnership from new owner address.

3
  • Thanks a lot for your reply. So if I understand correctly, constructor function Owned() public is called ONCE when contract is deployed. So it saves address of the deployer as owner ?
    – Sallu
    Commented Jan 19, 2018 at 5:34
  • Also they have address hard coded in constructor function FucksToken() public and once coins are created they are moved to the hard coded address using this command Transfer(address(0), 0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222, _totalSupply);
    – Sallu
    Commented Jan 19, 2018 at 5:36
  • In first case yes, its called once and saves deployer address as owner. But in FucksToken() constructor yes there are hard coded address, but command Transfer(address(0), 0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222, _totalSupply); is used to fire Event that is described in ERC20Interface, actual code that allocates tokens is this command: balances[0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222] = _totalSupply;
    – TracerWimp
    Commented Jan 19, 2018 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.