@SKYBITDev3 I made it much more simplier. I comment out create3 factory and just deploy transparent proxy contract. I overwrite the _checkOwner function to see what is going on.
After i deploy, i called the transferOwnership function its passed even i have the transferownership event, when i call owner() function i can see my newOwner is the owner. But when i try to call function with onlyOwner modifier function i am getting same error "Ownable: caller is not the owner".
On the console i can see the owner still the old one. What is going on?
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "hardhat/console.sol";
contract Box is Initializable, OwnableUpgradeable {
uint256 public value;
function _checkOwner() internal view override(OwnableUpgradeable) {
console.log("msgSender: ", _msgSender());
console.log("owner: ", owner());
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function initialize(uint256 _value, address _owner) public initializer {
__Ownable_init();
_transferOwnership(msg.sender);
value = _value;
console.log(_owner);
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public onlyOwner {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
}