Implementing our token sale contract

Our token sale contract will handle the mechanics of buying and selling our token in ether. To do this, our token sale contract will have to communicate with our ERC-20 contract in order to perform transfers from our token sale contract's balance to the balances of participants. For this communication, the token sale contract must know which functions are supported in our ERC-20 contract. This can be done in one of two ways:

  • Define an interface: We can use Solidity's interface keyword to define the parts of the ERC-20 contract that the token sale contract needs to use. We would make this declaration in the same file, above the token-sale contract body.
  • Import the ERC-20 contract: We can use an import statement to include the entire ERC-20 contract. For our implementation, this is the method we'll use.

First, create a new file in our project's contracts/ directory, named PacktTokenSale.sol. At the top of our new file, we want to declare the compiler version and import the ERC-20 contract:

pragma solidity ^0.4.24;

import "./PacktToken.sol";

contract PacktTokenSale {

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset