0

I am new to solidity coding and after I created some basic contracts as well as a ERC20 token contract I wanted to create a crowdsale contract. Now I am stuck and I have a question regarding the implementation of an allowance crowdsale contract using the OpenZeppelin contracts.

Here is the code I added after importing SafeMath, Ownable, ERC20Basic, ERC20, Crowdsale, WhitelistedCrowdsale, AllowanceCrowdsale, CappedCrowdsale, TimedCrowdsale:

contract TestToken is ERC20 {
    using SafeMath for uint256;

    string public symbol = "TEST";
    string public name = "TEST Token";
    uint8 public decimals = 18;
    uint256 public _totalSupply = 140000000 * 10**uint256(decimals);
}


contract TestCrowdsale is Crowdsale, WhitelistedCrowdsale, AllowanceCrowdsale, CappedCrowdsale, TimedCrowdsale
{
function TestCrowdsale(
    uint256 _openingTime,
    uint256 _closingTime,
    uint256 _rate,
    address _wallet,
    address _tokenWallet,
    uint256 _cap,
    TestToken _token
    )
    public
    Crowdsale(_rate, _wallet, _token)
    AllowanceCrowdsale(_tokenWallet)
    CappedCrowdsale(_cap)
    TimedCrowdsale(_openingTime, _closingTime)
    {
    }
}

My Questions...

Q1: Where do I enter the token contract address if I want to use a token which was created before the crowdsale contract?

Q2: If I cannot enter it anywhere directly, how do I define the token interface in the crowdsale contract? I tried in the same way shown in the example crowdsale contract which uses a minted Token but it failed.

Q3: If the two mentioned options are wrong, do I have to create the Token and the crowdsale in one step?

Q4: Do I have to change anything to the imported contracts themselves for example because of the multiple use of _prevalidatePurchase or _deliverTokens functions?

Thank you very much in advance for your help.

0

I know it's been 3 months already, but the answer may be useful to other. When I arrived here I knew part of the answer, so let me completely answer it. Let me first answer your questions:

Q1. On the TestCrowdsale constructor, the field TestToken _token should be the token contract address

Q2. You can!

Q3. A "long time ago", that's how this worked, but it changed ... you have your answer.

Q4. No, look at this contracts like Java classes. The crowdsale is the most basic one, and the others extend it, and sometimes they override methods like the _deliverTokens method. In this case, AllowanceCrowdsale is overriding these methods, but MintedCrowdsale also does.

I think it answered your questions. Now, what you are missing is how to deploy those contracts.
Well, there are a few methods, but let me say using Truffle is the easiest way.
Since I've done this recently let me show how it's done

var YourCrowdsale = artifacts.require("./YourCrowdsale.sol");
var YourCoin = artifacts.require("./YourCoin.sol");

module.exports = function(deployer, network, accounts) {
    deployer.then(() => {
        return deployer.deploy(YourCoin);
    })
    .then(() => {
        var rate = 1;
        var wallet = accounts[0];
        return deployer.deploy(YourCrowdsale, rate, wallet, wallet, YourCoin.address);
    });
};

This is called a migrations file on truffle (just have a look on their website). One important note, it was done with Truffle v4, the v5 was released a few days and fixed a few bugs, including the need to user deployer.then().then() .... (there was a bug on v4 that didn't let deploy contracts inside promises, so that was the trick).

Now, the last important thing, if you are using open-zepplin you have to transfer ownership of contracts, like this YourCoinInstance.transferOwnership(YourCrowdsaleInstance.address);. In case you are using a MintableCrowdsale, it's enough, you can start mining, in this case, you also need to approve to transfer tokens, like YourCoinInstance.approve(YourCrowdsaleInstance.address, web3.toWei(ammountOfTokens, 'ether'));.

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.