Creating Contracts from Other Contracts

Contracts can create other contracts using the new function. For example:

erc20Token = new ERC20Fun(name, symbol, decimals)
erc20Token.balanceOf(address(this))

Arguments passed to ContractName(args) are treated as constructor arguments. The return value is a variable with contract-type that you can immediately use to call functions on the newly deployed contract.

Deterministic Deployments

To set the address in advance, pass a bytes32 salt:

erc20Token = new ERC20Fun(name, symbol, decimals, { salt: salt })

Last updated