I am currently developing a dApp with Drizzle on top of ReactJS.
My project consists of, basically, 8 .sol files. 4 of them are just abstract contracts that include the functions, structs etc. for easier human readability and the other 4 hold the logic of the contracts.
My main issue is that some of the contracts must be unique to every user - The user should be able to create a new instance of a contract for as many times as they want.
I have tried to do it by having one more contract that will create the new instances, like this:
pragma solidity ^0.5.10;
import './ContractToBeInstanced.sol';
contract newInstance {
function newInstanceFunc(address _address) public returns(address) {
ContractToBeInstanced T = new ContractToBeInstanced(_address);
return T.getAddress(); //returns the address(this) of the contract
}
}
and in the ContractToBeInstanced.sol I have a constructor that it sets the owner of the new instance:
constructor(address _owner) public {
owner = _owner;
getAddress(); //it also calls the getAddress() to return the address to the parent function
}
So, my main issues are:
- How do I create that instance through Drizzle? For example, I have tried:
<Button onClick={ () => this.contracts.newInstance.methods.newInstanceFunc.cacheSend(contractConfig.contractName, {from: this.currentAccount})) }>New Instance</Button>
Metamask opens, I run the transaction, it gets valid and then, nothing. I also can not see the new (instance) of the contract in the Contracts menu in Ganache and there is no output in the transactions that returns the new contract's address. Is all this normal?
- When the new instance of the contract will be created, how will I be able to access it again in a later manner of time? I suspect that I will have to use some kind of IPFS or look through the past transactions? I know that this is a very simple question, but I am not really sure yet.
What I would also like to note, is that my truffle's migration files only do a:
deployer.deploy(ContractA).then( () => deployer.deploy(ContractB)...);
which I think is wrong and that the Migrations.sol is untouched.