Hi, I’m playing around with ZeppelinOS and I’m trying do use it with simple contract factory (using App contract).
I have MyContract.sol that works as contract factory and creates NewContract.sol
MyContract.sol:
pragma solidity ^0.4.24;
import "zos-lib/contracts/Initializable.sol";
import "zos-lib/contracts/application/App.sol";
contract MyContract is Initializable {
App private app;
function initialize(App _app) initializer public {
app = _app;
}
function createNewContract() public returns(address) {
return app.create("zos-fact", "NewContract", '0x69E3a4A7Ff6C1AEff4B096E4A6CF4d094D195a5A');
}
}
NewContarct.sol:
pragma solidity ^0.4.24;
import "zos-lib/contracts/Initializable.sol";
contract NewContract is Initializable {
uint256 public x;
function initialize() initializer public {
x = 10;
}
function setNumber(uint256 _x) public returns (bool) {
x = _x;
}
}
I have published my project to use App as admin of the proxies.
When I try to create new upgradeable contract on the fly I got error:
truffle(ganache)> myContract.createNewContract()
Error: VM Exception while processing transaction: revert
Do you have any ideas what a problem might be? I would be grateful for your advices
Hmm, I’m not the most informed on ZeppelinOS so maybe @spalladino can help out? We’re at ETHDenver right now so apologies if it takes a moment for him to respond
Hey @paulinablaszk! Have you run zos add NewContract and zos push on the corresponding network, so the App has registered the NewContract implementation? Does it work fine if you run zos create NewContract directly? And if all of the above fails, can you upload your project somewhere, so we can help in troubleshooting it? Thanks!
Hey @paulinablaszk! The issue that is causing the REVERT is in https://github.com/paulinablaszk/zos-fact/blob/master/contracts/MyContract.sol#L14. There, App#create is being called with 3 params (package name, contract name, and an admin address), which corresponds to the App interface in v2.2. However, in your project you have v2.1 as a dependency, where the App interface is slightly different. In 2.1, create takes 3 params: package name, contract name, and the data that will be forwarded to the contract upon initialization. The admin address you are supplying is actually being parsed as that data, is sent to the contract, and thus fails.
TL;DR: You should either upgrade to zos and zos-lib v2.2 (recommended) or change the call to create by removing the last 0x69E3a4A7Ff6C1AEff4B096E4A6CF4d094D195a5A parameter.
I have one more question connected with this topic. I upgraded my zos and zos-lib to 2.2 but now MyContract.sol does not compile because of the create function. I am getting an error:
TypeError: Wrong argument count for the function call: 3 arguments given but expected 4.
Is it correct behavior when the 4th param data is optional?
Update:
I tried to put as data first 4 bytes of the Keccak hash of the signature initialize() and function app.create() has returned some address(?) but NewContract wasn’t deployed to the network truffle(ganache)> contract.methods.createNewContract("zos-fact", "NewContract", "0x69E3a4A7Ff6C1AEff4B096E4A6CF4d094D195a5A", "0x8129fc1c").call() '0xD6C3A17f91D873352E882315269c1183278a96Ae'
Since I already initialized my project with zos init TheFaustFlick, could you please point to me the documentation on how do I properly upgrade zos and zos.lib to the latest version?
I just used both commands and they worked perfectly. However, the content of my zos.json file remains the same, is that ok? I am new on this, hence my basic questions…
@jaureguino No problem, nice to help
In zos.json you have:
The documentation says: The field zosversion indicates the major version of ZeppelinOS you are using
So it doesn't change because it can by only "1" or "2" (without detailed versions).
and "openzeppelin-eth": "^2.1.3" is OpenZeppelin EVM package - it is not the same as zos-lib. You should find info about zos-lib version in your package.json file.
How did you do that? After linking the openzeppelin-eth evm package, my app instance does not register the implementation addresses and thus i cannot use app.create("openzeppelin-eth", "StandaloneERC20", msg.sender, abi.encode(...))
Hi @imbenwolf, did you use: zos push --deploy-dependencies? (–deploy dependencies is needed when you use openzeppelin-eth on your local network)
and then zos publish ?
You can also check new example on zos github: Creating instances from solidity. It was very helpful for me when I was trying to create an upgradeable smart contract using factory