Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Add Ethereum Tooling Guides #474

Merged
merged 8 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 62 additions & 50 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,43 @@ module.exports = {
},
},
head: [
[
"link",
{
rel: "stylesheet",
href:
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css",
},
],
[
"link",
{
rel: "stylesheet",
href:
"https://cdn.jsdelivr.net/github-markdown-css/2.2.1/github-markdown.css",
},
],
[
"link",
{
rel: "stylesheet",
href:
"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css",
},
],
[
"link",
{
rel: "stylesheet",
href:
"https://cdn.jsdelivr.net/github-markdown-css/2.2.1/github-markdown.css",
},
],
],
base: process.env.VUEPRESS_BASE || '/',
plugins: [
'vuepress-plugin-element-tabs'
],
themeConfig: {
repo: 'tharsis/ethermint',
docsRepo: 'tharsis/ethermint',
docsBranch: 'main',
docsDir: 'docs',
editLinks: true,
custom: true,
project: {
name: 'Ethermint',
denom: 'PHOTON',
ticker: 'ETHM',
rpc_url: '',
rpc_url_local: 'http://localhost:8545/',
chain_id: '',
block_explorer_url: '',
},
logo: {
src: '/ethermint-logo-horizontal-alpha.svg',
},
Expand Down Expand Up @@ -201,50 +213,50 @@ module.exports = {
{
service: "linkedin",
url: "https://www.linkedin.com/company/tharsis-finance/",
},
{
},
{
service: "medium",
url: "https://medium.com/@tharsis_labs",
},
},
],
smallprint: 'This website is maintained by Tharsis Labs Ltd.',
links: [{
title: 'Documentation',
children: [{
title: 'Cosmos SDK Docs',
url: 'https://docs.cosmos.network/master/'
},
{
title: 'Ethereum Docs',
url: 'https://ethereum.org/developers'
},
{
title: 'Tendermint Core Docs',
url: 'https://docs.tendermint.com'
}
]
title: 'Documentation',
children: [{
title: 'Cosmos SDK Docs',
url: 'https://docs.cosmos.network/master/'
},
{
title: 'Community',
children: [{
title: 'Ethermint Community',
url: 'https://discord.gg/3ZbxEq4KDu'
},
{
title: 'Ethermint Forum',
url: 'https://forum.cosmos.network/c/ethermint'
}
]
title: 'Ethereum Docs',
url: 'https://ethereum.org/developers'
},
{
title: 'Tharsis',
children: [
{
title: 'Jobs at Tharsis',
url: 'https://tharsis.notion.site/Jobs-at-Tharsis-5a1642eb89b34747ae6f2db2d356fc0d'
}
]
title: 'Tendermint Core Docs',
url: 'https://docs.tendermint.com'
}
]
},
{
title: 'Community',
children: [{
title: 'Ethermint Community',
url: 'https://discord.gg/3ZbxEq4KDu'
},
{
title: 'Ethermint Forum',
url: 'https://forum.cosmos.network/c/ethermint'
}
]
},
{
title: 'Tharsis',
children: [
{
title: 'Jobs at Tharsis',
url: 'https://tharsis.notion.site/Jobs-at-Tharsis-5a1642eb89b34747ae6f2db2d356fc0d'
}
]
}
]
},
versions: [
Expand Down
4 changes: 3 additions & 1 deletion docs/guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ parent:
* [Keyring](./keys-wallets/keyring)
* [Metamask](./keys-wallets/metamask)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this one and merged the other into it

3. Ethereum Tooling
* [Truffle](./tools/truffle)
* [MetaMask](./tools/metamask)
* [Remix](./tools/remix)
* [Hardhat](./tools/hardhat)
* [Truffle](./tools/truffle)
4. [Validators](./validators/overview)
5. [Key Management System](./kms/kms)
199 changes: 199 additions & 0 deletions docs/guides/tools/hardhat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<!--
order: 3
-->

# Hardhat: Deploying a Smart Contract

Learn how to deploy a simple Solidity-based smart contract to Ethermint using the Hardhat environment {synopsis}

[Hardhat](https://hardhat.org/) is a flexible development environment for building Ethereum-based smart contracts. It is designed with integrations and extensibility in mind

## Pre-requisite Readings

- [Installation](./../../quickstart/installation.md) {prereq}
- [Run a node](./../../quickstart/run_node.md) {prereq}

## Install Dependencies

Before proceeding, you need to install Node.js (we'll use v16.x) and the npm package manager. You can download directly from [Node.js](https://nodejs.org/en/download/) or in your terminal:

:::: tabs
::: tab Ubuntu

```shell
$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

$ sudo apt install -y nodejs
```
:::
::: tab MacOS

```shell
# You can use homebrew (https://docs.brew.sh/Installation)
$ brew install node

# Or you can use nvm (https://github.com/nvm-sh/nvm)
$ nvm install node
```

:::
::::

You can verify that everything is installed correctly by querying the version for each package:

```shell
$ node -v
...

$ npm -v
...
```

::: tip
If you haven't already, you will also need to install Ethermint if you plan on deploying your smart contracts locally. Check this [document](./../../quickstart/installation.md) for the full instructions.
:::

## Create Hardhat Project

To create a new project, navigate to your project directory and run:

```shell
$ npx hardhat

888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888

Welcome to Hardhat v2.0.8

? What do you want to do? …
❯ Create a sample project
Create an empty hardhat.config.js
```

Following the prompts should create a new project structure in your directory. Consult the [Hardhat config page](https://hardhat.org/config/) for a list of configuration options to specify in `hardhat.config.js`. Most importantly, you should set the `defaultNetwork` entry to point to your desired JSON-RPC network:

:::: tabs
::: tab Local Node

```javascript
module.exports = {
defaultNetwork: "local",
networks: {
hardhat: {
},
local: {
url: "http://localhost:8545/",
accounts: [privateKey1, privateKey2, ...]
}
},
...
}
```

:::
::: tab Testnet

```javascript
module.exports = {
defaultNetwork: "testnet",
networks: {
hardhat: {
},
testnet: {
url: "",
accounts: [privateKey1, privateKey2, ...]
}
},
...
}
```

:::
::::

To ensure you are targeting the correct network, you can query for a list of accounts available to you from your default network provider:

```shell
$ npx hardhat accounts
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
0x70997970C51812dc3A010C7d01b50e0d17dc79C8
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
0x90F79bf6EB2c4f870365E785982E1f101E93b906
...
```

## Deploying a Smart Contract

You will see that a default smart contract, written in Solidity, has already been provided under `contracts/Greeter.sol`:

```javascript
pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract Greeter {
string private greeting;

constructor(string memory _greeting) {
console.log("Deploying a Greeter with greeting:", _greeting);
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
greeting = _greeting;
}
}
```

This contract allows you to set and query a string `greeting`. Hardhat also provides a script to deploy smart contracts to a target network; this can be invoked via the following command, targeting your default network:

```shell
$ npx hardhat run scripts/sample-script.js
```

Hardhat also lets you manually specify a target network via the `--network <your-network>` flag:

:::: tabs
::: tab Local Node

```shell
$ npx hardhat run --network {{ $themeConfig.project.rpc_url_local }} scripts/sample-script.js
```

:::
::: tab Testnet

```shell
$ npx hardhat run --network {{ $themeConfig.project.rpc_url }} scripts/sample-script.js
```

:::
::::

Finally, try running a Hardhat test:

```shell
$ npx hardhat test
Compiling 1 file with 0.8.4
Compilation finished successfully


Greeter
Deploying a Greeter with greeting: Hello, world!
Changing greeting from 'Hello, world!' to 'Hola, mundo!'
✓ Should return the new greeting once it's changed (803ms)


1 passing (805ms)
```
Loading