You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Deploy a Contract with Hardhat
2
+
title: Deploy Basic Contract with Hardhat
3
3
description: Learn how to deploy a basic smart contract to Polkadot Hub using Hardhat, Perfect for professional workflows requiring comprehensive testing and debugging.
Copy file name to clipboardExpand all lines: smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md
+37-56Lines changed: 37 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,27 @@
1
1
---
2
-
title: Deploy an ERC-20 to Polkadot Hub
2
+
title: Deploy ERC-20 Using Hardhat
3
3
description: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat.
4
4
tutorial_badge: Intermediate
5
5
categories: Basics, Smart Contracts
6
6
tools: Hardhat
7
7
---
8
8
9
-
# Deploy an ERC-20 to Polkadot Hub
9
+
# Deploy ERC-20 Using Hardhat
10
10
11
11
## Introduction
12
12
13
-
[ERC-20](https://eips.ethereum.org/EIPS/eip-20){target=\_blank} tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy token deployment with Ethereum-compatible smart contracts and tools via the EVM backend.
13
+
[ERC-20](https://eips.ethereum.org/EIPS/eip-20){target=\_blank} tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy ERC-20 token deployment with Ethereum-compatible smart contracts and tools via the EVM backend.
14
14
15
-
This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Hardhat](https://hardhat.org/){target=\_blank}, an Ethereum development environment. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}.
15
+
This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Hardhat](https://hardhat.org/){target=\_blank}, an Ethereum development environment. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}.
16
16
17
17
## Prerequisites
18
18
19
-
Before starting, make sure you have:
19
+
Before you begin, ensure sure you have the following:
20
20
21
-
- Basic understanding of Solidity programming and fungible tokens.
22
-
- Node.js v22.13.1 or later.
23
-
- A funded account with tokens for transaction fees. This example will deploy the contract to the Polkadot TestNet, so you'll [need some TestNet tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}.
21
+
- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming and [ERC-20](https://ethereum.org/developers/docs/standards/tokens/erc-20/) fungible tokens.
22
+
- Node.js v22.13.1 or later installed.
23
+
- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet.
24
+
- A wallet with a private key for signing transactions.
24
25
25
26
## Set Up Your Project
26
27
@@ -38,49 +39,31 @@ This tutorial uses a [Hardhat ERC-20 template](https://github.com/polkadot-devel
38
39
```bash
39
40
npm i
40
41
```
41
-
42
-
This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot.
42
+
43
+
This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot.
43
44
44
45
## Configure Hardhat
45
46
46
-
Once you've [setup your project](#set-up-your-project), you can configure the `hardhat.config.ts` to your needs. This tutorial has the file prepared to deploy to the Polkadot TestNet.
47
-
48
-
To store and use private keys or network URLs, you can use Hardhat's configuration variables. This can be set via tasks in the **vars** scope. For example, to store the private key to deploy to the Polkadot TestNet, run the following command:
49
-
50
-
```bash
51
-
npx hardhat vars set TESTNET_PRIVATE_KEY
52
-
```
53
-
54
-
The command will initiate a wizard in which you'll have to enter the value to be stored:
47
+
If you started with the cloned Hardhat ERC-20 template, `hardhat.config.js` is already configured to deploy to the Polkadot TestNet as shown in the example below:
55
48
56
-
<div id="termynal" data-termynal markdown>
57
-
<span data-ty="input">npx hardhat vars set TESTNET_PRIVATE_KEY</span>
58
-
<span data-ty>✔ Enter value: · •••••••••</span>
59
-
<span data-ty>The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json</span>
60
-
</div>
61
-
62
-
??? warning "Key Encryption"
63
-
This solution just prevents variables to be included in the code repository. You should find a solution that encrypts private keys and access them securely.
64
-
65
-
You can now use the account related to this private key by importing it into the Hardhat configuration file:
Visit the Hardhat [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} documentation to learn how to use Hardhat to handle your private keys in a secure way.
74
57
75
-
Once you've configured Hardhat, you can compile the contract.
58
+
## Compile the Contract
76
59
77
-
In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command:
60
+
Next, compile the contract included with the template by running the following command:
78
61
79
62
```bash
80
63
npx hardhat compile
81
64
```
82
65
83
-
If everything compiles successfully, you should see the following output:
66
+
If everything compiles successfully, you will see output similar to the following:
84
67
85
68
<div id="termynal" data-termynal markdown>
86
69
<span data-ty="input">npx hardhat compile</span>
@@ -89,26 +72,26 @@ If everything compiles successfully, you should see the following output:
Hardhat has a native feature to test contracts. You can run tests against the local Hardhat development node, but it could have some technical differences to Polkadot. Therefore, in this tutorial, you'll be testing against the Polkadot TestNet
77
+
Using Hardhat's native features to test contractsagainst the local Hardhat development node is challenging due to some technical differences between the local node and Polkadot. This example tests contracts against the Polkadot TestNet to account for these differences.
95
78
96
-
This example has a predefined test file located in [`test/Token.test.js`](https://github.com/polkadot-developers/revm-hardhat-examples/blob/master/erc20-hardhat/test/MyToken.test.ts){target=\_blank}, that runs the following tests:
79
+
You can view the predefined test file at [`test/MyToken.test.ts`](https://github.com/polkadot-developers/revm-hardhat-examples/blob/master/erc20-hardhat/test/MyToken.test.ts){target=\_blank}. This example test includes verification of the following:
97
80
98
-
1. The token was deployed by verifying its **name** and **symbol**.
99
-
2. The token has the right owner configured.
100
-
3. The token has an initial supply of zero.
101
-
4. The owner can mint tokens.
102
-
5. The total supply is increased after a mint.
103
-
6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply.
81
+
- The token name and symbol exist (confirms deployment) and are correct.
82
+
- The token owner is correctly configured.
83
+
- The initial token supply is zero.
84
+
- The owner can mint tokens.
85
+
- The total supply increases after a mint.
86
+
- Successful mints to different test addresses with correct corresponding account balance and total supply changes.
104
87
105
-
To run the test, you can execute the following command:
88
+
Run the test using the following command:
106
89
107
90
```bash
108
91
npx hardhat test --network polkadotTestnet
109
92
```
110
93
111
-
If tests are successful, you should see the following logs:
94
+
If tests are successful, you will see outputs similar to the following:
112
95
113
96
<div id="termynal" data-termynal markdown>
114
97
<span data-ty="input">npx hardhat test --network polkadotTestnet</span>
@@ -127,18 +110,16 @@ If tests are successful, you should see the following logs:
With the Hardhat configuration file ready, the private key stored as a variable under **vars**, and the contract compiled, you can proceed to deploy the contract to a given network. In this tutorial, you are deploying it to the Polkadot TestNet.
113
+
## Deploy the Contract
133
114
134
-
To deploy the contract, run the following command:
You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows:
139
116
140
-
You'll need to confirm the target network (by chain ID):
0 commit comments