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;
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
add a comment
|
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
add a comment
|
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
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
truffle dapp-development testing truffle-migration truffle-deployment
asked Apr 17 at 9:50
AleksandrAleksandr
6110 bronze badges
6110 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment
|
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
add a comment
|
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
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
edited Apr 17 at 13:02
answered Apr 17 at 10:51
Kyle DewhurstKyle Dewhurst
514 bronze badges
514 bronze badges
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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