When I started crowdsale, I transferred token ownership to the crowdsale contract. When the sale finished, I'd like to send back the ownership to token so that the next crowdsale will start. How can I do that? I guess I can use FinalizableCrowdsale for defining those functions, but I have no idea how to get the token address in the contract and how to define the finalize() function... help me..

Actually, the contract was working well, but after finishing the crowdsale, the finalize() that I defined in the contract didn't work which means the ownership was not transferred. Should I call the function manually?


pragma solidity 0.4.24;

import "./DappToken.sol";

import "../node_modules/openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/distribution/FinalizableCrowdsale.sol";
// import "../node_modules/openzeppelin-solidity/contracts/crowdsale/validation/WhitelistedCrowdsale.sol";

contract DappTokenCrowdsale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, FinalizableCrowdsale {
    DappToken private token;
    address tokenAddress;
    address crowdsaleOwner;

    bool public isFinalized = false;

      uint256 _rate,
      address _wallet,
      DappToken _token,
      uint256 _cap,
      uint256 _openingTime,
      uint256 _closingTime
    Crowdsale(_rate, _wallet, _token)
    TimedCrowdsale(_openingTime, _closingTime)
      token = _token;
      crowdsaleOwner = msg.sender;

    function transferOwnership(address _newOwner) public onlyOwner {
        require(msg.sender == crowdsaleOwner); // Only the owner of the crowdsale contract should be able to call this function.
        // I assume the crowdsale contract holds a reference to the token contract.

    function finalize() onlyOwner public {


      emit Finalized();

      isFinalized = true;
  • What does your MintableToken look like? If your MintableToken is the basic OpenZeppelin's token contract, then it inherits from Ownable and has the transferOWnership function which you can call. You seem to be missing an import for it at least? – Lauri Peltonen Nov 27 '18 at 4:08
  • @LauriPeltonen Ah, I just editted the code, and updated the question. the error has gone, but finalize() function didn't work T-T.. Should I call the function manually?? I thought, the contract inherited FinalizableCrowdsale, and I re-defined finalize() function on my contract. So, it gonna be working when the crowdsale finished, but it was not... – Unha Back Nov 27 '18 at 4:15
  • @LauriPeltonen I verified the code on the Etherscan and tried to call that function manually, but it was failed. I guess, the MetaMask that I logged on is not an owner of the contract.. How can I call it? currently, the owner of the token is an address of crowdsale. – Unha Back Nov 27 '18 at 4:19
  • transferOwnership can only be called by the owner, otherwise anyone could claim ownership. The crowdsale address would have to call it – flygoing Nov 27 '18 at 14:13
  • @UnhaBack If you called finalize() then you are executing transferOwnership(token) which will execute token.transferOwnership(token) setting itself as its owner. If you are using OpenZeppelin contracts then unless the token was modified to handle this case you will not be able to change the owner again. – Ismael Nov 28 '18 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.