> For the complete documentation index, see [llms.txt](https://solstep.gitbook.io/solidity-steps/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://solstep.gitbook.io/solidity-steps/tips/tips-hardhat-tutorial.md).

# Tips: Hardhat Tutorial

### Hardhat Tutorial

This tutorial is intended to help anyone who is interested in learning the basics of Solidity and the Hardhat development environment. After completing this tutorial, you should be able to write and deploy simple Solidity smart contracts.

**Setting up Hardhat**\
The first step is to install the Hardhat development environment. This can be done by running the following command:

```bash
npm install -g @nomiclabs/hardhat
```

**Initializing a Hardhat Project**\
Once Hardhat is installed, you can create a new project. This can be done by running the following command:

```bash
hardhat init
```

This will create the default hardhat.config.js file, which will be used to configure the Hardhat environment.

**Writing a Solidity Smart Contract**\
Now you are ready to write your first Solidity smart contract. Create a new file called `MyContract.sol` in the root of your project directory. This file should contain the following code:

```solidity
pragma solidity ^0.8; 
contract MyContract {  
  uint public myVariable; 
  constructor() public {    
    myVariable = 0;  
  } 
  function add(uint _value) public {    
    myVariable += _value;  
  }
}
```

This contract defines a single public variable, `myVariable`, and a single public function, `add`, which can be used to add a value to `myVariable`.

**Compiling a Smart Contract**\
Once your contract is written, you can compile it using Hardhat. This can be done by running the following command:

```bash
hardhat compile
```

This will compile your contract and output a JSON file containing the contract's abi and bytecode.

**Deploying a Smart Contract**\
Now you are ready to deploy your contract. This can be done by running the following command:

```bash
hardhat deploy
```

This will deploy your contract to a local development blockchain. Once the contract is deployed, you can interact with it using Hardhat's built-in console.

**Interacting with a Smart Contract**\
You can interact with your deployed contract using Hardhat's built-in console. This can be done by running the following command:

```bash
hardhat console
```

This will open a console which you can use to call functions on your deployed contract. For example, to add a value to myVariable, you can run the following command:

```javascript
MyContract.methods.add(10).send()
```

### Conclusion

This tutorial has demonstrated the basics of using Hardhat to write, compile, and deploy Solidity smart contracts. With the skills you have learned here, you should now be able to write and deploy basic Solidity smart contracts.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://solstep.gitbook.io/solidity-steps/tips/tips-hardhat-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
