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
- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat.
2177
+
2178
+
# Deploy an ERC-20 to Polkadot Hub
2179
+
2180
+
## Introduction
2181
+
2182
+
[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.
2183
+
2184
+
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](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}.
2185
+
2186
+
## Prerequisites
2187
+
2188
+
Before starting, make sure you have:
2189
+
2190
+
- Basic understanding of Solidity programming and fungible tokens.
2191
+
- Node.js v22.13.1 or later.
2192
+
- 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}.
2193
+
2194
+
## Set Up Your Project
2195
+
2196
+
This tutorial uses a [Hardhat ERC-20 template](https://github.com/polkadot-developers/revm-hardhat-examples/tree/master/erc20-hardhat){target=\_blank} that contains all the necessary files. To get started, take the following steps:
This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot.
2212
+
2213
+
## Configure Hardhat
2214
+
2215
+
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.
2216
+
2217
+
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:
2218
+
2219
+
```bash
2220
+
npx hardhat vars set TESTNET_PRIVATE_KEY
2221
+
```
2222
+
2223
+
The command will initiate a wizard in which you'll have to enter the value to be stored:
2224
+
2225
+
<div id="termynal" data-termynal markdown>
2226
+
<span data-ty="input">npx hardhat vars set TESTNET_PRIVATE_KEY</span>
2227
+
<span data-ty>✔ Enter value: · •••••••••</span>
2228
+
<span data-ty>The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json</span>
2229
+
</div>
2230
+
2231
+
??? warning "Key Encryption"
2232
+
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.
2233
+
2234
+
You can now use the account related to this private key by importing it into the Hardhat configuration file:
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
2284
+
2285
+
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:
2286
+
2287
+
1. The token was deployed by verifying its **name** and **symbol**.
2288
+
2. The token has the right owner configured.
2289
+
3. The token has an initial supply of zero.
2290
+
4. The owner can mint tokens.
2291
+
5. The total supply is increased after a mint.
2292
+
6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply.
2293
+
2294
+
To run the test, you can execute the following command:
2295
+
2296
+
```bash
2297
+
npx hardhat test --network polkadotTestnet
2298
+
```
2299
+
2300
+
If tests are successful, you should see the following logs:
2301
+
2302
+
<div id="termynal" data-termynal markdown>
2303
+
<span data-ty="input">npx hardhat test --network polkadotTestnet</span>
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.
2322
+
2323
+
To deploy the contract, run the following command:
And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat.
2353
+
2354
+
## Where to Go Next
2355
+
2356
+
<div class="grid cards" markdown>
2357
+
2358
+
- <span class="badge guide">Guide</span> __Deploy an NFT with Remix__
2359
+
2360
+
---
2361
+
2362
+
Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix.
2363
+
2364
+
[:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/)
2365
+
2366
+
</div>
2367
+
2368
+
2170
2369
---
2171
2370
2172
2371
Page Title: Deploy an ERC-20 to Polkadot Hub
@@ -2187,9 +2386,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us
2187
2386
2188
2387
Before starting, make sure you have:
2189
2388
2389
+
- Basic understanding of Solidity programming and fungible tokens.
2190
2390
- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}.
2191
2391
- 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}.
2192
-
- Basic understanding of Solidity and fungible tokens.
2193
2392
2194
2393
## Create Your Contract
2195
2394
@@ -2924,7 +3123,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP
2924
3123
2925
3124
- Basic understanding of Solidity programming and NFT standards.
2926
3125
- Node.js v22.13.1 or later.
2927
-
- Test tokens for gas fees (available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}). See the [step-by-step instructions](/smart-contracts/faucet/#get-test-tokens){target=\_blank}.
3126
+
- 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}.
2928
3127
- A wallet with a private key for signing transactions.
0 commit comments