0
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 1. Fallback (The Ethernaut)

Last updated at Posted at 2018-04-25

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

原文はこちら

  1. Fallbackをクリック

1. フォールバック

難易度 1/6
下記のコントラクトコードをよく見るのだ。
このレベルのクリア条件は

  1. スマートコントラクトのオーナーを自分自身のアドレスに変更する
  2. コントラクトの残高を0にする
回答の助けになるヒント
  • ABI(Application Binary Interface)とやり取りするときにether を送る方法
  • ABIの外部にether を送る方法
  • wei/etherとの間で変換する(help()コマンドで参照)
  • フォールバックメソッドについて

ソースコード

pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/ownership/Ownable.sol';

contract Fallback is Ownable {

  mapping(address => uint) public contributions;

  function Fallback() public {
    contributions[msg.sender] = 1000 * (1 ether);
  }

  function contribute() public payable {
    require(msg.value < 0.001 ether);
    contributions[msg.sender] += msg.value;
    if(contributions[msg.sender] > contributions[owner]) {
      owner = msg.sender;
    }
  }

  function getContribution() public view returns (uint) {
    return contributions[msg.sender];
  }

  function withdraw() public onlyOwner {
    owner.transfer(this.balance);
  }

  function() payable public {
    require(msg.value > 0 && contributions[msg.sender] > 0);
    owner = msg.sender;
  }
}
0
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
0
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?