Skip to content

Commit 7191e77

Browse files
authored
Merge branch 'staging/product-ia' into bruno/pallet-unit-testing
2 parents db8af0c + 45b3899 commit 7191e77

19 files changed

+2085
-45
lines changed

.ai/categories/basics.md

Lines changed: 201 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,205 @@ Several SCALE codec implementations are available in various languages. Here's a
21672167
- **TypeScript**: [`parity-scale-codec-ts`](https://github.com/tjjfvi/subshape){target=\_blank}, [`scale-ts`](https://github.com/unstoppablejs/unstoppablejs/tree/main/packages/scale-ts#scale-ts){target=\_blank}, [`soramitsu/scale-codec-js-library`](https://github.com/soramitsu/scale-codec-js-library){target=\_blank}, [`subsquid/scale-codec`](https://github.com/subsquid/squid-sdk/tree/master/substrate/scale-codec){target=\_blank}
21682168

21692169

2170+
---
2171+
2172+
Page Title: Deploy an ERC-20 to Polkadot Hub
2173+
2174+
- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md
2175+
- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/
2176+
- 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:
2197+
2198+
1. Clone the GitHub repository locally:
2199+
2200+
```bash
2201+
git clone https://github.com/polkadot-developers/revm-hardhat-examples/
2202+
cd revm-hardhat-examples/erc20-hardhat
2203+
```
2204+
2205+
2. Install the dependencies:
2206+
2207+
```bash
2208+
npm i
2209+
```
2210+
2211+
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:
2235+
2236+
```ts title="hardhat.config.ts" hl_lines="1 17"
2237+
2238+
const config: HardhatUserConfig = {
2239+
solidity: {
2240+
version: "0.8.28",
2241+
settings: {
2242+
optimizer: {
2243+
enabled: true,
2244+
runs: 200,
2245+
},
2246+
},
2247+
},
2248+
networks: {
2249+
polkadotTestnet: {
2250+
url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"),
2251+
accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [],
2252+
},
2253+
},
2254+
mocha: {
2255+
timeout: 40000,
2256+
},
2257+
};
2258+
2259+
export default config;
2260+
```
2261+
2262+
## Compile your Contract
2263+
2264+
Once you've configured Hardhat, you can compile the contract.
2265+
2266+
In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command:
2267+
2268+
```bash
2269+
npx hardhat compile
2270+
```
2271+
2272+
If everything compiles successfully, you should see the following output:
2273+
2274+
<div id="termynal" data-termynal markdown>
2275+
<span data-ty="input">npx hardhat compile</span>
2276+
<span data-ty>Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6</span>
2277+
<span data-ty>Successfully generated 62 typings!</span>
2278+
<span data-ty>Compiled 21 Solidity files successfully (evm target: paris).</span>
2279+
</div>
2280+
2281+
## Test your Contract
2282+
2283+
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>
2304+
<span data-ty></span>
2305+
<span data-ty>&nbsp;&nbsp;MyToken</span>
2306+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;Deployment</span>
2307+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should have correct name and symbol</span>
2308+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should set the right owner</span>
2309+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should have zero initial supply</span>
2310+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;Minting</span>
2311+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should allow owner to mint tokens</span>
2312+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should increase total supply on mint</span>
2313+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;Multiple mints</span>
2314+
<span data-ty>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;✔ Should correctly track balance after multiple mints</span>
2315+
<span data-ty></span>
2316+
<span data-ty>&nbsp;&nbsp;6 passing (369ms)</span>
2317+
</div>
2318+
2319+
## Deploy your Contract
2320+
2321+
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:
2324+
2325+
```bash
2326+
npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet
2327+
```
2328+
2329+
You'll need to confirm the target network (by chain ID):
2330+
2331+
<div id="termynal" data-termynal markdown>
2332+
<span data-ty="input">npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet</span>
2333+
<span data-ty>✔ Confirm deploy to network polkadotTestnet (420420420)? … yes</span>
2334+
<span data-ty>&nbsp;</span>
2335+
<span data-ty>Hardhat Ignition 🚀</span>
2336+
<span data-ty>&nbsp;</span>
2337+
<span data-ty>Deploying [ TokenModule ]</span>
2338+
<span data-ty>&nbsp;</span>
2339+
<span data-ty>Batch #1</span>
2340+
<span data-ty> Executed TokenModule#MyToken</span>
2341+
<span data-ty>&nbsp;</span>
2342+
<span data-ty>Batch #2</span>
2343+
<span data-ty> Executed TokenModule#MyToken.mint</span>
2344+
<span data-ty>&nbsp;</span>
2345+
<span data-ty>[ TokenModule ] successfully deployed 🚀</span>
2346+
<span data-ty>&nbsp;</span>
2347+
<span data-ty>Deployed Addresses</span>
2348+
<span data-ty>&nbsp;</span>
2349+
<span data-ty>TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3</span>
2350+
</div>
2351+
2352+
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+
21702369
---
21712370

21722371
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
21872386

21882387
Before starting, make sure you have:
21892388

2389+
- Basic understanding of Solidity programming and fungible tokens.
21902390
- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}.
21912391
- 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.
21932392

21942393
## Create Your Contract
21952394

@@ -2924,7 +3123,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP
29243123

29253124
- Basic understanding of Solidity programming and NFT standards.
29263125
- 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}.
29283127
- A wallet with a private key for signing transactions.
29293128

29303129
## Set Up Your Project

0 commit comments

Comments
 (0)