1
votes

I'm trying to make crowdsale smart contract using "zeppelin-solidity"

But It always throw "revert" error. Especially when I want to use token related function like token.mint, transfer and so on.

Does anyone can check what's wrong in my code?

Below is the crowdsale code.

pragma solidity ^0.4.15;

import './SSSToken.sol';
import 'zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';
import "zeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";


contract SSSTokenSale is Crowdsale {
  using SafeMath for uint256;
  uint256 public round;
  uint256 public every;
  MintableToken public token;

  constructor(
    // uint256 _startTime,
    // uint256 _endTime,
    uint256 _rate,
    address _wallet,
    uint256 _initialMint,
    uint256 _every,
    MintableToken _token
  )
    public
    Crowdsale(_rate, _wallet, _token)
  {
    token = _token;
    // token.mint(_wallet, _initialMint);
    every = _every;
  }

  // function createTokenContract() internal returns (MintableToken) {
  //   return new SSSToken();
  // }

  function () external payable {
      buyTokens(msg.sender);
  }

  function buyTokens(address beneficiary) public payable {
    require(beneficiary != 0x0);
    // calculate token amount to get
    uint256 weiAmount = msg.value;
    uint256 tokens = weiAmount.mul(rate);
    weiRaised = weiRaised.add(weiAmount);
    round = round.add(1);

    // double
    if (round % every == 0) {
      tokens = tokens.mul(2);
    }

    token.mint(msg.sender, tokens);
    TokenPurchase(beneficiary, beneficiary, weiAmount, tokens);

    _forwardFunds();
  }
}

Below is the token contract.

pragma solidity ^0.4.15;

import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';

contract SYToken is MintableToken {
  string public name = "SSS TOKEN";
  string public symbol = "SSS";
  uint256 public decimals = 8;
}

I got several errors something like below.

I don't know why error "Revert" is thrown...

The error "revert" is shown all the time.

1

1 Answers

0
votes

It looks like you commented out the token creation from the crowdsale contract. I assume that means you're deploy ingSYToken manually and then pass the address into your crowdsale contract. When you create the token contract, the owner will be set to whatever address you used when you did the deployment. The mint transaction has onlyOwner as a restriction. When you try to call mint from your crowdsale contract, it uses the address of the crowdsale contract when checking for the owner, not the address of who initiated the transaction. To get around this, either create the token contract when you create the crowdsale contract or transfer ownership of your token contract to the address of your crowdsale contract.

If you still have problems, I'd recommend walking through the debugger in Remix.