I am getting generic error every time I try to modify the code. I am passing byte32
value as "0xabcd"
and address value as "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
in Setaddress
function.
The error is as below:
"transact to EternalStorage.setAddress errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information."
Below is my code
pragma solidity ^0.4.17;
contract EternalStorage {
address owner = msg.sender;
address latestVersion;
mapping(bytes32 => uint) uIntStorage;
mapping(bytes32 => address) addressStorage;
modifier onlyLatestVersion() {
require(msg.sender == latestVersion);
_;
}
function upgradeVersion(address _newVersion) public {
require(msg.sender == owner);
latestVersion = _newVersion;
}
// *** Getter Methods ***
function getUint(bytes32 _key) external view returns(uint) {
return uIntStorage[_key];
}
function getAddress(bytes32 _key) external view returns(address) {
return addressStorage[_key];
}
// *** Setter Methods ***
function setUint(bytes32 _key, uint _value) onlyLatestVersion external {
uIntStorage[_key] = _value;
}
function setAddress(bytes32 _key, address _value) onlyLatestVersion external payable{
addressStorage[_key] = _value;
}
// *** Delete Methods ***
function deleteUint(bytes32 _key) onlyLatestVersion external {
delete uIntStorage[_key];
}
function deleteAddress(bytes32 _key) onlyLatestVersion external {
delete addressStorage[_key];
}
}
The error message says that the transaction to setAddress()
reverted:
transact to EternalStorage.setAddress errored: VM error: revert.
There is only one requre()
statement in setAddress()
, in onlyLatestVersion()
:
require(msg.sender == latestVersion);
So it's virtually certain that the sender of the transaction ( msg.sender
) is not set to latestVersion
. That means you either need to:
latestVersion
, or... latestVersion
using the contract's function upgradeVersion()
, so that it matches your transaction sender.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.