'2017/07/11'에 해당되는 글 2건

  1. 2017.07.11 이더리움 - Token 만들기(4) 1
  2. 2017.07.11 이더리움 - Token 만들기(3) 2
블록체인2017. 7. 11. 15:06


코인 사용하기


토큰을 배포하면 토큰 목록에 추가되고 총 잔액이 계정에 표시된다. 토큰을 보내려면 보내기 탭으로 이동하여 토큰이 포함 된 계정을 선택하라. 계정에있는 토큰은 이더 아래에 나열된다. 그들을 선택하고 보내려는 토큰의 양을 입력하라.

다른 사람의 토큰을 추가하려면 계약 탭으로 이동하여 토큰보기를 클릭하라. 예를 들어, 감시 목록에 Unicorn (🦄) 토큰을 추가하려면 주소 0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7을 추가하기 만하면 나머지 정보가 자동으로로드된다. 확인을 클릭하면 토큰이 추가된다.

유니콘 토큰은 Ethereum Foundation이 관리하는 주소 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359에 기부 한 사람들을 위해 독점적으로 만들어지는 기념품이다. 이에 대해 더 알고 싶다면 여기를 읽어보아라.


이더리움으로 토큰을 발행하는 방법을 배웠다. 원하는 토큰을 만들 수 있다. 하지만 토큰으로 무엇을 할 수 있을까? 회사의 주식이 가능합니다. 또한 중앙위원회를 사용하여 인플레이션을 제어하기 위해 새로운 동전을 ㅂ라행 할 시기에 투표할 수 있다. 또한 crowdsale을 통해 어떤문제를 위해 돈을 모으기 위해 사용가능 하다. 다음엔 무엇을 만들래?

Posted by 삼스
블록체인2017. 7. 11. 14:54

전체 코드


pragma solidity ^0.4.2;

contract owned {

    address public owner;


    function owned() {

        owner = msg.sender;

    }


    modifier onlyOwner {

        if (msg.sender != owner) throw;

        _;

    }


    function transferOwnership(address newOwner) onlyOwner {

        owner = newOwner;

    }

}


contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }


contract token {

    /* Public variables of the token */

    string public standard = 'Token 0.1';

    string public name;

    string public symbol;

    uint8 public decimals;

    uint256 public totalSupply;


    /* This creates an array with all balances */

    mapping (address => uint256) public balanceOf;

    mapping (address => mapping (address => uint256)) public allowance;


    /* This generates a public event on the blockchain that will notify clients */

    event Transfer(address indexed from, address indexed to, uint256 value);


    /* Initializes contract with initial supply tokens to the creator of the contract */

    function token(

        uint256 initialSupply,

        string tokenName,

        uint8 decimalUnits,

        string tokenSymbol

        ) {

        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens

        totalSupply = initialSupply;                        // Update total supply

        name = tokenName;                                   // Set the name for display purposes

        symbol = tokenSymbol;                               // Set the symbol for display purposes

        decimals = decimalUnits;                            // Amount of decimals for display purposes

    }


    /* Send coins */

    function transfer(address _to, uint256 _value) {

        if (balanceOf[msg.sender] < _value) throw;           // Check if the sender has enough

        if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows

        balanceOf[msg.sender] -= _value;                     // Subtract from the sender

        balanceOf[_to] += _value;                            // Add the same to the recipient

        Transfer(msg.sender, _to, _value);                   // Notify anyone listening that this transfer took place

    }


    /* Allow another contract to spend some tokens in your behalf */

    function approve(address _spender, uint256 _value)

        returns (bool success) {

        allowance[msg.sender][_spender] = _value;

        return true;

    }


    /* Approve and then communicate the approved contract in a single tx */

    function approveAndCall(address _spender, uint256 _value, bytes _extraData)

        returns (bool success) {    

        tokenRecipient spender = tokenRecipient(_spender);

        if (approve(_spender, _value)) {

            spender.receiveApproval(msg.sender, _value, this, _extraData);

            return true;

        }

    }


    /* A contract attempts to get the coins */

    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {

        if (balanceOf[_from] < _value) throw;                 // Check if the sender has enough

        if (balanceOf[_to] + _value < balanceOf[_to]) throw;  // Check for overflows

        if (_value > allowance[_from][msg.sender]) throw;   // Check allowance

        balanceOf[_from] -= _value;                          // Subtract from the sender

        balanceOf[_to] += _value;                            // Add the same to the recipient

        allowance[_from][msg.sender] -= _value;

        Transfer(_from, _to, _value);

        return true;

    }


    /* This unnamed function is called whenever someone tries to send ether to it */

    function () {

        throw;     // Prevents accidental sending of ether

    }

}


contract MyAdvancedToken is owned, token {


    uint256 public sellPrice;

    uint256 public buyPrice;


    mapping (address => bool) public frozenAccount;


    /* This generates a public event on the blockchain that will notify clients */

    event FrozenFunds(address target, bool frozen);


    /* Initializes contract with initial supply tokens to the creator of the contract */

    function MyAdvancedToken(

        uint256 initialSupply,

        string tokenName,

        uint8 decimalUnits,

        string tokenSymbol

    ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}


    /* Send coins */

    function transfer(address _to, uint256 _value) {

        if (balanceOf[msg.sender] < _value) throw;           // Check if the sender has enough

        if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows

        if (frozenAccount[msg.sender]) throw;                // Check if frozen

        balanceOf[msg.sender] -= _value;                     // Subtract from the sender

        balanceOf[_to] += _value;                            // Add the same to the recipient

        Transfer(msg.sender, _to, _value);                   // Notify anyone listening that this transfer took place

    }



    /* A contract attempts to get the coins */

    function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {

        if (frozenAccount[_from]) throw;                        // Check if frozen            

        if (balanceOf[_from] < _value) throw;                 // Check if the sender has enough

        if (balanceOf[_to] + _value < balanceOf[_to]) throw;  // Check for overflows

        if (_value > allowance[_from][msg.sender]) throw;   // Check allowance

        balanceOf[_from] -= _value;                          // Subtract from the sender

        balanceOf[_to] += _value;                            // Add the same to the recipient

        allowance[_from][msg.sender] -= _value;

        Transfer(_from, _to, _value);

        return true;

    }


    function mintToken(address target, uint256 mintedAmount) onlyOwner {

        balanceOf[target] += mintedAmount;

        totalSupply += mintedAmount;

        Transfer(0, this, mintedAmount);

        Transfer(this, target, mintedAmount);

    }


    function freezeAccount(address target, bool freeze) onlyOwner {

        frozenAccount[target] = freeze;

        FrozenFunds(target, freeze);

    }


    function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {

        sellPrice = newSellPrice;

        buyPrice = newBuyPrice;

    }


    function buy() payable {

        uint amount = msg.value / buyPrice;                // calculates the amount

        if (balanceOf[this] < amount) throw;               // checks if it has enough to sell

        balanceOf[msg.sender] += amount;                   // adds the amount to buyer's balance

        balanceOf[this] -= amount;                         // subtracts amount from seller's balance

        Transfer(this, msg.sender, amount);                // execute an event reflecting the change

    }


    function sell(uint256 amount) {

        if (balanceOf[msg.sender] < amount ) throw;        // checks if the sender has enough to sell

        balanceOf[this] += amount;                         // adds the amount to owner's balance

        balanceOf[msg.sender] -= amount;                   // subtracts the amount from seller's balance

        if (!msg.sender.send(amount * sellPrice)) {        // sends ether to the seller. It's important

            throw;                                         // to do this last to avoid recursion attacks

        } else {

            Transfer(msg.sender, this, amount);            // executes an event reflecting on the change

        }               

    }

}


배포


아래로 스크롤하면 배포에 드는 예상 비용이 표시된다. 원한다면 작은 수수료를 설정하도록 슬라이더를 변경할 수 있지만 가격이 평균 시장 가격보다 너무 낮으면 거래가 성사되는데 더 오래 걸릴 수 있다. 배포를 클릭하고 암호를 입력한다. 몇 초 후에 대시 보드로 리디렉션되고 최신 트랜잭션에 "계약 생성"이라고 표시된다. 누군가가 거래를 선택하기까지 잠깐 기다리면 얼마나 많은 다른 노드가 거래를보고 확인했는지 나타내는 푸른 색 직사각형이 보일 것이다. 확인 사항이 많을수록 코드가 배포되었음을 확신 할 수 있다. 



Admin 페이지 링크를 클릭하면 새로 만든 통화로 원하는 모든 것을 할 수있는 세계에서 가장 간단한 중앙 은행 대시 보드를 이용할 수 있다.

계약서 읽기 아래 왼쪽에는 무료로 계약 정보를 읽을 수있는 모든 옵션과 기능이 있다. 토큰에 소유자가 있으면 여기에 주소가 표시된다. 해당 주소를 복사하여 잔액에 붙여 넣으면 모든 계정의 잔액이 표시된다 (잔액은 토큰이있는 계정 페이지에도 자동으로 표시됨).

오른쪽 계약서에 쓰기에서 어떤 방식으로든 블록 체인을 변경하거나 변경할 수있는 모든 기능을 볼 수 있다. 이것들은 가스를 소비 할 것이다. 새로운 동전을 만들 수있는 계약을 만든 경우 "민트 토큰"이라는 기능이 있어야한다. 그것을 선택한다.



새 통화가 생성 될 주소를 선택한 다음 금액을 입력한다 (소숫점이 2로 설정된 경우 금액 뒤에 2 개의 숫자를 추가하여 정확한 수량을 생성한다). 선택에서 소유자로 설정된 계정을 실행하고 이더 금액을 0으로두고 실행을 누른다.

몇 가지 확인 후 수취인 잔액은 새로운 금액을 반영하도록 업데이트된다. 그러나 수령인 지갑에 자동으로 표시되지 않을 수 있다. 사용자 정의 토큰을 인식하려면 지갑을 수동으로 감시 목록에 추가해야 한다. 토큰 주소를 복사한다 (관리자 페이지에서 사본 주소를 누르면된다). 아직 계약 탭으로 이동하지 않았다면 시계 토큰을 누른 다음 주소를 추가한다. 표시되는 이름, 기호 및 십진수는 최종 사용자가 사용자 정의 할 수 있다. 특히 비슷한 (또는 동일한) 이름을 가진 다른 토큰이있는 경우에 유용합니다. 기본 아이콘은 변경 가능하지 않으므로 토큰을 보내고받을 때 주의해야 한다. 토큰을 모방하지 않으면 실제 거래를 처리 할 수 있습니다.



Posted by 삼스