Hi,
I'm working on a factory and I'm starting to test "@openzeppelin/contracts/proxy/Clones.sol".
My SC is the following one:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/proxy/Clones.sol";
import "./VotingHandler.sol";
contract VotingFactory {
address immutable votingHandlerImplementation;
mapping(bytes32 => address) public deployedInstances;
event NewInstance(address indexed _from, address indexed _contract, bytes32 indexed _votingId);
constructor() {
votingHandlerImplementation = address(new VotingHandler());
}
function b_A6Q() external {
bytes32 votingId = keccak256(abi.encodePacked(msg.sender, address(this), block.timestamp));
require(deployedInstances[votingId] == address(0), "Instance already exists");
address clone = Clones.cloneDeterministic(votingHandlerImplementation, votingId);
VotingHandler(clone).transferOwnership(msg.sender); // this line isn't working
emit NewInstance(msg.sender, clone, votingId);
}
}
VotingHandler is using "@openzeppelin/contracts/access/Ownable.sol"; and don't have a constructor:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
contract VotingHandler is Ownable, Pausable {
...
}
VotingHandler is working perfectly when it's not Clone.
When I want to call "b_A6Q()" from VotingFactory, the line "VotingHandler(clone).transferOwnership(msg.sender);" isn't working and I get a revert with this error: "Reason provided by the contract: "Ownable: caller is not the owner"."
I've followed the following video: https://www.youtube.com/watch?v=3Mw-pMmJ7TA, but I guess I haven't understand something...
How can I properly transferOwnership of the new instance to msg.sender?