坚固 - 更新已部署合同中的时间戳值

发布于 2025-01-31 15:19:15 字数 724 浏览 3 评论 0原文

我有一份拍卖合同,应该说20分钟。

为了促进这一点,我有一个AuctionEndTime变量,我在构造函数中初始化,如下所示:

  auctionEndTime = block.timestamp + 20 minutes;

但是,如果我想通过添加AhauctionEnd Time来更新还有一些额外的时间?

Ahaucterendtime变量的额外分钟的价值,如下:

function changeAuctionEndTime(uint extraTimeAmount) public {
    require(msg.sender == contractOwner, "ONLY THE CONTRACT's OWNER CAN CALL THIS FUNCTION!");  
    auctionEndTime += newEndTime minutes;  
}

我写了一个

Expected ';' but got 'minutes'

函数,让我通过我想添加到我的 单词分钟下的红线。 因此,显然不喜欢那里的东西。 (并注意此错误立即出现 - 作为IN,这不像我编译并获取此错误,而是我什至无法编译并运行代码。)

那是怎么回事?我该如何解决?

I have an auction contract that's supposed to run for say 20 minutes.

To facilitate this, I have an auctionEndTime variable which I initialize in the constructor as follows:

  auctionEndTime = block.timestamp + 20 minutes;

But what if I wanted to update the auctionEndTime by adding some additional minutes to it?

I wrote a function that lets me pass in the value of the additional minutes I'd wanna add to my auctionEndTime variable, as follows:

function changeAuctionEndTime(uint extraTimeAmount) public {
    require(msg.sender == contractOwner, "ONLY THE CONTRACT's OWNER CAN CALL THIS FUNCTION!");  
    auctionEndTime += newEndTime minutes;  
}

But this immediately gives me the following error:

Expected ';' but got 'minutes'

And it's giving me a squiggly red line under the word minutes.
So it's clearly not liking something right there. (And note that this error appears immediately - as-in, it's not like I compile and get this error, it's that I can't even compile and run the code as is.)

So what's going on? How do I fix this?

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

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

发布评论

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

评论(1

一花一树开 2025-02-07 15:19:15
  1. 您的变量是extratimeamount而不是newendtime
  2. seconds分钟小时Weeks Weeks 之后文字数字可用于指定时间单位。 (来自官方文档)。
  3. 因此,您需要做extratimeamount * 1分钟而不是extratimeamount分钟

这是您的代码,可以根据上述点工作 -

function changeAuctionEndTime(uint extraTimeAmount) public {
    require(msg.sender == contractOwner, "ONLY THE CONTRACT's OWNER CAN CALL THIS FUNCTION!");  
    auctionEndTime += extraTimeAmount * 1 minutes;  
}

  1. Your variable is extraTimeAmount and not newEndTime.
  2. Suffixes like seconds, minutes, hours, days and weeks after literal numbers can be used to specify units of time. (From official docs).
  3. So you need to do extraTimeAmount * 1 minutes instead of extraTimeAmount minutes.

Here is your piece of code that will work as per above points -

function changeAuctionEndTime(uint extraTimeAmount) public {
    require(msg.sender == contractOwner, "ONLY THE CONTRACT's OWNER CAN CALL THIS FUNCTION!");  
    auctionEndTime += extraTimeAmount * 1 minutes;  
}

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