Deploy new contract through another contract function in TruffleHow is the address of an Ethereum contract computed?Transaction receipt has contractAddress as null'Error: base fee exceeds gas limit' When creating new contract instance (Using Truffle, Web3Js and testrpc)Truffle migrate vs Truffle deployVM Exception: Contract from within a contractDeploying contracts in truffle while passing parameters of it constructor results in an errorTruffle deployment error with infuraDeploying smart contract through TruffleUnused function parameter. Remove or comment out the variable name to silence this warning

Test if two food are the same

3x3 self-descriptive squares

What are the bars protruding from this C-130?

Would it be easier to colonise a living world or a dead world?

Ways to bypass spell resistance in 5e?

Why did a young George Washington sign a document admitting to assassinating a French military officer?

how do you value what your leisure time is worth?

Meaning/translation of title "The Light Fantastic" By Terry Pratchett

Relation between signal processing and control systems engineering?

How much money should I save in order to generate $1000/month for the rest of my life?

Why didn't Trudy wear a breathing mask in Avatar?

How to Skip One Bullet in ITEMIZE?

How are steel imports supposed to threaten US national security?

Concrete description of lift in Arens-Eells space

Find the percentage

Looking for PC graphics demo software from the early 90s called "Unreal"

This fell out of my toilet when I unscrewed the supply line. What is it?

Rat proofing compost bin but allowing worms in

Why does allocating a single 2D array take longer than a loop allocating multiple 1D arrays of the same total size and shape?

How to measure torque accurately?

What if a quote contains an error

Scalar `new T` vs array `new T[1]`

Does UPDATE without WHERE clause lock a table in PostgreSQL?

Can I perform Umrah while on a Saudi Arabian visit e-visa



Deploy new contract through another contract function in Truffle


How is the address of an Ethereum contract computed?Transaction receipt has contractAddress as null'Error: base fee exceeds gas limit' When creating new contract instance (Using Truffle, Web3Js and testrpc)Truffle migrate vs Truffle deployVM Exception: Contract from within a contractDeploying contracts in truffle while passing parameters of it constructor results in an errorTruffle deployment error with infuraDeploying smart contract through TruffleUnused function parameter. Remove or comment out the variable name to silence this warning






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1















I have a function in my contract minter.sol that creates another contract etnX.sol:



function createNewContract(string memory name, string memory symbol, uint256 _maxSupply) 
public onlyOwner
etnX c = new etnX(name, symbol, _maxSupply, address(store));



I want to call this function in truffle and get new contract address.
I'm trying to do so:



const minter = artifacts.require('../contracts/minter.sol')
const etnX = artifacts.require('etnX')
const etnXs = [100,200,500,1000,10000,100000,1000000,10000000]
module.exports = async function(deployer)
deployer.deploy(minter).then(async() =>
var minterInstance = await minter.deployed();
for (var i=0; i<etnXs.length;i++)
await minterInstance.createNewContract("x","x", etnXs[i]);
var x = await etnX.deployed();
console.log(x.address);
)
;


However, it doesn't deploy. Can someone explain me how to do this?










share|improve this question






























    1















    I have a function in my contract minter.sol that creates another contract etnX.sol:



    function createNewContract(string memory name, string memory symbol, uint256 _maxSupply) 
    public onlyOwner
    etnX c = new etnX(name, symbol, _maxSupply, address(store));



    I want to call this function in truffle and get new contract address.
    I'm trying to do so:



    const minter = artifacts.require('../contracts/minter.sol')
    const etnX = artifacts.require('etnX')
    const etnXs = [100,200,500,1000,10000,100000,1000000,10000000]
    module.exports = async function(deployer)
    deployer.deploy(minter).then(async() =>
    var minterInstance = await minter.deployed();
    for (var i=0; i<etnXs.length;i++)
    await minterInstance.createNewContract("x","x", etnXs[i]);
    var x = await etnX.deployed();
    console.log(x.address);
    )
    ;


    However, it doesn't deploy. Can someone explain me how to do this?










    share|improve this question


























      1












      1








      1








      I have a function in my contract minter.sol that creates another contract etnX.sol:



      function createNewContract(string memory name, string memory symbol, uint256 _maxSupply) 
      public onlyOwner
      etnX c = new etnX(name, symbol, _maxSupply, address(store));



      I want to call this function in truffle and get new contract address.
      I'm trying to do so:



      const minter = artifacts.require('../contracts/minter.sol')
      const etnX = artifacts.require('etnX')
      const etnXs = [100,200,500,1000,10000,100000,1000000,10000000]
      module.exports = async function(deployer)
      deployer.deploy(minter).then(async() =>
      var minterInstance = await minter.deployed();
      for (var i=0; i<etnXs.length;i++)
      await minterInstance.createNewContract("x","x", etnXs[i]);
      var x = await etnX.deployed();
      console.log(x.address);
      )
      ;


      However, it doesn't deploy. Can someone explain me how to do this?










      share|improve this question














      I have a function in my contract minter.sol that creates another contract etnX.sol:



      function createNewContract(string memory name, string memory symbol, uint256 _maxSupply) 
      public onlyOwner
      etnX c = new etnX(name, symbol, _maxSupply, address(store));



      I want to call this function in truffle and get new contract address.
      I'm trying to do so:



      const minter = artifacts.require('../contracts/minter.sol')
      const etnX = artifacts.require('etnX')
      const etnXs = [100,200,500,1000,10000,100000,1000000,10000000]
      module.exports = async function(deployer)
      deployer.deploy(minter).then(async() =>
      var minterInstance = await minter.deployed();
      for (var i=0; i<etnXs.length;i++)
      await minterInstance.createNewContract("x","x", etnXs[i]);
      var x = await etnX.deployed();
      console.log(x.address);
      )
      ;


      However, it doesn't deploy. Can someone explain me how to do this?







      truffle dapp-development testing truffle-migration truffle-deployment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 17 at 9:50









      AleksandrAleksandr

      6110 bronze badges




      6110 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          3
















          1.) You can make the function emit an event that broadcasts the new address and then check the logs of the transaction receipt. Receipt




          // Solidity
          function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
          public onlyOwner
          etnX c = new etnX(name, symbol, _maxSupply, address(store));
          emit NewContract(address(c));


          // Javascript
          let tx = await minterInstance.createNewContract("x", "x", 300);
          // Look through tx.logs for event results


          2.) You can return the contract address in the solidity function and then instead of initiating a transaction make a call() to get the address. (Then make the transaction....it will be deployed at the same address as returned by the call())




          // Solidity
          function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
          public onlyOwner
          returns (address)
          etnX c = new etnX(name, symbol, _maxSupply, address(store));
          return address(c)


          // Javascript
          let addr = await minterInstance.createNewContract.call("x", "x", 300);


          3.) Manually calculate it






          share|improve this answer




























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "642"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f69754%2fdeploy-new-contract-through-another-contract-function-in-truffle%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3
















            1.) You can make the function emit an event that broadcasts the new address and then check the logs of the transaction receipt. Receipt




            // Solidity
            function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
            public onlyOwner
            etnX c = new etnX(name, symbol, _maxSupply, address(store));
            emit NewContract(address(c));


            // Javascript
            let tx = await minterInstance.createNewContract("x", "x", 300);
            // Look through tx.logs for event results


            2.) You can return the contract address in the solidity function and then instead of initiating a transaction make a call() to get the address. (Then make the transaction....it will be deployed at the same address as returned by the call())




            // Solidity
            function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
            public onlyOwner
            returns (address)
            etnX c = new etnX(name, symbol, _maxSupply, address(store));
            return address(c)


            // Javascript
            let addr = await minterInstance.createNewContract.call("x", "x", 300);


            3.) Manually calculate it






            share|improve this answer































              3
















              1.) You can make the function emit an event that broadcasts the new address and then check the logs of the transaction receipt. Receipt




              // Solidity
              function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
              public onlyOwner
              etnX c = new etnX(name, symbol, _maxSupply, address(store));
              emit NewContract(address(c));


              // Javascript
              let tx = await minterInstance.createNewContract("x", "x", 300);
              // Look through tx.logs for event results


              2.) You can return the contract address in the solidity function and then instead of initiating a transaction make a call() to get the address. (Then make the transaction....it will be deployed at the same address as returned by the call())




              // Solidity
              function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
              public onlyOwner
              returns (address)
              etnX c = new etnX(name, symbol, _maxSupply, address(store));
              return address(c)


              // Javascript
              let addr = await minterInstance.createNewContract.call("x", "x", 300);


              3.) Manually calculate it






              share|improve this answer





























                3














                3










                3









                1.) You can make the function emit an event that broadcasts the new address and then check the logs of the transaction receipt. Receipt




                // Solidity
                function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
                public onlyOwner
                etnX c = new etnX(name, symbol, _maxSupply, address(store));
                emit NewContract(address(c));


                // Javascript
                let tx = await minterInstance.createNewContract("x", "x", 300);
                // Look through tx.logs for event results


                2.) You can return the contract address in the solidity function and then instead of initiating a transaction make a call() to get the address. (Then make the transaction....it will be deployed at the same address as returned by the call())




                // Solidity
                function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
                public onlyOwner
                returns (address)
                etnX c = new etnX(name, symbol, _maxSupply, address(store));
                return address(c)


                // Javascript
                let addr = await minterInstance.createNewContract.call("x", "x", 300);


                3.) Manually calculate it






                share|improve this answer















                1.) You can make the function emit an event that broadcasts the new address and then check the logs of the transaction receipt. Receipt




                // Solidity
                function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
                public onlyOwner
                etnX c = new etnX(name, symbol, _maxSupply, address(store));
                emit NewContract(address(c));


                // Javascript
                let tx = await minterInstance.createNewContract("x", "x", 300);
                // Look through tx.logs for event results


                2.) You can return the contract address in the solidity function and then instead of initiating a transaction make a call() to get the address. (Then make the transaction....it will be deployed at the same address as returned by the call())




                // Solidity
                function createNewContract(string memory name, string memory symbol, uint256 _maxSupply)
                public onlyOwner
                returns (address)
                etnX c = new etnX(name, symbol, _maxSupply, address(store));
                return address(c)


                // Javascript
                let addr = await minterInstance.createNewContract.call("x", "x", 300);


                3.) Manually calculate it







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 17 at 13:02

























                answered Apr 17 at 10:51









                Kyle DewhurstKyle Dewhurst

                514 bronze badges




                514 bronze badges































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Ethereum Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f69754%2fdeploy-new-contract-through-another-contract-function-in-truffle%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Tamil (spriik) Luke uk diar | Nawigatjuun

                    Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                    Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?