Creating contracts
There are the following two ways of creating and using a contract in Solidity:
- Using the
new
keyword - Using the address of the already deployed contract
Using the new keyword
The new
keyword in Solidity deploys and creates a new contract instance. It initializes the contract instance by deploying the contract, initializing the state variables, running its constructor, setting the nonce
value to one, and, eventually, returns the address of the instance to the caller. Deploying a contract involves checking whether the requestor has provided enough gas to complete deployment, generating a new account/address for contract deployment using the requestor's address
and nonce
value, and passing on any Ether sent along with it.
In the next screenshot, two contracts, HelloWorld
and client
, are defined. In this scenario, one contract (client
) deploys and creates a new instance of another contract (HelloWorld
). It does so using the new
keyword as shown in the following code snippet:
HelloWorld...