2017-09-19 5 views
0

私はいくつかのスマート契約テンプレートを見て、いくつかのチュートリアルを見ました。しかし、それらのコードの詳細を1行ずつ調べる人はいません。私は会社の利益の配当を顧客に返す関数を追加したいのですが、どこに追加すればいいですか?例えば、次のコードテンプレートは、私の関数giveBackDividend()をコードブロックに追加できますか?自己定義機能のスマートコントラクトテンプレートを変更する方法

誰でも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); 
     setPricingStrategy(p_strategy); 
     setCeilingStrategy(c_strategy); 
     // 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); 
     token.setReleaseAgent(address(f_agent)); 
     setFinalizeAgent(f_agent); 
    } 

    // 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; 
    } 

}

答えて

1

TL; DR。このコードはブロック番号を使ってICOの開始と終了を定義するだけですが、トークンを実装するためにさまざまなソースを拡張します。それを変更しても問題は発生しません。

あなたは間違った場所から始めていると思います。まず、既存の機能を意識せずに契約に任意のコードを追加できます。少し早すぎますが、翌日にはERC20とERC223の2つのチュートリアルを行います。これはトークンを設計するためのものです。これは、あなたが、その後ICOについて考えたいあなたのトークンのためのあなたの契約を持っていた後

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); 
} 

https://www.youtube.com/channel/UCaWes1eWQ9TbzA695gl_PtA

ERC20

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); 
} 

ERC223に掲載されます。 ICOでは、開始点と終了点を定義する必要があります。この契約は、あなたの実装ルックスのところほとんどである「Crowdsale」と呼ばれる契約から継承している

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

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

:この上の例では、あなたが持っている理由であるブロックをオフに基づいていますそれが来ているように。これの完全なソースコードはhttps://etherscan.io/address/0xb9aac097f4dadcd6f06761eb470346415ef28d5a#codeにあります。このトークンはERC20標準を基にしており、かなりの継承ツリーを持っています。

トークンのコードがBasicTokenで行われます。

/** 
* @title Basic token 
* @dev Basic version of StandardToken, with no allowances. 
*/ 
contract BasicToken is ERC20Basic { 
    using SafeMath for uint; 

    mapping(address => uint) balances; 

    /** 
    * Obsolete. Removed this check based on: 
    * https://blog.coinfabrik.com/smart-contract-short-address-attack-mitigation-failure/ 
    * @dev Fix for the ERC20 short address attack. 
    * 
    * modifier onlyPayloadSize(uint size) { 
    * require(msg.data.length >= size + 4); 
    * _; 
    * } 
    */ 

    /** 
    * @dev transfer token for a specified address 
    * @param _to The address to transfer to. 
    * @param _value The amount to be transferred. 
    */ 
    function transfer(address _to, uint _value) public returns (bool success) { 
    balances[msg.sender] = balances[msg.sender].sub(_value); 
    balances[_to] = balances[_to].add(_value); 
    Transfer(msg.sender, _to, _value); 
    return true; 
    } 

    /** 
    * @dev Gets the balance of the specified address. 
    * @param _owner The address to query the the balance of. 
    * @return An uint representing the amount owned by the passed address. 
    */ 
    function balanceOf(address _owner) public constant returns (uint balance) { 
    return balances[_owner]; 
    } 

} 

あなたがソースに従うことをしようとしている場合、それは結構ですERC20とERC223規格のビットを使用して、少し混乱しているように見えますコード。

関連する問題