簡體   English   中英

錯誤:交易已恢復為初始state

[英]Error :The transaction has been reverted to the initial state

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

contract modifierExample{

    address admin ;

    constructor() public {
        admin == msg.sender;
    }

    modifier isAdmin {
        require(admin == msg.sender,"you are not the owner");
        _;
    }

    modifier isExp(uint exp) {
        if(exp >= 5)
        _;
        else
        revert("you are not experienced");
    }

    struct employeeDetails{
        uint iD;
        string name;
        uint age;
    }

    mapping (uint => employeeDetails) getDetailsByNum;

    function enterDetails(uint number,
                          uint iD,
                          string memory name,
                          uint age) public isAdmin isExp(5) {
                              employeeDetails memory EmployeeDetails = employeeDetails(iD,name,age);
                              getDetailsByNum[number] = EmployeeDetails;
                          }

    function getDetailsByNumber(uint number) public view returns (employeeDetails memory) {
        return getDetailsByNum[number];
    }

}

為什么我會遇到這個錯誤????? 輸入詳細信息后,它向我拋出一個錯誤,如下所述

處理 modifierExample.enterDetails 錯誤:VM 錯誤:還原。

revert 交易已經恢復到最初的state。合約提供的原因:“你不是所有者”。 調試事務以獲取更多信息。

您的enterDetails() function 使用了isAdmin修飾符。

根據以下代碼,任何使用isAdmin修飾符的 function 只能由部署合約的地址執行。

address admin ;

constructor() public {
    admin == msg.sender;
}

modifier isAdmin {
    require(admin == msg.sender,"you are not the owner");
    _;
}

您收到了you are not the owner錯誤,因為您正嘗試從admin以外的其他地址執行 function 。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM