Skip to main content

You have to do something like this:

  • Token.sol

     // This should be an abstract interface without implementation
     constractcontract Token {
       function mint(address _to, uint _amount) public returns (bool);
    
       // Rest of the ERC20 methodscode
     }
    
  • CrowdsaleToken.sol

     import "Token.sol";
    
     // This contract contains the implementation of ERC20 methods
     contract CrowdsaleToken is Token {
    
       function mint(address _to, uint _amount) public returns (bool) {
           balances[_to] = balances[_to] + _amount;
           return true;
       }
    
       // ImplementationRest of other ERC20the methodscode
     }
    
  • Crowdsale.sol

     import "Token.sol";
    
     // The Crowdsale  interact with CrowdsaleToke through the
     // abstract interface Token
     contact Crowdsale {
         Token crowdsaleToken; // Address of the CrowdsaleToken
    
         function Crowdsale(address _crowdsaleToken) {
             // We receive the CrowdsaleToken addres as constructor param
             crowdsaleToken = Token(_crowdsaleToken);
    
             // We can use the CrowdsaleToken contract
             crowdsaleToken.mint(msg.sender, 0x31415926535);
         }
    
         // Other crowdsale methods
     }
    

The deployment is done in two steps

  1. Deploy CrowdsaleToken, await for the contract address
  2. Deploy Crowdsale and pass the CrowdsaleToken address as parameter

That is the basic idea.

Some frameworks like Truffle and Populus can be used to automate some of this tasks.

You have to do something like this:

  • Token.sol

     // This should be an abstract interface without implementation
     constract Token {
       function mint(address _to, uint _amount) public returns (bool);
    
       // Rest of the ERC20 methods
     }
    
  • CrowdsaleToken.sol

     import "Token.sol";
    
     // This contract contains the implementation of ERC20 methods
     contract CrowdsaleToken is Token {
    
       function mint(address _to, uint _amount) public returns (bool) {
           balances[_to] = balances[_to] + _amount;
           return true;
       }
    
       // Implementation of other ERC20 methods
     }
    
  • Crowdsale.sol

     import "Token.sol";
    
     // The Crowdsale  interact with CrowdsaleToke through the
     // abstract interface Token
     contact Crowdsale {
         Token crowdsaleToken; // Address of the CrowdsaleToken
    
         function Crowdsale(address _crowdsaleToken) {
             // We receive the CrowdsaleToken addres as constructor param
             crowdsaleToken = Token(_crowdsaleToken);
    
             // We can use the CrowdsaleToken contract
             crowdsaleToken.mint(msg.sender, 0x31415926535);
         }
    
         // Other crowdsale methods
     }
    

The deployment is done in two steps

  1. Deploy CrowdsaleToken, await for the contract address
  2. Deploy Crowdsale and pass the CrowdsaleToken address as parameter

That is the basic idea.

Some frameworks like Truffle and Populus can be used to automate some of this tasks.

You have to do something like this:

  • Token.sol

     // This should be an abstract interface without implementation
     contract Token {
       function mint(address _to, uint _amount) public returns (bool);
    
       // Rest of the code
     }
    
  • CrowdsaleToken.sol

     import "Token.sol";
    
     // This contract contains the implementation of ERC20 methods
     contract CrowdsaleToken is Token {
    
       function mint(address _to, uint _amount) public returns (bool) {
           balances[_to] = balances[_to] + _amount;
           return true;
       }
    
       // Rest of the code
     }
    
  • Crowdsale.sol

     import "Token.sol";
    
     // The Crowdsale  interact with CrowdsaleToke through the
     // abstract interface Token
     contact Crowdsale {
         Token crowdsaleToken; // Address of the CrowdsaleToken
    
         function Crowdsale(address _crowdsaleToken) {
             // We receive the CrowdsaleToken addres as constructor param
             crowdsaleToken = Token(_crowdsaleToken);
    
             // We can use the CrowdsaleToken contract
             crowdsaleToken.mint(msg.sender, 0x31415926535);
         }
    
         // Other crowdsale methods
     }
    

The deployment is done in two steps

  1. Deploy CrowdsaleToken, await for the contract address
  2. Deploy Crowdsale and pass the CrowdsaleToken address as parameter

That is the basic idea.

Some frameworks like Truffle and Populus can be used to automate some of this tasks.

Source Link
Ismael
  • 30.3k
  • 23
  • 54
  • 97

You have to do something like this:

  • Token.sol

     // This should be an abstract interface without implementation
     constract Token {
       function mint(address _to, uint _amount) public returns (bool);
    
       // Rest of the ERC20 methods
     }
    
  • CrowdsaleToken.sol

     import "Token.sol";
    
     // This contract contains the implementation of ERC20 methods
     contract CrowdsaleToken is Token {
    
       function mint(address _to, uint _amount) public returns (bool) {
           balances[_to] = balances[_to] + _amount;
           return true;
       }
    
       // Implementation of other ERC20 methods
     }
    
  • Crowdsale.sol

     import "Token.sol";
    
     // The Crowdsale  interact with CrowdsaleToke through the
     // abstract interface Token
     contact Crowdsale {
         Token crowdsaleToken; // Address of the CrowdsaleToken
    
         function Crowdsale(address _crowdsaleToken) {
             // We receive the CrowdsaleToken addres as constructor param
             crowdsaleToken = Token(_crowdsaleToken);
    
             // We can use the CrowdsaleToken contract
             crowdsaleToken.mint(msg.sender, 0x31415926535);
         }
    
         // Other crowdsale methods
     }
    

The deployment is done in two steps

  1. Deploy CrowdsaleToken, await for the contract address
  2. Deploy Crowdsale and pass the CrowdsaleToken address as parameter

That is the basic idea.

Some frameworks like Truffle and Populus can be used to automate some of this tasks.