如何求解ParserError:预期的PRAGMA,进口指令或合同/接口/库/struct/enum/constant/constant/function/错误定义。在固体中

发布于 2025-02-01 02:40:26 字数 2495 浏览 4 评论 0原文

我在运行拍卖代码方面非常成功,直到按下一些钥匙,现在出现了此错误,我无法弄清楚为什么此错误显示

ParserError:预期的PRAGMA,IMPOCTIVER或CONTERTIVER/CONTERTIVER/interface/Interface/Library/struct/enum /常数/函数/错误定义。

错误是在第79行中,其中该事件被声明了,

我可能会检查我的pragma声明其pragma solidity> = 0.7.0< 0.9.0; 0.9.0;



pragma solidity >=0.7.0 <0.9.0;

contract Auction {
address payable internal auction_owner; 
uint256 public auction_start; 
uint256 public auction_end; 
uint256 public highestBid;
address public highestBidder;

enum auction_state {
CANCELLED, STARTED,ENDED
}
address[] bidders;

mapping(address => uint) public bids; 

auction_state public STATE;



modifier an_ongoing_auction() { require(block.timestamp <= auction_end);
_;
}

modifier only_owner() { require(msg.sender == auction_owner);
_;
}

function MyAuction (uint _biddingTime, address payable  _owner) public {
     auction_owner = _owner; 
     auction_start = block.timestamp;
    auction_end = auction_start + _biddingTime* 1 minutes;
     STATE = auction_state.STARTED;
    if (block.timestamp>auction_end){
        STATE=auction_state.ENDED;
        auction_owner.transfer(highestBid);
        bids[highestBidder]=0;
        
    } 

}

function bid() public payable an_ongoing_auction returns (bool){ 

    require(bids[msg.sender] + msg.value > highestBid, "can't bid, Make a higher Bid" );

    highestBidder = msg.sender; 
    highestBid = msg.value; 
    bidders.push(msg.sender);
    bids[msg.sender] = bids[msg.sender] + msg.value; 
    emit BidEvent(highestBidder, highestBid);
    return true; 
    }
    
}

function withdraw() public payable returns (bool){
   // address payable rec = msg.sender;
    require(block.timestamp > auction_end , "can't withdraw, Auction is still open");
    uint amount= bids[msg.sender];
    bids[msg.sender] = 0; 
    payable(msg.sender).transfer(amount); 
    emit WithdrawalEvent(msg.sender, amount);
    return true;
}
function cancel_auction() only_owner an_ongoing_auction public returns (bool) {
     STATE = auction_state.CANCELLED;
    emit CanceledEvent("Auction Cancelled", block.timestamp,highestBid); 
    return true;
}
function time_remain() an_ongoing_auction public view returns (uint256){
uint256 timeleft= auction_end - block.timestamp;
return timeleft; 

}

event BidEvent(address highestBidder, uint256 highestBid); 

event WithdrawalEvent(address withdrawer, uint256 amount);

event CanceledEvent(string message, uint256 time, uint256 highestBid);
}

i was pretty successful in running my auction code until maybe some keys were pressed and now this error started showing, I am unable to figure out why this error is showing

ParserError: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function/error definition.

the error is in line 79 where the event is declared

what could it possibly be I check my pragma statement its pragma solidity >=0.7.0 <0.9.0;



pragma solidity >=0.7.0 <0.9.0;

contract Auction {
address payable internal auction_owner; 
uint256 public auction_start; 
uint256 public auction_end; 
uint256 public highestBid;
address public highestBidder;

enum auction_state {
CANCELLED, STARTED,ENDED
}
address[] bidders;

mapping(address => uint) public bids; 

auction_state public STATE;



modifier an_ongoing_auction() { require(block.timestamp <= auction_end);
_;
}

modifier only_owner() { require(msg.sender == auction_owner);
_;
}

function MyAuction (uint _biddingTime, address payable  _owner) public {
     auction_owner = _owner; 
     auction_start = block.timestamp;
    auction_end = auction_start + _biddingTime* 1 minutes;
     STATE = auction_state.STARTED;
    if (block.timestamp>auction_end){
        STATE=auction_state.ENDED;
        auction_owner.transfer(highestBid);
        bids[highestBidder]=0;
        
    } 

}

function bid() public payable an_ongoing_auction returns (bool){ 

    require(bids[msg.sender] + msg.value > highestBid, "can't bid, Make a higher Bid" );

    highestBidder = msg.sender; 
    highestBid = msg.value; 
    bidders.push(msg.sender);
    bids[msg.sender] = bids[msg.sender] + msg.value; 
    emit BidEvent(highestBidder, highestBid);
    return true; 
    }
    
}

function withdraw() public payable returns (bool){
   // address payable rec = msg.sender;
    require(block.timestamp > auction_end , "can't withdraw, Auction is still open");
    uint amount= bids[msg.sender];
    bids[msg.sender] = 0; 
    payable(msg.sender).transfer(amount); 
    emit WithdrawalEvent(msg.sender, amount);
    return true;
}
function cancel_auction() only_owner an_ongoing_auction public returns (bool) {
     STATE = auction_state.CANCELLED;
    emit CanceledEvent("Auction Cancelled", block.timestamp,highestBid); 
    return true;
}
function time_remain() an_ongoing_auction public view returns (uint256){
uint256 timeleft= auction_end - block.timestamp;
return timeleft; 

}

event BidEvent(address highestBidder, uint256 highestBid); 

event WithdrawalEvent(address withdrawer, uint256 amount);

event CanceledEvent(string message, uint256 time, uint256 highestBid);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与他有关 2025-02-08 02:40:26

代码的快速副本和粘贴到混音中,表明您在投标功能后的关闭式设备放错了。如果您删除了放错位置的闭合支架,则您的代码应正确编译。

A quick copy and paste of your code to remix shows that you have a misplaced closing brace after the bid function. If you remove that misplaced closing brace, your code should compile correctly.

相权↑美人 2025-02-08 02:40:26

您需要清洁和造型代码,以便很容易找到错误。
坚固性需要指定SPDX许可以避免此处的警告是:代码应为:


//SPDX-License-Identifier: Unlicense
pragma solidity >=0.7.0 <0.9.0;

contract Auction {
address payable internal auction_owner; 
uint256 public auction_start; 
uint256 public auction_end; 
uint256 public highestBid;
address public highestBidder;

enum auction_state {
CANCELLED, STARTED,ENDED
}
address[] bidders;

mapping(address => uint) public bids; 

auction_state public STATE;



modifier an_ongoing_auction() { require(block.timestamp <= auction_end);
_;
}

modifier only_owner() { require(msg.sender == auction_owner);
_;
}

function MyAuction (uint _biddingTime, address payable  _owner) public {
     auction_owner = _owner; 
     auction_start = block.timestamp;
    auction_end = auction_start + _biddingTime* 1 minutes;
     STATE = auction_state.STARTED;
    if (block.timestamp>auction_end){
        STATE=auction_state.ENDED;
        auction_owner.transfer(highestBid);
        bids[highestBidder]=0;
        
    } 

}

function bid() public payable an_ongoing_auction returns (bool){ 

    require(bids[msg.sender] + msg.value > highestBid, "can't bid, Make a higher Bid" );

    highestBidder = msg.sender; 
    highestBid = msg.value; 
    bidders.push(msg.sender);
    bids[msg.sender] = bids[msg.sender] + msg.value; 
    emit BidEvent(highestBidder, highestBid);
    return true; 
    }

    
function withdraw() public payable returns (bool){
   // address payable rec = msg.sender;
    require(block.timestamp > auction_end , "can't withdraw, Auction is still open");
    uint amount= bids[msg.sender];
    bids[msg.sender] = 0; 
    payable(msg.sender).transfer(amount); 
    emit WithdrawalEvent(msg.sender, amount);
    return true;
}
function cancel_auction() only_owner an_ongoing_auction public returns (bool) {
     STATE = auction_state.CANCELLED;
    emit CanceledEvent("Auction Cancelled", block.timestamp,highestBid); 
    return true;
}
function time_remain() an_ongoing_auction public view returns (uint256){
uint256 timeleft= auction_end - block.timestamp;
return timeleft; 

}

event BidEvent(address highestBidder, uint256 highestBid); 

event WithdrawalEvent(address withdrawer, uint256 amount);

event CanceledEvent(string message, uint256 time, uint256 highestBid);
    
}

You need to clean and styling your code so that it's easy to find the mistake.
and solidity will need to specify the SPDX License to avoided the warning as well here is the code should be:


//SPDX-License-Identifier: Unlicense
pragma solidity >=0.7.0 <0.9.0;

contract Auction {
address payable internal auction_owner; 
uint256 public auction_start; 
uint256 public auction_end; 
uint256 public highestBid;
address public highestBidder;

enum auction_state {
CANCELLED, STARTED,ENDED
}
address[] bidders;

mapping(address => uint) public bids; 

auction_state public STATE;



modifier an_ongoing_auction() { require(block.timestamp <= auction_end);
_;
}

modifier only_owner() { require(msg.sender == auction_owner);
_;
}

function MyAuction (uint _biddingTime, address payable  _owner) public {
     auction_owner = _owner; 
     auction_start = block.timestamp;
    auction_end = auction_start + _biddingTime* 1 minutes;
     STATE = auction_state.STARTED;
    if (block.timestamp>auction_end){
        STATE=auction_state.ENDED;
        auction_owner.transfer(highestBid);
        bids[highestBidder]=0;
        
    } 

}

function bid() public payable an_ongoing_auction returns (bool){ 

    require(bids[msg.sender] + msg.value > highestBid, "can't bid, Make a higher Bid" );

    highestBidder = msg.sender; 
    highestBid = msg.value; 
    bidders.push(msg.sender);
    bids[msg.sender] = bids[msg.sender] + msg.value; 
    emit BidEvent(highestBidder, highestBid);
    return true; 
    }

    
function withdraw() public payable returns (bool){
   // address payable rec = msg.sender;
    require(block.timestamp > auction_end , "can't withdraw, Auction is still open");
    uint amount= bids[msg.sender];
    bids[msg.sender] = 0; 
    payable(msg.sender).transfer(amount); 
    emit WithdrawalEvent(msg.sender, amount);
    return true;
}
function cancel_auction() only_owner an_ongoing_auction public returns (bool) {
     STATE = auction_state.CANCELLED;
    emit CanceledEvent("Auction Cancelled", block.timestamp,highestBid); 
    return true;
}
function time_remain() an_ongoing_auction public view returns (uint256){
uint256 timeleft= auction_end - block.timestamp;
return timeleft; 

}

event BidEvent(address highestBidder, uint256 highestBid); 

event WithdrawalEvent(address withdrawer, uint256 amount);

event CanceledEvent(string message, uint256 time, uint256 highestBid);
    
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文