0

I am deploying contract that creates a token and a crowdsale, based on code slightly modified from zeppelin-solidity.

Problem: After deploying the contract to Rinkeby using Truffle and Infura, searching the Contract Address 0x9B4b8583048D77F7CDc5c665f138E6dbce1e37Ba on [Etherscan's ERC20 Token Search][2] gave the result that no token is found in that contract address!

What went wrong?

Output of truffle migrate --network rinkeby

Using network 'rinkeby'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0xb101fbf5cb0c6f2e0e937484c2db43cef906501d5544c0ce742fd6965a06594e
  Migrations: 0x9b4b8583048d77f7cdc5c665f138e6dbce1e37ba
Saving successful migration to network...
  ... 0x53dd9d5eb01e0dc636695a21ea8e95d58862a0c9e010c7fa8c840048fc21f7ad
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Replacing SampleCrowdsale...
  ... 0x31fef6189be9eb877b87751cd27c00f52e46c0fca3ce17722a4a586691a5c995
  SampleCrowdsale: 0x2c7bf1f6c01bd45e104de98e96266a2b1f07907f
Saving successful migration to network...
  ... 0xddfecd93e7d8aefa4c438a0e4a7d8e775e17ff6241177b0511413a5ccb665985
Saving artifacts...

SampleCrowdsale.sol

pragma solidity ^0.4.11;

import "zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol";
import "zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol";
import "zeppelin-solidity/contracts/token/MintableToken.sol";


contract SampleCrowdsaleToken is MintableToken {

  string public constant name = "Sample Crowdsale Token";
  string public constant symbol = "SCT";
  uint8 public constant decimals = 18;

  uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));

  /**
   * @dev Constructor that gives msg.sender all of existing tokens.
   */
  function SampleCrowdsaleToken() {
    totalSupply = INITIAL_SUPPLY;
    balances[msg.sender] = INITIAL_SUPPLY;
  }

}


contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {

  function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet)
    CappedCrowdsale(_cap)
    FinalizableCrowdsale()
    RefundableCrowdsale(_goal)
    Crowdsale(_startTime, _endTime, _rate, _wallet)
  {
    //As goal needs to be met for a successful crowdsale
    //the value needs to less or equal than a cap which is limit for accepted funds
    require(_goal <= _cap);
  }

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

}

2_deploy_contract.js

var SampleCrowdsale = artifacts.require("../contracts/SampleCrowdsale.sol");

module.exports = function(deployer) {
    var d = new Date()
    var startTime = d.getTime()
    var endTime = startTime + (86400 * 20) // 20 days
    const rate = new web3.BigNumber(1000)
    const goal = 10000
    const cap = 1000000
    const wallet = '0xcede48d8aC162d1b08ed9419010DE3c99F2cfDd6'
  deployer.deploy(SampleCrowdsale, startTime, endTime, rate, goal, cap, wallet);
};

This creates 2 contracts

  • Migrations: 0xc0e02bc10bc4fbdba607365afcab5f6c992759e0
  • SampleCrowdsale: 0x09451e7df77a32f4b35858385b96ddd0a4e2bff2

However using0x09451e7df77a32f4b35858385b96ddd0a4e2bff2 in Metamask Add Token feature does not add any Token. Etherscan's ETC20 Standard Token Explorer also does not find any valid Token at the contract address.

1

*** Adding a new answer as my previous one does not reflect the current state of the question.

If I'm not mistaken you are searching on Etherscan this address: 0x09451e7df77a32f4b35858385b96ddd0a4e2bff2 which corresponds to the Crowdsale.

What you need to look for on Etherscan is the contract address for the SampleCrowdsaleToken that gets created inside the Crowdsale token.

You'll have to deploy the Crowdsale contract and then findout the address to which the token was deployed.

Update:

From the output of truffle migrate posted in the question, it appears that only 2 contracts were created, 1 for the truffle migration (from 1_intiial_migration.js) and one for the crowdsale (from 2_deploy_contracts.js). Is there supposed to be a third contract created for the token? I cant seem to find a third contract.

Focus on the Crowdsale contract that was deployed. Inside this Crowdsale contract, the createTokenContract method is instantiating your Coin contract, actually deploying it to a new address. That address is the one you must inspect on Etherscan to find your token.

Here's a step by step guide to search the token contract. It's based on exactly the same code you posted and available on Ropsten testnet:

1- Search your Crowdsale contract on Etherscan: Mine deployed at https://ropsten.etherscan.io/address/0xb40b859107e7e788895f06fffdbb8db7777dcb9e

2- Go to "Internal Transactions" tab, this will show transactions made by internal contracts. https://ropsten.etherscan.io/address/0xb40b859107e7e788895f06fffdbb8db7777dcb9e#internaltx It will initially show 1 transaction, which is contract creation (that's the Coin contract that Crowdsale contract deployed). Mine will show 2 transactions as I already bought some tokens.

3- Click on Contract Creation transaction. It will redirect you to the address to which the Coin was deployed. That's your Token address https://ropsten.etherscan.io/address/0x50729cd2a36984b6ee6757755eb59ae2f87a7d20

4- Go to https://ropsten.etherscan.io/token-search and search your token by address, which is the one you got previously. In this case: 0x50729cd2a36984b6ee6757755eb59ae2f87a7d20

5- The following screen will show after you make at least 1 transaction with your Token (For example, use Metamask to send ether to the Crowdsale which will trigger the fallback function of the Crowdsale, which calls buyTokens(). Even if you didn't make a transaction you should be able to see the state variables of your token, such as name, totalSupply, etc.

If you did everything correctly, you should see this:

enter image description here

  • From the output of truffle migrate posted in the question, it appears that only 2 contracts were created, 1 for the truffle migration (from 1_intiial_migration.js) and one for the crowdsale (from 2_deploy_contracts.js). Is there supposed to be a third contract created for the token? I cant seem to find a third contract. – Nyxynyx Oct 13 '17 at 4:47
  • @pabloruiz55 You should be able to edit your own answer to add/remove information. – Ismael Oct 13 '17 at 6:12
  • @Ismael Yes, I'm aware of that, but given that this question has mutated since it was originally posted, I preferred adding another answer related to the current state, rather than removing the previous one, in case it's useful for someone else with a similar problem. – pabloruiz55 Oct 13 '17 at 12:33
  • Perfect, everything makes sense now! Did not know how to search for the token contract from the crowdsale contract. Step by step guide isvery helpful. – Nyxynyx Oct 13 '17 at 14:31
0

It seems you are not overriding the Crowsale's function that handles the token creation.

This is the function as it appears in Crowdsale.sol

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

You should override it in your SampleCrowdsale implementation:

// creates the token to be sold.
// override this method to have crowdsale of a specific MintableToken token.
function createTokenContract() internal returns (MintableToken) {
  return new SimpleToken();
}
  • Added createTokenContract back to Crowdsale.sol, but still not able to find any valid tokens at the contract address for SampleCrowdsale using Metamask and Etherscan's ERC20 Token explorer – Nyxynyx Oct 12 '17 at 20:55
  • Note that I did create an initial supply of the token and send it all to msg.sender – Nyxynyx Oct 12 '17 at 20:55

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.