pragma solidity ^0.4.2;
   import DappToken;

    contract DappTokenSale {
       address admin;
       DappToken public tokenContract;

      function DappTokeSale(DappToken _tokenContract) public {

          admin = msg.sender;

DappToken is my previous smartContract why did we declare a varable type of contract how is it diffrent from other types why did we declared DappToken public tokenContract;


The variable DappToken is a user-defined variable and the variable admin is a primitive variable. I don't think there is any other difference between the two vaiables.

I am assuming you are following this tutorial.

As you are accessing transfer function of DappToken contract in buyTokens and endSale method you need to import DappToken smart contract.

Hope it helps.

| improve this answer | |
  • DappToken is the name of the smart contract i defined before in tutorial we are asked to name it is DappToken i don't know why i have imported also DappToken in my smart contract – Venkatesh Muthyala Oct 8 '18 at 11:25
  • @VenkateshMuthyala, I have updated my answer. Let me know if you need any further clarification. – Soham Lawar Oct 8 '18 at 12:28

Smart contract types are basically syntactic sugar around addresses, that add convenient way to call smart contract methods no them. They also add some type-safety on assignments and argument passing. On low level

DappToken public tokenContract;

is the same as

address public tokenContract;

but you may call methods like tokenContract.foo(...) rather than like DappToken (tokenContract).foo (...).

| improve this answer | |

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.