4

I understand that the following function is used to link the ico contract to the token. Appreciate if someone could explain how to use the function, and exactly how it works. Thank you.

/**
 * @title Token
 * @dev API interface for interacting with the Token contract 
 */
interface Token {
  function transfer(address _to, uint256 _value) returns (bool);
  function balanceOf(address _owner) constant returns (uint256 balance);
}
9

It's an "Abstract" a.k.a. "Interface" contract.

It's used to define the interface, meaning the functions that exist, their exact names and inputs/outputs while being silent about how they work internally.

The idea is to use inheritance to create a compliant implementation - a contract with the exact same functions implemented.

You go about it like this.

contract Interface {
  // undefined functions with names and arguments
}

contract Implementation is Interface {
  // now you are forced to have matching functions with definition
}
```

You will not be able to deploy Implementation unless it implements each function defined in Interface.

Hope it helps.

  • Thank you. That's really helpful. I've done some further research and it clearer. One thing i'm still confused about is the Ed Zygga video (link below - 4:20 onwards) he includes the following lines of text in the contract: – double_aces Jan 1 '18 at 18:27
1

This is an interface for interacting with the Token Contract. If you read the solidity doc, you will notice the characteristics for the interface.

Let me write about the properties of an interface again:

1) Interfaces cannot have any functions implemented

2) Interfaces cannot inherit other contracts or interfaces

3) Interfaces cannot define a constructor

4) Interfaces cannot define variables

5) Interfaces cannot define structs

6) Interfaces cannot define enums.

7) Interfaces are expressed using the interface keyword.

Now if we analyze the code :

 interface Token {
   function transfer(address _to, uint256 _value) returns (bool);
   function balanceOf(address _owner) constant returns (uint256 balance);
}

Token interface has two functions. Both of these functions are not implemented here. But anyone can implement these functions later.That's the fun part.

0

The balance of the users is stored in a mapping called balances;

mapping(address => uint) balances;

When you call the transfer function with the receiver's address and the amount to be transferred, you reduce your balance by that amount and increase the receiver's amount. Like this:

balances[msg.sender] -= _value;
balances[_to] += _value;

BalanceOf function simply returns your balance.

return balances[msg.sender]

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.