Solidity
我的 Timelock 合約不會將發佈時間設置在 100000000000 以下
新手來了 能加入社區真的很興奮。
我一直在嘗試編譯一個基本的時間鎖契約。我終於設法部署它,但我只能將發佈時間設置為 100000000000000 秒。我收到此錯誤消息的任何內容。
我嘗試了各種網路,包括主網,但我仍然收到相同的錯誤消息。
我還嘗試將建構子中的 block.timestamp 更改為 +1 和 -1,看看這是否會有所幫助……不高興。
任何建議或幫助將不勝感激。謝謝
PS我正在使用混音
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./SafeERC20.sol"; /** * @dev A token holder contract that will allow a beneficiary to extract the * tokens after a given release time. * * Useful for simple vesting schedules like "advisors get all of their tokens * after 1 year". */ contract TokenTimelock { using SafeERC20 for IERC20; // ERC20 basic token contract being held IERC20 immutable private _token; // beneficiary of tokens after they are released address immutable private _beneficiary; // timestamp when token release is enabled uint256 immutable private _releaseTime; constructor (IERC20 token_, address beneficiary_, uint256 releaseTime_) { // solhint-disable-next-line not-rely-on-time require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time"); _token = token_; _beneficiary = beneficiary_; _releaseTime = releaseTime_; } /** * @return the token being held. */ function token() public view virtual returns (IERC20) { return _token; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view virtual returns (address) { return _beneficiary; } /** * @return the time when the tokens are released. */ function releaseTime() public view virtual returns (uint256) { return _releaseTime; } /** * @notice Transfers tokens held by timelock to beneficiary. */ function release() public virtual { // solhint-disable-next-line not-rely-on-time require(block.timestamp >= releaseTime(), "TokenTimelock: current time is before release time"); uint256 amount = token().balanceOf(address(this)); require(amount > 0, "TokenTimelock: no tokens to release"); token().safeTransfer(beneficiary(), amount); } }
根據Solidity Docs
block.timestamp
,返回目前區塊自紀元以來的秒數。這意味著自 1970 年 1 月 1 日以來經過了多少秒。所以,如果你想在 1 年後釋放你的令牌,你必須在目前時間戳上增加 1 年並傳遞該值。
您可以手動將
31556926 * YEARS
秒數添加到今天的時間戳,也可以使用應用程序來製作。對於您的錯誤,我認為發生此錯誤是因為
100000000000000
seconds 大約是300 萬年,這是一個巨大的數字。