Deploy new contract through another contract function in Truffle Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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 Deploy Doesn't WorkTruffle deployment error with infuraTruffle contract migration deploying same contract on multiple addressTruffle deployment with metamask to ganache leads private key errorDeploying smart contract through TruffleReferenceError: address is not defined

Statistical analysis applied to methods coming out of Machine Learning

How to infer difference of population proportion between two groups when proportion is small?

Are there any irrational/transcendental numbers for which the distribution of decimal digits is not uniform?

Can I cut the hair of a conjured korred with a blade made of precious material to harvest that material from the korred?

Flight departed from the gate 5 min before scheduled departure time. Refund options

By what mechanism was the 2017 UK General Election called?

How does TikZ render an arc?

Russian equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

calculator's angle answer for trig ratios that can work in more than 1 quadrant on the unit circle

My mentor says to set image to Fine instead of RAW — how is this different from JPG?

An isoperimetric-type inequality inside a cube

Is the time—manner—place ordering of adverbials an oversimplification?

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

Why do C and C++ allow the expression (int) + 4*5?

Can two people see the same photon?

How to achieve cat-like agility?

How to make triangles with rounded sides and corners? (squircle with 3 sides)

Pointing to problems without suggesting solutions

First paper to introduce the "principal-agent problem"

Meaning of 境 in その日を境に

3D Masyu - A Die

Marquee sign letters

Any stored/leased 737s that could substitute for grounded MAXs?



Deploy new contract through another contract function in Truffle



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)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 Deploy Doesn't WorkTruffle deployment error with infuraTruffle contract migration deploying same contract on multiple addressTruffle deployment with metamask to ganache leads private key errorDeploying smart contract through TruffleReferenceError: address is not defined










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

      509




      509




















          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/3.0/"u003ecc by-sa 3.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




                514



























                    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

                    Sum ergo cogito? 1 nng

                    419 nièngy_Soadمي 19bal1.5o_g

                    Queiggey Chernihivv 9NnOo i Zw X QqKk LpB