이더리움으로 자신만의 토큰 만들기 #4 by elysia

View this thread on steempeak.com
· @elysia · (edited)
$0.30
이더리움으로 자신만의 토큰 만들기 #4
이번에는 토큰의 추가기능들에 대한 내용 입니다~
(본문에 있는 코드는 혹시 모르니 이더리움 홈페이지에서 복사 하는걸 추천 드려요)

원제 : Create your own CRYPTO-CURRENCY with Ethereum
출처 : https://ethereum.org/token

![5lJi5beb.jpg](https://cdn.steemitimages.com/DQmUJitrcYsRPm4BinqVaCZjcGPo9hCmpaAJ2cWreFsR3Xe/5lJi5beb.jpg)

MORE BASIC FUNCTIONS

approve, sendFrom 및 기타와 같은 기본 토큰 계약에 몇 가지 기능이 있음을 알 수 있습니다. 토큰이 다른 계약과 상호 작용할 수 있는 기능은 다음과 같습니다.

토큰을 분산 된 거래소에 판매하려는 경우 계약서에서 이벤트를 구독 할 수 없으므로 거래소가 새로운 토큰이나 발송자를 알지 못하기 때문에 주소로 보내는 것만으로는 충분하지 않습니다. 함수 호출에만 사용됩니다.

따라서 계약의 경우 먼저 계정에서 이동할 수 있는 토큰 양을 승인 한 다음 ping을 수행하여 자신의 일을 해야 한다는 것을 알리거나 approveAndCall로 두 가지 조치를 취해야합니다. 이 함수들 중 많은 것들이 토큰의 전송을 재 구현해야하기 때문에 계약 함수 자체로만 호출 할 수 있는 내부 함수로 변경하는 것이 좋습니다.

...................................................................................................

    /* Internal transfer, can only be called by this contract */
    function _transfer(address _from, address _to, uint _value) internal {
        require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
        require (balanceOf[_from] >= _value);                // Check if the sender has enough
        require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
        require(!frozenAccount[_from]);                     // Check if sender is frozen
        require(!frozenAccount[_to]);                       // Check if recipient is frozen
        balanceOf[_from] -= _value;                         // Subtract from the sender
        balanceOf[_to] += _value;                           // Add the same to the recipient
        emit Transfer(_from, _to, _value);
    }

...................................................................................................

이제 동전 전송을 초래하는 모든 기능이 자체 점검을 수행 한 다음 올바른 매개 변수로 통화를 전송할 수 있습니다. 이 기능을 사용하면 다른 사람의 허가 없이 다른 계정으로 동전을 옮길 수 있습니다. 이것이 내부 기능이므로 계약에 의해서만 호출됩니다. 호출하는 함수를 추가하는 경우에는 호출자에게 이동 권한이 있어야하는지 제대로 확인해야합니다.

CENTRALIZED ADMINISTRATOR

모든 dapp는 기본적으로 완전히 분산되어 있지만 원하는 경우 일종의 중앙 관리자를 가질 수 없다는 것을 의미하지는 않습니다. 어쩌면 당신은 더 많은 동전을 발행할 수 있는 능력을 원할 것입니다, 어쩌면 당신은 어떤 사람들이 당신의 통화를 사용하는 것을 금지하는 것을 원할 것입니다. 이러한 기능 중 하나를 추가 할 수는 있지만 시작 부분에만 추가 할 수 있다는 것이 특징입니다. 그래서 모든 토큰 보유자는 자신이 소유하기로 결정하기 전에 항상 게임의 규칙을 정확히 알 수 있습니다.

그런 일이 일어나려면 중앙 통화 컨트롤러가 필요합니다. 이는 간단한 계정 일 수 있지만 계약 일 수도 있으므로 더 많은 토큰을 만드는 결정은 계약에 따라 다릅니다. 투표를 할 수 있는 민주적 조직이라면 토큰 소유자의 권한을 제한 할 수 있는 방법 일 수 있습니다. 이를 위해 우리는 유익한 계약의 속성인 상속을 배웁니다. 상속을 사용하면 계약서를 모두 재정의하지 않고도 계약서의 특성을 취득 할 수 있습니다. 이렇게 하면 코드를 보다 명확하고 쉽게 재사용 할 수 있습니다.
MyToken 계약을 맺기 전에 이 코드를 코드의 첫 번째 줄에 추가하십시오.

...................................................................................................

    contract owned {
        address public owner;

        function owned() {
            owner = msg.sender;
        }

        modifier onlyOwner {
            require(msg.sender == owner);
            _;
        }

        function transferOwnership(address newOwner) onlyOwner {
            owner = newOwner;
        }
    }

...................................................................................................

이는 "owned" 할 수 있는 계약에 대한 일부 일반 기능을 정의하는 것을 제외하고는 아무것도 하지 않는 매우 기본적인 계약을 생성합니다.
이제 다음 단계는 계약서에 텍스트가 추가되도록 하는 것입니다.

...................................................................................................

    contract MyToken is owned {
        /* the rest of the contract as usual */

...................................................................................................

MyToken 내부의 모든 기능은 변수 소유자와 수정 소유자 만 액세스 할 수 있습니다. 계약은 또한 소유권을 이전하는 기능을 갖습니다. 시작할 때 계약 소유자를 설정하는 것이 흥미로울 수 있으므로 이것을 생성자 함수에 추가 할 수도 있습니다.

...................................................................................................

    function MyToken(
        uint256 initialSupply,
        string tokenName,
        uint8 decimalUnits,
        string tokenSymbol,
        address centralMinter
        ) {
        if(centralMinter != 0 ) owner = centralMinter;
    }

...................................................................................................

CENTRAL MINT

순환하는 동전의 양을 바꾸기를 원한다고 가정 해보십시오. 토큰이 실제로 오프 블록체인 자산(예 : 금 증명서 또는 정부 통화)을 나타내고 가상 인벤토리에 실제 인벤토리가 반영되기를 원하는 경우 입니다. 이는 통화 보유자가 토큰 가격을 일부 통제하기를 기대하고 순환에서 토큰을 발행하거나 제거하려는 경우에도 해당 될 수 있습니다.
먼저 totalSupply를 저장하고 생성자 함수에 할당 할 변수를 추가해야합니다.

...................................................................................................

    contract MyToken {
        uint256 public totalSupply;

        function MyToken(...) {
            totalSupply = initialSupply;
            ...
        }
        ...
    }

...................................................................................................

이제 소유자가 새 토큰을 만들 수 있도록 마지막으로 새 함수를 추가해 보겠습니다.

...................................................................................................
 
    function mintToken(address target, uint256 mintedAmount) onlyOwner {
        balanceOf[target] += mintedAmount;
        totalSupply += mintedAmount;
        emit Transfer(0, owner, mintedAmount);
        emit Transfer(owner, target, mintedAmount);
    }

...................................................................................................

함수 이름 끝에 한정자 onlyOwner가 있음을 알 수 있습니다. 이것은 컴파일 시에 이 함수를 다시 작성하여 이전에 정의한 한정자 onlyOwner의 코드를 상속받습니다.

이 함수의 코드는 한정자 함수에 밑줄이 있는 곳에 삽입됩니다. 즉, 이 특정 함수는 소유자로 설정된 계정에서만 호출 할 수 있습니다. 이 옵션을 owner 한정자가 있는 계약에 추가하기 만하면 더 많은 동전을 만들 수 있습니다.


FREEZING OF ASSETS

사용 케이스에 따라 토큰을 사용할 수 있는 사람과 사용할 수없는 사람에 대한 규정적인 장애물이 필요할 수 있습니다. 이를 위해 계약 소유자가 자산을 고정하거나 고정 해제 할 수 있는 매개 변수를 추가 할 수 있습니다. 계약 내 어디서나 이 변수와 함수를 추가하십시오. 어디서나 배치 할 수 있지만 좋은 연습을 위해 다른 매핑 및 이벤트와 매핑을 다른 이벤트와 함께 배치하는 것이 좋습니다.

...................................................................................................

    mapping (address => bool) public frozenAccount;
    event FrozenFunds(address target, bool frozen);

    function freezeAccount(address target, bool freeze) onlyOwner {
        frozenAccount[target] = freeze;
        emit FrozenFunds(target, freeze);
    }

...................................................................................................

이 코드를 사용하면 모든 계정이 기본적으로 동결해제 되지만 소유자는 동결계정으로 전화하여 동결상태로 설정할 수 있습니다. 불행히도, 우리가 전달 함수에 아무 것도 추가하지 않았기 때문에 동결은 실제적인 효과가 없습니다.
우리는 지금 그것을 변화 시킵니다.

...................................................................................................

    function transfer(address _to, uint256 _value) {
        require(!frozenAccount[msg.sender]);

...................................................................................................

이제 동결 된 계정에는 자금이 그대로 유지되지만 이동할 수는 없습니다. 모든 계정은 기본적으로 사용자가 동결 할 때까지 동결 해제되지만, 수동으로 모든 계정을 승인하면 허용 목록으로 쉽게 되돌릴 수 있습니다.
frozenAccount의 이름을 approvedAccount로 변경하고 마지막 행을 다음으로 변경하십시오.

...................................................................................................

        require(approvedAccount[msg.sender]);

...................................................................................................
👍  , , , , , ,
properties (23)
post_id60,138,397
authorelysia
permlink4
categorykr
json_metadata{"format":"markdown","app":"steemit\/0.1","tags":["kr","crypto","blockchain","bitcoin","ethereum"],"image":["https:\/\/cdn.steemitimages.com\/DQmUJitrcYsRPm4BinqVaCZjcGPo9hCmpaAJ2cWreFsR3Xe\/5lJi5beb.jpg"],"links":["https:\/\/ethereum.org\/token"]}
created2018-08-19 10:26:57
last_update2018-08-19 10:33:45
depth0
children4
net_rshares224,926,606,330
last_payout2018-08-26 10:26:57
cashout_time1969-12-31 23:59:59
total_payout_value0.232 SBD
curator_payout_value0.068 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6,989
author_reputation36,963,899,244
root_title"이더리움으로 자신만의 토큰 만들기 #4"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (7)
@steemitboard ·
Congratulations @elysia! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/votes.png)](http://steemitboard.com/@elysia) Award for the number of upvotes

<sub>_Click on the badge to view your Board of Honor._</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Do not miss the last post from @steemitboard:**
[SteemitBoard and the Veterans on Steemit - The First Community Badge.](https://steemit.com/veterans/@steemitboard/steemitboard-and-the-veterans-on-steemit-the-first-community-badge)

> Do you like [SteemitBoard's project](https://steemit.com/@steemitboard)? Then **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!
👍  
properties (23)
post_id60,555,863
authorsteemitboard
permlinksteemitboard-notify-elysia-20180823t193341000z
categorykr
json_metadata{"image":["https:\/\/steemitboard.com\/img\/notify.png"]}
created2018-08-23 19:33:39
last_update2018-08-23 19:33:39
depth1
children1
net_rshares388,689,079
last_payout2018-08-30 19:33:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length900
author_reputation38,705,954,145,809
root_title"이더리움으로 자신만의 토큰 만들기 #4"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@elysia ·
Thanks~!!
properties (22)
post_id60,627,391
authorelysia
permlinkre-steemitboard-steemitboard-notify-elysia-20180824t150602652z
categorykr
json_metadata{"app":"steemit\/0.1","tags":["kr"]}
created2018-08-24 15:06:06
last_update2018-08-24 15:06:06
depth2
children0
net_rshares0
last_payout2018-08-31 15:06:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation36,963,899,244
root_title"이더리움으로 자신만의 토큰 만들기 #4"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@doosan ·
이오스로 만들기도 연재하시면 좋을 것 같아요 ㅅ ㅅ
👍  
properties (23)
post_id60,584,291
authordoosan
permlinkre-elysia-4-20180824t035159233z
categorykr
json_metadata{"tags":["kr"],"app":"steemit\/0.1"}
created2018-08-24 03:52:00
last_update2018-08-24 03:52:00
depth1
children1
net_rshares379,579,178
last_payout2018-08-31 03:52:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length28
author_reputation9,847,666,521,101
root_title"이더리움으로 자신만의 토큰 만들기 #4"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@elysia ·
감사합니다~^^ 이더리움으로 만들기 끝나고나면 이오스도 시도해볼께요~!!
properties (22)
post_id60,627,823
authorelysia
permlinkre-doosan-re-elysia-4-20180824t151101106z
categorykr
json_metadata{"app":"steemit\/0.1","tags":["kr"]}
created2018-08-24 15:11:03
last_update2018-08-24 15:11:03
depth2
children0
net_rshares0
last_payout2018-08-31 15:11:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length40
author_reputation36,963,899,244
root_title"이더리움으로 자신만의 토큰 만들기 #4"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000