pragma solidity ^0.4.18;

contract Auction {
    event newBid();
    address owner;
    address public leader;
    address public winner;
    string public item;
    uint public leadingBid;

    function Auction(string name, uint price) public {
        owner = msg.sender;
        item = name;
        leadingBid = price;
    }
    function placeBid() payable public{
        if (msg.value > leadingBid) {
            returnPrevBid();
            leader = msg.sender;
            leadingBid = msg.value;
            newBid();
        }
    }
    function returnPrevBid() private{
        if (leader != 0) {
            leader.transfer(leadingBid);
        }
    }
    function endAuction() public {
       if (msg.sender == owner) {
           winner = leader;
           owner.transfer(leadingBid);
       }
   }
}

 

var event = myAuction.newBid(function(error, result){
  if (!error)
    console.log("New bid placed for " + web3.fromWei(myAuction.leadingBid(),"ether") + " Ether from " +  myAuction.leader());
});

 

 

流程:

拍卖猫 10以太币

A 创建拍卖智能合约(cat ,10)

B竞价20(B转账到合约20)

C竞价40(C转账到合约40,并且返还B 20)

A结束拍卖 (合约转账40到A)

相关文章:

  • 2021-12-03
  • 2021-12-26
  • 2021-12-27
  • 2021-04-30
  • 2021-10-29
  • 2021-12-23
  • 2021-04-14
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2021-08-13
  • 2021-12-14
  • 2022-12-23
  • 2021-08-08
相关资源
相似解决方案