Deploy new contract through another contract function in Truffle Planned maintenance scheduled...

Does classifying an integer as a discrete log require it be part of a multiplicative group?

What does this Jacques Hadamard quote mean?

What causes the direction of lightning flashes?

How could we fake a moon landing now?

How does the math work when buying airline miles?

First console to have temporary backward compatibility

If a VARCHAR(MAX) column is included in an index, is the entire value always stored in the index page(s)?

Is "Reachable Object" really an NP-complete problem?

Is this homebrew Lady of Pain warlock patron balanced?

Did MS DOS itself ever use blinking text?

What does the "x" in "x86" represent?

If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?

How do I find out the mythology and history of my Fortress?

Fundamental Solution of the Pell Equation

Can an alien society believe that their star system is the universe?

How to find all the available tools in mac terminal?

How do I make this wiring inside cabinet safer? (Pic)

What is homebrew?

Dating a Former Employee

What would be the ideal power source for a cybernetic eye?

What's the meaning of "fortified infraction restraint"?

How to convince students of the implication truth values?

Would "destroying" Wurmcoil Engine prevent its tokens from being created?

Is there such thing as an Availability Group failover trigger?



Deploy new contract through another contract function in Truffle



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?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 18 hours ago









      AleksandrAleksandr

      509




      509






















          2 Answers
          2






          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

































            0














            The Cryptocurenncy Very Special When Her Open : Mining Pool / Trading / Hot Wallet With : Ethereum Revolutions : We Target Last Price On The Decemner $120






            share|improve this answer








            New contributor




            BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              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

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              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 14 hours ago

























                  answered 16 hours ago









                  Kyle DewhurstKyle Dewhurst

                  513




                  513























                      0














                      The Cryptocurenncy Very Special When Her Open : Mining Pool / Trading / Hot Wallet With : Ethereum Revolutions : We Target Last Price On The Decemner $120






                      share|improve this answer








                      New contributor




                      BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        The Cryptocurenncy Very Special When Her Open : Mining Pool / Trading / Hot Wallet With : Ethereum Revolutions : We Target Last Price On The Decemner $120






                        share|improve this answer








                        New contributor




                        BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          The Cryptocurenncy Very Special When Her Open : Mining Pool / Trading / Hot Wallet With : Ethereum Revolutions : We Target Last Price On The Decemner $120






                          share|improve this answer








                          New contributor




                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          The Cryptocurenncy Very Special When Her Open : Mining Pool / Trading / Hot Wallet With : Ethereum Revolutions : We Target Last Price On The Decemner $120







                          share|improve this answer








                          New contributor




                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 1 hour ago









                          BIGCRYPTO001BIGCRYPTO001

                          11




                          11




                          New contributor




                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          BIGCRYPTO001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              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

                              Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

                              Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                              VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...