Let's say now we have this:
Fatory.sol:
import "./Contract.sol";
contract Factory {
address[] newContracts;
function createContract (bytes32 name) {
address newContract = new Contract(name);
newContracts.push(newContract);
}
}
Contract.sol:
contract Contract {
bytes32 public Name;
function Contract (bytes32 name) {
Name = name;
}
}
then we can deploy this two contracts like this:
2_deploy_contract.js:
var Factory = artifacts.require("./Factory.sol");
var Contract= artifacts.require("./Contract.sol")
module.exports = function(deployer){
deployer.deploy(Factory);
deployer.deploy(Contract,['Contract 1"]);
}
then we deploy this two contracts by : truffle migrate
after that we can interact with the smart contract through web3js, for simplity, I just call:
var factory = contract(factory_artifacts);
factory.deployerd().then(function(inst){
inst.createContract('Contract 2", {from: web3.eth.accounts[0]});
});
1). what's the difference when I call "deployer.deploy(Contract,['Contract 1"]);" through truffle migrate and " inst.createContract('Contract 2", {from: web3.eth.accounts[0]});" through web3js
2). where does it store, I mean the bytecode I deployed and the "nstance" I created: 'Contract 1' and 'Contract 2', are they stored in the same place
3). instead of deployer.deploy(Contract,['Contract 1"]); how about if deployer.deploy(Contract); without calling the construction function, is it ok, if this is fine, then what's the difference again?
0 ·