npm package: @hzabala/create-solidity-smart-contract
Description: <p align="left">   <a href="https://www.npmjs.com/package/@hzabala/create-solidity-smart-contract"><img src="https://img.shields.io/npm/v/@hzabala/create-solidity-smart-contract.svg" alt="npm version"></a>   <a href="./LICENSE.md"><img src="https://img.sh
Author: Heanzy Zabala
Latest version: 0.1.3

# Create Solidity Smart Contract
<p align="left">
  <a href="https://www.npmjs.com/package/@hzabala/create-solidity-smart-contract"><img src="https://img.shields.io/npm/v/@hzabala/create-solidity-smart-contract.svg" alt="npm version"></a>
  <a href="./LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License MIT"/></a>
<p>

A template generator for creating smart contracts using:
- [Solidity](https://soliditylang.org/) 
- [HardHat](https://hardhat.org) 
- [Typescript](https://www.typescriptlang.org)
- [TypeChain](https://github.com/ethereum-ts/TypeChain)

## Installation
```bash
npm i -g @hzabala/create-solidity-smart-contract
```
Or
```bash
npx @hzabala/create-solidity-smart-contract <projectName>
```

## Usage
Create a project using this command:

```bash
create-express-api myapp
```

## Getting Started

After installing, navigate to the project and run:
```bash
npm run deploy
```
You should be able to see something like this:
```bash
Deploying a Greeter with greeting: Hello, Hardhat!
Hash 0xa9a34b54e06fb7070f541c1690c724be6893e2e4adb5eadcfe103e8205ae9697
Greeter deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
```
This deploys the sample [greeter.sol](https://github.com/heanzyzabala/create-solidity-smart-contract/blob/master/template/contracts/greeter.sol) smart contract to your local Ethereum network. 

By default, if you deploy and you don't have a persistent node running, a temporary node is created that only lives for the duration of the deployment, meaning that any transactions created will be gone. 
The same behavior applies when running tests.

### Running a persistent node

To run a persitent node, type:
```bash
npm run dev
```
Open a new terminal, and then run:
```bash
npm run deploy -- --network localhost
```

The `--network localhost` flag simply points the connection to the persistent node that you're running, rather than the default.

So now you can persist and interact with the transactions created in your local node, which is useful if you're creating dApps and you want to test it locally.

Read more here: [Hardhat - Getting Started](https://hardhat.org/getting-started/)

## Deploying to a public testnet

After developing and testing your smart contract, you can now deploy it to an Ethereum public testnet.

A testnet is a production-like environment where you initially deploy your smart contracts before deploying them to the mainnet.
In conventional software development, it's the same as the Staging and Production environment.

Read more here: [Ethereum - Networks](https://ethereum.org/en/developers/docs/networks)

### Connecting to Ropsten Test Network

Similar to running a local node, you need to run a testnet node in order to deploy smart contracts to it. 
However, maintaining your own testnet node is not really worth it.

Fortunately, we have [Infura](https://infura.io). 
Infura is a service provider that hosts their own testnets and mainnet nodes and provides API for developers for easy access.

Register and create a project in Infura. After creating a new project, Infura will give you a `PROJECT ID`. Navigate your directory, and paste it as value for `INFURA_API_KEY` in `.env` file.
```bash
INFURA_API_KEY=
DEPLOYER_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000
```

Additionally, you also need an account for `DEPLOYER_PRIVATE_KEY`.  It's simply a wallet that you'll use to deploy smart contracts in the testnet, you need it to be funded since deploying smart contracts requires gas fees. A dummy private key is currently set to suppress Hardhat config validation until you have an actual account.

You can register an account in [MetaMask](https://metamask.io), set `Ropsten Test Network` as your network.
Export your private key from MetaMask and paste it as value for `DEPLOYER_PRIVATE_KEY` in `.env`.

To fund your account, just visit ether faucets like: https://faucet.ropsten.be and paste your public address. It will send you ETH for free.

### Deploying to Ropsten Test Network
After everything is set, just type:
```bash
npm run deploy -- --network ropsten
```
You'll see a similar output when deploying to a local node:
```bash
Hash 0x071059df0bfd7599868e502744f0851c28ec9d7167777066e9b7efb4597876bc
Greeter deployed to: 0xde6E94Da99EE84a90E85FFcE02c5baF2380D3248
```

You can use the transaction hash to see the transaction in [Ropsten - Etherscan](https://ropsten.etherscan.io).

The `--network ropsten` flag is configured in `hardhat.config.ts`. You can freely add or change any networks (e.g. kovan, rinkeby, goerli). But in this case, I choose ropsten since it's the closet representation of the mainnet.

```typescript
const config: HardhatUserConfig = {
	solidity: '0.7.3',
	defaultNetwork: 'hardhat',
	networks: {
		ropsten: {
			url: `https://ropsten.infura.io/v3/${INFURA_API_KEY}`,
			accounts: [`0x${DEPLOYER_PRIVATE_KEY}`],
		},
	},
};
```

## Contributing

Pull requests are welcome. Please open an issue first to discuss what you would like to change.

## License
```
MIT License

Copyright (c) 2021 Heanzy Zabala

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```