Contract-Development

“僅供朋友使用”的代幣如何與其他貨幣進行交易?

  • December 26, 2017

我先說我是新手。我正在學習 Solidity 以及智能合約的工作原理。我想做的很簡單:我只想把 MyFriendToken (MFT) 賣給朋友,以換取一些 ETH (1 ETH = 1000 MFT),然後允許他們用這個代幣與其他貨幣或其他代幣交易 (也許通過 EtherDelta)。

以下是關於我的兩個問題的簡單契約(下文詳述),請參閱:

pragma solidity ^0.4.0;
contract ERC20 {
   //here are the same functions defined in the TokenContractFragment
   //https://theethereum.wiki/w/index.php/ERC20_Token_Standard

   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);
   uint public totalSupply = 0;
   mapping(address => uint256) balances;
}

contract MyFriendToken is ERC20{
   string public token_name;
   string public symbol;
   uint8 public decimals;

   address public owner;

   bool purchase_OK = true;

   address friend1 = address(0x123...);
   address friend2 = address(0x456...);
   //.....

   function purchase_ko() {
       if(msg.sender != owner){ throw;}
       purchase_OK = false;
   }

   function purchase_ok()  {
       if(msg.sender != owner){ throw;}
       purchase_OK = true;
   }

   function MyFriendToken(){

       owner = msg.sender;
       token_name = "MyFriendToken";
       symbol = "MFT";
       decimals = 18;
   }

   function kill() {
       if (msg.sender == owner) selfdestruct(owner);
   }

   function() payable {
       if(!purchase_OK){throw;}
       if(msg.sender != friend1 && msg.sender != friend2) {throw;}

       owner.transfer(msg.value);
       uint256 myFriendToken = (msg.value * 1000);
       totalSupply += myFriendToken;
       balances[msg.sender] += myFriendToken;
   }
}

以下是我的問題:

  1. 購買結束後,我的朋友可以在 EtherDelta 上兌換這個代幣嗎?

2)如果我呼叫這個kill()函式,我朋友的餘額會全部失去嗎?

非常感謝。如果這個問題太寬泛或者這不是正確的地方,我會毫無問題地刪除。

1-我認為要將您的令牌添加到 Etherdelta,您需要在https://gitter.im/etherdelta/etherdelta.github.io與他們聯繫

2-如官方文件中所述:

儲存在該地址的乙太幣被發送到指定的目標,然後從狀態中刪除儲存和程式碼

所以你朋友的餘額會失去(你不知道地址 X 的餘額是多少),但全部金額將發送到所有者地址。

引用自:https://ethereum.stackexchange.com/questions/20831