1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Level 15. Naught Coin(The Ethernaut)

Last updated at Posted at 2018-05-08

「The Ethernaut by Zeppelin Level 15. Naught Coin」を翻訳してみました(CryptoZombiesのように?)

原文はこちら

https://ethernaut.zeppelin.solutions/
15. Naught Coinをクリック

15. Naught Coin

難易度 5/6
NaughtコインはERC20トークンであり、お主は既にすべてのトークンを保持している。
しかし、Naughtコインは10年間のロックアウト期間後に、転送が可能であることを理解しなければならない、お主はいつでも自由にNaughtコインを転送できるようする為、別のアドレスを取得する方法を把握しているかな?
このレベルのクリア条件はお主のトークン残高を0にすることである。

回答の助けになるヒント
  • ERC20の仕様について
  • OpenZeppelinのコードベースについて

ソースコード

pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/token/ERC20/StandardToken.sol';

 contract NaughtCoin is StandardToken {

  string public constant name = 'NaughtCoin';
  string public constant symbol = '0x0';
  uint public constant decimals = 18;
  uint public timeLock = now + 10 years;
  uint public INITIAL_SUPPLY = 1000000 * (10 ** decimals);
  address public player;

  function NaughtCoin(address _player) public {
    player = _player;
    totalSupply_ = INITIAL_SUPPLY;
    balances[player] = INITIAL_SUPPLY;
    Transfer(0x0, player, INITIAL_SUPPLY);
  }
  
  function transfer(address _to, uint256 _value) lockTokens public returns(bool) {
    super.transfer(_to, _value);
  }

  // Prevent the initial owner from transferring tokens until the timelock has passed
  modifier lockTokens() {
    if (msg.sender == player) {
      require(now > timeLock);
      if (now < timeLock) {
        _;
      }
    } else {
     _;
    }
  } 
} 
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?