how to modify smart contract template for self defined functionality

0 votes

I have looked at several smart contract template and go through several tutorials. But none of them go through details of those code line by line. I want to add a function that give back dividends of company profit to customers, where should I add it? For example the following code template, can I add my function giveBackDividend() in the code block?

can anyone walk me through the general structure of smart contract for ICO?

contract HubiiCrowdsale is Crowdsale {
  uint private constant chunked_multiple = 18000 * (10 ** 18); // in wei
  uint private constant limit_per_address = 100000 * (10 ** 18); // in wei
  uint private constant hubii_minimum_funding = 17000 * (10 ** 18); // in wei
  uint private constant token_initial_supply = 0;
  uint8 private constant token_decimals = 15;
  bool private constant token_mintable = true;
  string private constant token_name = "Hubiits";
  string private constant token_symbol = "HBT";
  uint private constant token_in_wei = 10 ** 15;
  // The fraction of 10,000 out of the total target tokens that is used to mint bonus tokens. These are allocated to the team's multisig wallet.
  uint private constant bonus_base_points = 3000;
  function HubiiCrowdsale(address _teamMultisig, uint _start, uint _end) Crowdsale(_teamMultisig, _start, _end, hubii_minimum_funding) public {
      PricingStrategy p_strategy = new FlatPricing(token_in_wei);
      CeilingStrategy c_strategy = new FixedCeiling(chunked_multiple, limit_per_address);
      FinalizeAgent f_agent = new BonusFinalizeAgent(this, bonus_base_points, _teamMultisig); 
      // Testing values
      token = new CrowdsaleToken(token_name, token_symbol, token_initial_supply, token_decimals, _teamMultisig, token_mintable);
      token.setMintAgent(address(this), true);
      token.setMintAgent(address(f_agent), true);

  // These two setters are present only to correct block numbers if they are off from their target date by more than, say, a day
  function setStartingBlock(uint startingBlock) public onlyOwner inState(State.PreFunding) {
      require(startingBlock > block.number && startingBlock < endsAt);
      startsAt = startingBlock;

  function setEndingBlock(uint endingBlock) public onlyOwner notFinished {
      require(endingBlock > block.number && endingBlock > startsAt);
      endsAt = endingBlock;
Aug 1, 2018 in Blockchain by charlie_brown
• 7,720 points

1 answer to this question.

0 votes

TL;DR; This code simply defines the start and end of the ICO using block number, but it extends various other sources to implement the Token, etc. Modifying it won't cause any issues.

I think you're starting in the wrong place. Firstly, you can add any code to any contract without implicating its existing functionality. I know it's a little premature, but I plan to do 2 tutorials in the next day or so on the ERC20 and ERC223 standards which is what a token should be designed around. This will be posted on


contract ERC20 {
    function totalSupply() constant returns (uint totalSupply);
    function balanceOf(address _owner) constant returns (uint balance);
    function transfer(address _to, uint _value) returns (bool success);
    function transferFrom(address _from, address _to, uint _value) returns (bool success);
    function approve(address _spender, uint _value) returns (bool success);
    function allowance(address _owner, address _spender) constant returns (uint remaining);
    event Transfer(address indexed _from, address indexed _to, uint _value);
    event Approval(address indexed _owner, address indexed _spender, uint _value);


contract ERC223 {
    uint public totalSupply;
    function balanceOf(address who) constant returns (uint);
    function name() constant returns (string _name);
    function symbol() constant returns (string _symbol);
    function decimals() constant returns (uint8 _decimals);
    function totalSupply() constant returns (uint256 _supply);
    function transfer(address to, uint value) returns (bool ok);
    function transfer(address to, uint value, bytes data) returns (bool ok);
    function transfer(address to, uint value, bytes data, string custom_fallback) returns (bool ok);
    event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);

After you have your contract for your token you then want to think about the ICO. With the ICO you should define start and end points. In the example above this is based off the blocks which is why you have:

  require(startingBlock > block.number && startingBlock < endsAt);


  require(endingBlock > block.number && endingBlock > startsAt);

This contract is inheriting from a contract called "Crowdsale" which is where most of your implementation looks like it's coming from. The full source code for this can be found on This token is based around ERC20 standard and has quite a bit of an inheritance tree.

answered Aug 1, 2018 by aryya
• 7,450 points

Related Questions In Blockchain

+1 vote
4 answers

How to estimate the cost for deploying smart contract on mainnet?

Since you have already deployed the contract ...READ MORE

answered Apr 10, 2018 in Blockchain by Shashank
• 10,400 points
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,100 points
0 votes
1 answer

How is a request sent from an app to a smart contract?

Yes, the contract is distributed by every node ...READ MORE

answered Jun 4, 2018 in Blockchain by Perry
• 17,100 points
0 votes
1 answer

How to prevent the smart contract from being modified and deployed in the blockchain network?

To expand on Matthew's answer, each state ...READ MORE

answered Jul 6, 2018 in Blockchain by aryya
• 7,450 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
0 votes
2 answers

How to get notified when an event triggers on ethereum smart contract?

Muchas gracias. ?Como puedo iniciar sesion? READ MORE

answered May 2, 2020 in Blockchain by aqowcmbevs
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP