2

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:

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 are they stored, I mean the bytecodes I deployed and the "instance" 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 ok, then what's the difference again with and without calling construction when deployment?

1 Answer 1

1

1)

The difference is that truffle will store where the contract address is in its compile output, looking like this:

"networks": {
  "3": {
    "events": {},
    "links": {},
    "address": "0xd968c3bc28aad317379753e2f0cb253b4cfbc039",
    "transactionHash": "0xb37c58de5550c0c5880fa2166adff8b50a23d06a031f4887f64f9fd358864740"
}

So when you use truffle-contract interface this way: SomeContract.deployed(), truffle framework will know where is the contract.

2)

They store in different address with the same bytecodes, you'd need to store their addresses. Truffle deployment will help you to store them in the compilation output .json file. I actually recommend you to store those .json file to your code repository, although they are generated files.

3)

I believe documentation says about them very clearly: http://truffleframework.com/docs/getting_started/migrations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.