0

I try to use the Upgradable Contract and transferOwnership but i have an issue.

What i want to do :

  • vers1 of my contract
  • deployProxy vers1 (with user1 : become the owner)
  • deployed
  • transferOwnership with user1 to another user2 (works)
  • vers2 of my contract (for testing no code update of the contract, deploy the same)
  • upgradeProxy to vers2 (with user2 because he is the new owner) << issue

See my unit test below :

console.log('Before Change, Owner: ', await contract.owner()); // show user1 address
const transaction = await contract.transferOwnership(user2.address); // transfer to user2
const receipt = await transaction.wait();
console.log('After change, Owner: ', await contract.owner()); // show user2 address
const factory = await ethers.getContractFactory("MyContract", user2); // use user2 because is the new owner
const upgraded = await upgrades.upgradeProxy(contract.address, factory);

Always have : reverted with reason string 'Ownable: caller is not the owner' But the contract.owner() show the new user2

I think there is issue between implementation, proxy but i d'ont find the issue. Any idea ?

1 Answer 1

0

Without seeing the full contracts I can't tell whats going on but my guess would be to add ", {from: user2}" to your upgradeProxy call

2
  • Thanks, i tried but same issue. The contract is almost empty ` contract MyContract is ERC721Upgradeable, AccessControlUpgradeable, OwnableUpgradeable, EIP712Upgradeable{ mapping (address => uint256) pendingWithdrawals; mapping (uint256 => uint256) minted; function initialize() initializer public { __ERC721_init("Test", "test"); __ERC721URIStorage_init(); __AccessControl_init(); __Ownable_init(); } `
    – Cryptopowa
    Nov 28, 2022 at 7:52
  • this issue come from this method in "Ownable" : function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } owner() => user2 (the good new owner) _msgSender() => user1 (the old owner)
    – Cryptopowa
    Nov 28, 2022 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.