Hi, I have a factory contract from which I can create another product contract. It uses App.sol so that the product contract can also be upgradeable later following this: https://docs.openzeppelin.com/upgrades/2.8/creating-upgradeable-from-solidity
The process is:
- I deployed the Factory contract using Oz cli: oz deploy-> upgradeable
- I then created an instance of the Product contract from inside Factory through : oz send-tx and can interact with it programmatically with a js script.
- Now, if I make some changes in the Product contract, and run "oz-upgrade" to upgrade the Factory contract, will my Product contract be upgraded too? (coz that is what I want to do, right?)
I tried to do this and sadly, I was unable to do so..
Or do I have to upgrade the product contract programmatically separately?
If so... then can you provide me with an example of how I can do that?
I've checked this one : https://docs.openzeppelin.com/learn/upgrading-smart-contracts#:~:text=Upgrading%20Contracts%20Programmatically,interaction%2C%20and%20source%20code%20verification.
But still, I wasn't clear as to how or if i can follow the same pattern for my Product contract that's already been deployed using Factory contract...
And btw, how's this solution conducted in steps?
How can the network.json be modified as per this?
1 Like
Hi @asmeedhungana,
We can use a factory to deploy upgradeable contracts. We can also make the factory upgradeable, though upgrading the factory only changes the factory and not any of the already created contracts by the factory.
To upgrade contracts deployed by the factory, the admin of each contract would need to upgrade the contract, we could do this programmatically. As the contracts werenât deployed using the CLI we wouldnât be able to use the CLI for this. I wouldnât recommend trying to manually modify the CLI config to be able to upgrade using the CLI.
I suggest not using App.sol: When should I use App.sol in my project?
1 Like
Can you tell me what I'll need to use if I don't use App.sol in my project to create upgradeable product instances from the upgradeable factory contract?
And can I get a pre-implemented example for what you're suggesting please? or anywhere I can look for them...
I am just lost... I've checked so many places but haven't been able to figure our what to do exactly...
1 Like
And can you tell me how I can do this if I don't use App.sol?
Is there a pre-implemented example for ProxyFactory that you can provide me with, please?
1 Like
Hi @asmeedhungana,
I had a quick look and donât appear to have an example unfortunately.
If you have a factory deploying using App.sol I would use that for testing and I can see what I can find later in the week regards an example of deploying a proxy contract via a factory.
1 Like
Shall I provide my factory contract code? Is that what you mean?
1 Like
Hi @asmeedhungana,
I need to come back to you with an example later in the week.
1 Like
pragma solidity >=0.5.0;
import â@openzeppelin/upgrades/contracts/Initializable.solâ;
import â@openzeppelin/upgrades/contracts/application/App.solâ;
// import â@openzeppelin/upgrades/contracts/upgradeability/AdminUpgradeabilityProxy.solâ;
import â./Token.solâ;
contract TokenFactory is Initializable {
App private app;
event TokenCreated(address);
function initialize (App _app) public initializer {
app = _app;
}
address[] public activeTokens; //track list of campaigns running
mapping (address => address) public tokenManager; // token addr to manager addr
mapping (address => address) myToken; //tokenMgr to his token's address
address public admin;
mapping (string => bool) private tokenExists;
function createToken(string memory _name, string memory _symbol, uint256 _mintAmount) public {
// address newToken = address(new Token(_name, _symbol, _mintAmount));
require(!tokenExists[_name], "name already taken!!");
admin = msg.sender;
address newToken = address (
app.create("tokenproject",
"Token",
admin,
abi.encodeWithSelector(
bytes4(keccak256(bytes("initializeChild(string,string,uint256)"))),
_name,
_symbol,
_mintAmount
)
)
);
activeTokens.push(newToken);
tokenManager[newToken] = msg.sender;
myToken[msg.sender] = newToken;
tokenExists[_name] = true;
emit TokenCreated(newToken);
}
function getActiveTokens() public view returns (address[] memory) {
return activeTokens;
}
function getManager(address _token) public view returns (address) {
return tokenManager[_token];
}
function getMyToken() public view returns (address) {
return myToken[msg.sender];
}
}
Thank you as always⌠looking forward to getting it soon!
What I want to do is to be able to upgrade the Token contracts that I create from the TokenFactory contract. I can interact with them via manual scripts but havenât been able to find a way to upgrade them.
Hey @abcoathup!
I wanted to remind you that Iâm waiting (i know youâre a busy man, so )âŚ
Were you able to make or find one example?
1 Like
Hi @asmeedhungana,
There isnât a ready made example. I have started to create one but ran into an issue, so it will be next week before I get to look at it again unfortunately. (It is Friday afternoon in Melbourne).
1 Like
Ohh sure! You can do it accordingly!
And⌠have a happy weekend!
1 Like
hey @abcoathup,
any progress in here ?
1 Like