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 1, and, eventually, returning the address of the instance to the caller.
Deploying a contract involves checking whether the sender has provided enough gas to complete the deployment, generating a new account/address for contract deployment using the requestor's address
and nonce
values, and passing on any Ether sent along with it.
In the following code snippet, 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...