I am following this tutorial about creating new tokens:


it('one ETH should buy 5 Hashnode Tokens in PreICO', function(done){
        HashnodeCrowdsale.deployed().then(async function(instance) {
            const data = await instance.sendTransaction({ from: accounts[7], value: web3.toWei(1, "ether")});
            const tokenAddress = await instance.token.call();
            const hashnodeToken = HashnodeToken.at(tokenAddress);
            const tokenAmount = await hashnodeToken.balanceOf(accounts[7]);
            assert.equal(tokenAmount.toNumber(), 5000000000000000000, 'The sender didn\'t receive the tokens as per PreICO rate');

Question 1: Many people do not specify "to" in sendTransaction. By default does it go to where instance was deployed? It is not the address: 0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE below. Is this address for the hashnode tokens?

module.exports = function(deployer) {
  const startTime = Math.round((new Date(Date.now() - 86400000).getTime())/1000); // Yesterday
  const endTime = Math.round((new Date().getTime() + (86400000 * 20))/1000); // Today + 20 days
    "0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE", // Replace this wallet address with the last one (10th account) from Ganache UI. This will be treated as the beneficiary address. 
    2000000000000000000, // 2 ETH
    500000000000000000000 // 500 ETH

Question 2: In the test above, accounts[7] is used to send ether from. Then below it uses balanceOf to determine balance of accounts[7]. Does it mean that the same account address i.e. 7 stores ether and hashnode token?

contract HashnodeCrowdsale is CappedCrowdsale, RefundableCrowdsale {
function forwardFunds() internal {
      if (stage == CrowdsaleStage.PreICO) {
          EthTransferred("forwarding funds to wallet");
      } else if (stage == CrowdsaleStage.ICO) {
          EthTransferred("forwarding funds to refundable vault");

HashnodeCrowdsale inherits from CappedCrowdsale which inherits from Crowdsale.

Question 3: forwardFunds is overwritting the forwardFunds in Crowsdale, but then inside Crowdsale when forwardFunds is called the one in HashnodeCrowdsale is called. Should it not be the one inside Crowdsale because Crowdsale does not know that HashnodeCrowdsale is inheriting Crowdsale. It's the other way round Hashnodecrowdsale knows that it is inheriting from Crowdsale

  • If you have three questions, please ask three separate questions. It's hard for someone to search for an answer to their question if it's an embedded part of another question. (It's also hard for someone to answer unless they want to answer all the questions at once.) – user19510 Feb 24 '18 at 22:13

Answer 1: If you do instance.sendTransaction instead of web3.eth.sendTransaction then to is already assigned as instance.

Answer 2: Yes. It basicly means that account[7] created the crowdsale and some amount of tokens (usually full total amount) was assigned to his account during contract creation.

Answer 3: Totally unclear what you are asking. You provided one segment of code and your question is about 3 contracts and you say crowdsale when there are 3 contracts named ******Crowdsale.

Meanwhile my assumption will be that you are confused because some method in HashnodeCrowdsale is calling forwardFunds internally which inside the method uses super. syntax which underthehood is calling inhereted method forwardFunds.

  • Answer 1: how do I know which account correspond to the instance. Answer 2: when we say instance.sendtransaction( {from ; accounts[7]} will it not decrease the amount of ether from accounts[7]. But the how come we get tokens in accounts[7] when we do balanceOf later? thanks – Lily Feb 25 '18 at 7:31
  • @Lily instance.address – Roman Frolov Feb 25 '18 at 7:32
  • Oh, the reason that the accounts[7] can show both ether and the token amounts is because instance first store the ether amount and the HashnodeToken is a different instance which uses the accounts[7] name to store the token. In real life, is my ethereum address the account e.g. accounts[7] and it can store both the token and ether? That address is different from the deployed address? – Lily Feb 25 '18 at 7:46
  • @Lily deployed address is contract address. Your account literally store only ether. All the tokens are stored in token contracts in mapping called balances and you can check your token balance by calling balances[address]. This being said, token contracts literally store a list of token holders and their balances. – Roman Frolov Feb 25 '18 at 8:03
  • Thanks, i understand it now. About answer 3, the tutorial is using openzeppelin. There "Crowdsale" is a contract. So, it's like this HashnodeCrowdsale <-- CappedCrowdsale <-- Crowdsale. I do not see any super.forwardFunds being used. HashnodeCrowdsale defines forwardFunds and Crowdsale.sol also defines forwardFunds. Inside Crowdsale.sol forwardFunds() is called. The one that is executed is the one inside HashnodeCrowdsale. I expected it to be the other way round i.e. when forwardFunds is called inside HashnodeCrowdsale then the one inside Crowdsale.sol will not be executed. – Lily Feb 25 '18 at 20:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.