0

Hoping someone can answer a couple questions regarding deploying multiple contracts with truffle. 1.)I can create one contract in the the deploy, something like 2_deploy_contracts.js and all the contracts i am deploying can be deployed using this one file or did i need multiple deploy files?

2.)Do i also need to deploy the interface contracts and other contracts I've Imported into my contracts, like openzeppelin contracts i am using? I am guessing any interfaces/imported contracts will automatically get deployed when i deploy my main contracts right? So i don't need to actually deploy them in the deploy file?

3.)Many of the contracts i have written have constructors, so in the 2_deploy_contracts.js file i need to include everything i am passing into the constructor for each of the contracts right?

Does anyone have an examples, a github link, or anything else that shows an example of a deploy file that is written to deploy multiple contracts with Truffle? I am particularly interested in seeing how this is written when you are deploying contracts that have constructors you need to pass variables to.

1 Answer 1

0
  1. You don't need multiple files, you can use only one. Here's an example of a multi-contracts deployment:
const erc20_token_template = artifacts.require("./ERC20TokenTemplate.sol");
const erc20_token_vendor = artifacts.require("./ERC20TokenVendor.sol");
const erc20_token_dealer = artifacts.require("./ERC20TokenDealer.sol");

module.exports = function(deployer) {
    var name = "coins";
    var symbol = "MTK"
    var totalSupply = "100000000000000000000";
    deployer.deploy(erc20_token_template, name, symbol, totalSupply)
    .then(() => deployer.deploy(erc20_token_vendor, erc20_token_template.address, 5));
    deployer.deploy(erc20_token_dealer, erc20_token_template.address)
};

  1. You don't deploy interfaces. You should compile them for using their ABI to access the deployed contracts.

  2. See the example, it's an actual code from one of my projects :)

2
  • Thanks for the response. Greatly appreciate the help. If you get around to it maybe you can clarify on thing for me.... In the module.exports section, for each contract it looks like you are doing... deployer.deploy() and inside the parenthesis you are putting both the contract name and anything that goes in the constructor for that particular contract. Is that correct? Also if i import the open zeppelin ERC20 contract (not interface) in one of my contracts do I also need to deploy it since its not an interface? Thanks again.
    – Blockpain
    Commented Oct 17, 2022 at 14:34
  • If you inherit from a contract you don’t need to deploy it, the implementation is in your contract. And yes, deployer.deploy gets the contract and it’s constructor arguments.
    – matank001
    Commented Oct 17, 2022 at 15:04

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.