1

コンサートチケットを購入するための分散化アプリを作成しようとしています。何らかの理由で、一部 owner.transfer(this.balance) でエラーが発生し続けます。また、Solidity にはバージョンが多すぎるため、自分に最適なものが見つかりません。これで私を助けてください。ありがとうございました

エラー メッセージ

Getting error as Member “balance” not found or not visible after argument-dependent lookup. Use address(this).balance to access address owner.transfer(this.balance)

堅牢性コード

pragma solidity 0.6.6;

contract Event {
    
    address owner;
    uint public tickets;
    string public description;
    string public website;
    uint constant price = 0.01 ether;
    mapping (address => uint) public purchasers;
    
    constructor(uint t,  string memory _description, string memory _webstite) public {
        owner = msg.sender;
        description = _description;
        website = _webstite;
        tickets = t;
    }
    
    // function () payable {
    //     buyTickets(1);
    // }
    
    function buyTickets(uint amount) public payable {
        if (msg.value != (amount * price) || amount > tickets) {
            revert();
        }
        purchasers[msg.sender] += amount;
        tickets -= amount;
        if (tickets == 0) {
            owner.transfer(this.balance);
        }
    }
    
    function refund(uint numTickets)  public {
        if (purchasers[msg.sender] < numTickets) {
            revert();
        }
        
        msg.sender.transfer(numTickets * price);
        purchasers[msg.sender] -= numTickets;
        tickets += numTickets;
    }
    
}

に変更した後owner.transfer(address(this).balance);、別のエラーが発生しました。

[vm] from: 0x5b3...eddc4to: Event.buyTickets(uint256) 0xd91...39138value: 0 weidata: 0x2f3...00001logs: 0hash: 0x030...bbdf1
status  0x0 Transaction mined but execution failed
 transaction hash   0x03045aab3f5d40ebeef4eacedf50ce506edfc2b75c279652839fd74f8e9bbdf1 
 from   0x5b38da6a701c568545dcfcb03fcb875f56beddc4 
 to Event.buyTickets(uint256) 0xd9145cce52d386f254917e481eb44e9943f39138 
 gas    3000000 gas 
 transaction cost   21760 gas 
 execution cost 296 gas 
 hash   0x03045aab3f5d40ebeef4eacedf50ce506edfc2b75c279652839fd74f8e9bbdf1 
 input  0x2f3...00001 
 decoded input  { "uint256 amount": { "_hex": "0x01" } } 
 decoded output {} 
 logs   []  
 value  0 wei 
transact to Event.buyTickets errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
4

1 に答える 1