diff --git a/.ai/categories/basics.md b/.ai/categories/basics.md index be88860cb..f6a53dc1c 100644 --- a/.ai/categories/basics.md +++ b/.ai/categories/basics.md @@ -2167,6 +2167,205 @@ Several SCALE codec implementations are available in various languages. Here's a - **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} +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- 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 Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -2924,7 +3123,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -8032,6 +8231,131 @@ tail -f /tmp/zombie-794af21178672e1ff32c612c3c7408dc_-2397036-6717MXDxcS55/alic After running this command, you will see the logs of the `alice` node in real-time, which can be useful for debugging purposes. The logs of the `bob` and `collator01` nodes can be checked similarly. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/dapps.md b/.ai/categories/dapps.md index 481cbe15f..d6dfa2166 100644 --- a/.ai/categories/dapps.md +++ b/.ai/categories/dapps.md @@ -2779,6 +2779,205 @@ const unsub = await client.tx.balances For more detailed information about Dedot, check the [official documentation](https://dedot.dev/){target=\_blank}. +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -2799,9 +2998,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -3536,7 +3735,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -11430,6 +11629,131 @@ To submit a transaction, you must construct an extrinsic, sign it with your priv Now that you've covered the basics dive into the official [subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/infrastructure.md b/.ai/categories/infrastructure.md index 305a83525..f7e917001 100644 --- a/.ai/categories/infrastructure.md +++ b/.ai/categories/infrastructure.md @@ -2168,6 +2168,205 @@ Several SCALE codec implementations are available in various languages. Here's a - **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} +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -2188,9 +2387,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -2925,7 +3124,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -11551,6 +11750,131 @@ To unbond tokens, go to **Network > Staking > Account Actions** on Polkadot.js A Once the unbonding period is complete, your tokens will be available for use in transactions or transfers outside of staking. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/networks.md b/.ai/categories/networks.md index 28c6d88b7..6801f35c5 100644 --- a/.ai/categories/networks.md +++ b/.ai/categories/networks.md @@ -2168,6 +2168,205 @@ Several SCALE codec implementations are available in various languages. Here's a - **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} +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -2188,9 +2387,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -2925,7 +3124,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -9272,6 +9471,131 @@ tail -f /tmp/zombie-794af21178672e1ff32c612c3c7408dc_-2397036-6717MXDxcS55/alic After running this command, you will see the logs of the `alice` node in real-time, which can be useful for debugging purposes. The logs of the `bob` and `collator01` nodes can be checked similarly. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/parachains.md b/.ai/categories/parachains.md index 7348ba718..f883c0299 100644 --- a/.ai/categories/parachains.md +++ b/.ai/categories/parachains.md @@ -4512,6 +4512,205 @@ Several SCALE codec implementations are available in various languages. Here's a - **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} +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -4532,9 +4731,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -5269,7 +5468,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -17526,6 +17725,131 @@ The primary trade-off is increased implementation complexity, as you must manage For a complete implementation example of multi-block migrations, refer to the [official example](https://github.com/paritytech/polkadot-sdk/tree/polkadot-stable2506-2/substrate/frame/examples/multi-block-migrations){target=\_blank} in the Polkadot SDK. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/polkadot-protocol.md b/.ai/categories/polkadot-protocol.md index 1da5e8aee..8321df8a9 100644 --- a/.ai/categories/polkadot-protocol.md +++ b/.ai/categories/polkadot-protocol.md @@ -2577,6 +2577,205 @@ Several SCALE codec implementations are available in various languages. Here's a - **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} +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -2597,9 +2796,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -3334,7 +3533,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -10228,6 +10427,131 @@ tail -f /tmp/zombie-794af21178672e1ff32c612c3c7408dc_-2397036-6717MXDxcS55/alic After running this command, you will see the logs of the `alice` node in real-time, which can be useful for debugging purposes. The logs of the `bob` and `collator01` nodes can be checked similarly. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/reference.md b/.ai/categories/reference.md index 9b259cf0b..a2ce3408f 100644 --- a/.ai/categories/reference.md +++ b/.ai/categories/reference.md @@ -1240,6 +1240,131 @@ If an error occurs, the response will include an error object: ``` +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: XCM Config diff --git a/.ai/categories/smart-contracts.md b/.ai/categories/smart-contracts.md index 65cacb7c7..946b50a80 100644 --- a/.ai/categories/smart-contracts.md +++ b/.ai/categories/smart-contracts.md @@ -4401,6 +4401,205 @@ Your deployed contract will appear in the **Deployed Contracts** section, ready +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -4421,9 +4620,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -5158,7 +5357,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -14391,6 +14590,131 @@ tail -f /tmp/zombie-794af21178672e1ff32c612c3c7408dc_-2397036-6717MXDxcS55/alic After running this command, you will see the logs of the `alice` node in real-time, which can be useful for debugging purposes. The logs of the `bob` and `collator01` nodes can be checked similarly. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Testing and Debugging diff --git a/.ai/categories/tooling.md b/.ai/categories/tooling.md index 23ea85110..8b5870604 100644 --- a/.ai/categories/tooling.md +++ b/.ai/categories/tooling.md @@ -3938,6 +3938,205 @@ const unsub = await client.tx.balances For more detailed information about Dedot, check the [official documentation](https://dedot.dev/){target=\_blank}. +--- + +Page Title: Deploy an ERC-20 to Polkadot Hub + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md +- Canonical (HTML): https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
+ + --- Page Title: Deploy an ERC-20 to Polkadot Hub @@ -3958,9 +4157,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract @@ -4695,7 +4894,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project @@ -19925,6 +20124,131 @@ To submit a transaction, you must construct an extrinsic, sign it with your priv Now that you've covered the basics dive into the official [subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features. +--- + +Page Title: Technical Reference Overview + +- Source (raw): https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md +- Canonical (HTML): https://docs.polkadot.com/reference/ +- Summary: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. + +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
+ + --- Page Title: Test and Deploy with Hardhat diff --git a/.ai/pages/reference.md b/.ai/pages/reference.md index d05701a93..59bc64741 100644 --- a/.ai/pages/reference.md +++ b/.ai/pages/reference.md @@ -1,5 +1,122 @@ --- +title: Technical Reference Overview +description: Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. +categories: Basics, Polkadot Protocol, Reference url: https://docs.polkadot.com/reference/ --- -TODO +## Introduction + +The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need. + +Polkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\_blank} to the [governance](/reference/glossary#governance){target=\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants. + +This guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem. + +## Polkadot Hub + +[Polkadot Hub](/reference/polkadot-hub/){target=\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain. + +The Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include: + +- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications. +- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem. +- **Staking**: Participate in network security and earn rewards by staking DOT. +- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov. +- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities. +- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem. +- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations. + +## Parachains + +[Parachains](/reference/parachains/){target=\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers: + +- **Accounts**: Deep dive into account types, storage, and management on parachains. +- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms. +- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus. +- **Chain data**: Explore data structures, storage layouts, and state management. +- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains. +- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility. +- **Networks**: Learn about networking protocols and peer-to-peer communication. +- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\_blank}, the standard for cross-chain communication. +- **Randomness**: Understand how randomness is generated and used in Polkadot chains. +- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. + +## On-Chain Governance + +[On-Chain governance](/reference/governance/){target=\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details: + +- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums. +- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity. +- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance. +- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system. + +## Glossary + +The [Glossary](/reference/glossary/){target=\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include: + +- Blockchain concepts (blocks, transactions, state) +- Consensus mechanisms (validators, collators, finality) +- Polkadot-specific terms (relay chain, parachain, XCM, FRAME) +- Network components (nodes, runtimes, storage) +- Governance terminology (origins, tracks, referendums) + +## Tools + +The [Tools](/reference/tools/){target=\_blank} section documents essential development and interaction tools for the Polkadot ecosystem: + +- **Light clients**: Lightweight solutions for interacting with the network without running full nodes. +- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank} and [PAPI](/reference/tools/papi/){target=\_blank} for building applications. +- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\_blank} and other Rust-based libraries for SDK development. +- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\_blank} for Python developers. +- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\_blank}, and [Omninode](/reference/tools/omninode/){target=\_blank} for smart contract and parachain testing. +- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\_blank} for substrate interaction. +- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\_blank} for XCM integration and asset transfers. + +## Where to Go Next + +For detailed exploration of specific areas, proceed to any of the main sections: + +
+ +- Learn **Polkadot Hub** + + --- + + Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance. + + [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/) + +- Learn **Parachains** + + --- + + Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains. + + [:octicons-arrow-right-24: Reference](/reference/parachains/) + +- Learn **On-Chain Governance** + + --- + + Explore Polkadot's decentralized governance framework and how to participate in network decision-making. + + [:octicons-arrow-right-24: Reference](/reference/governance/) + +- Guide **Glossary** + + --- + + Quick reference for Polkadot-specific terminology and concepts used throughout the documentation. + + [:octicons-arrow-right-24: Reference](/reference/glossary/) + +- Guide **Tools** + + --- + + Discover development tools, libraries, and frameworks for building and interacting with Polkadot. + + [:octicons-arrow-right-24: Reference](/reference/tools/) + +
diff --git a/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md new file mode 100644 index 000000000..f0eadd1f2 --- /dev/null +++ b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md @@ -0,0 +1,196 @@ +--- +title: Deploy an ERC-20 to Polkadot Hub +description: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. +categories: Basics, Smart Contracts +url: https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/ +--- + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" + +const config: HardhatUserConfig = { + solidity: { + version: "0.8.28", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + networks: { + polkadotTestnet: { + url: vars.get("TESTNET_URL", "http://127.0.0.1:8545"), + accounts: vars.has("TESTNET_PRIVATE_KEY") ? [vars.get("TESTNET_PRIVATE_KEY")] : [], + }, + }, + mocha: { + timeout: 40000, + }, +}; + +export default config; +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
diff --git a/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md index 7c1ea6730..1d2a03cb9 100644 --- a/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md +++ b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md @@ -17,9 +17,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract diff --git a/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat.md b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat.md index 616fab753..6c91edea7 100644 --- a/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat.md +++ b/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat.md @@ -17,7 +17,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project diff --git a/.ai/site-index.json b/.ai/site-index.json index ac7cb0c85..d66db54c9 100644 --- a/.ai/site-index.json +++ b/.ai/site-index.json @@ -9835,22 +9835,60 @@ }, { "id": "reference", - "title": "reference", + "title": "Technical Reference Overview", "slug": "reference", "categories": [ - "Uncategorized" + "Basics", + "Polkadot Protocol", + "Reference" ], "raw_md_url": "https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md", "html_url": "https://docs.polkadot.com/reference/", - "preview": "TODO", - "outline": [], + "preview": "The Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need.", + "outline": [ + { + "depth": 2, + "title": "Introduction", + "anchor": "introduction" + }, + { + "depth": 2, + "title": "Polkadot Hub", + "anchor": "polkadot-hub" + }, + { + "depth": 2, + "title": "Parachains", + "anchor": "parachains" + }, + { + "depth": 2, + "title": "On-Chain Governance", + "anchor": "on-chain-governance" + }, + { + "depth": 2, + "title": "Glossary", + "anchor": "glossary" + }, + { + "depth": 2, + "title": "Tools", + "anchor": "tools" + }, + { + "depth": 2, + "title": "Where to Go Next", + "anchor": "where-to-go-next" + } + ], "stats": { - "chars": 5, - "words": 1, - "headings": 0, - "estimated_token_count_total": 0 + "chars": 7648, + "words": 937, + "headings": 7, + "estimated_token_count_total": 1682 }, - "hash": "sha256:56ba36249ea8216ad513b13df3de6c0e490ba214897674d30331f1c7e7edbef3", + "hash": "sha256:9f71f3b4018f7a9e127cff51fab7cfe1168adcde2553cd1fc5dc8c25fb97a30d", "token_estimator": "heuristic-v1" }, { @@ -11028,6 +11066,68 @@ "hash": "sha256:56ba36249ea8216ad513b13df3de6c0e490ba214897674d30331f1c7e7edbef3", "token_estimator": "heuristic-v1" }, + { + "id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", + "title": "Deploy an ERC-20 to Polkadot Hub", + "slug": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", + "categories": [ + "Basics", + "Smart Contracts" + ], + "raw_md_url": "https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md", + "html_url": "https://docs.polkadot.com/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/", + "preview": "[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.", + "outline": [ + { + "depth": 2, + "title": "Introduction", + "anchor": "introduction" + }, + { + "depth": 2, + "title": "Prerequisites", + "anchor": "prerequisites" + }, + { + "depth": 2, + "title": "Set Up Your Project", + "anchor": "set-up-your-project" + }, + { + "depth": 2, + "title": "Configure Hardhat", + "anchor": "configure-hardhat" + }, + { + "depth": 2, + "title": "Compile your Contract", + "anchor": "compile-your-contract" + }, + { + "depth": 2, + "title": "Test your Contract", + "anchor": "test-your-contract" + }, + { + "depth": 2, + "title": "Deploy your Contract", + "anchor": "deploy-your-contract" + }, + { + "depth": 2, + "title": "Where to Go Next", + "anchor": "where-to-go-next" + } + ], + "stats": { + "chars": 8131, + "words": 1205, + "headings": 8, + "estimated_token_count_total": 2156 + }, + "hash": "sha256:4036cb47abaf081ce480654bece336f83bd043f5225d5d8d20f152fb91aa2157", + "token_estimator": "heuristic-v1" + }, { "id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "title": "Deploy an ERC-20 to Polkadot Hub", @@ -11077,12 +11177,12 @@ } ], "stats": { - "chars": 9109, - "words": 1260, + "chars": 9121, + "words": 1261, "headings": 7, - "estimated_token_count_total": 2182 + "estimated_token_count_total": 2183 }, - "hash": "sha256:0cb418d465a51230ece5d3a56d64754f979bc6c4ad78f2cc3df537b99739e627", + "hash": "sha256:992767525da7c1323f28bcaee5b6d1256ee2c0c70dbd16ae521245299858d996", "token_estimator": "heuristic-v1" }, { @@ -11316,12 +11416,12 @@ } ], "stats": { - "chars": 4745, - "words": 550, + "chars": 4837, + "words": 565, "headings": 9, - "estimated_token_count_total": 1137 + "estimated_token_count_total": 1152 }, - "hash": "sha256:f787f9c66787c53aa5c6fccf30d622b2b617794d1292641ea256e0896d418b28", + "hash": "sha256:1e44c9df24715affa822f0df9680413cd995909f2c086d3a70499ee69901985e", "token_estimator": "heuristic-v1" }, { diff --git a/.gitignore b/.gitignore index 7f7d81496..61f0d073d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ node_modules .vscode target .DS_Store -scripts/__pycache__/* \ No newline at end of file +scripts/__pycache__/* + +.github/instructions/kluster-code-verify.instructions.md +.kluster diff --git a/llms-full.jsonl b/llms-full.jsonl index 1f5ab24b0..b6e49669f 100644 --- a/llms-full.jsonl +++ b/llms-full.jsonl @@ -1234,6 +1234,13 @@ {"page_id": "reference-tools-xcm-tools", "page_title": "XCM Tools", "index": 4, "depth": 3, "title": "Astar XCM Tools", "anchor": "astar-xcm-tools", "start_char": 2667, "end_char": 4207, "estimated_token_count": 369, "token_estimator": "heuristic-v1", "text": "### Astar XCM Tools\n\nThe [Astar parachain](https://github.com/AstarNetwork/Astar/tree/master){target=\\_blank} offers a crate with a set of utilities for interacting with the XCM protocol. The [xcm-tools](https://github.com/AstarNetwork/Astar/tree/master/bin/xcm-tools){target=\\_blank} crate provides a straightforward method for users to locate a sovereign account or calculate an XC20 asset ID. Some commands included by the xcm-tools crate allow users to perform the following tasks:\n\n- **Sovereign accounts**: Obtain the sovereign account address for any parachain, either on the Relay Chain or for sibling parachains, using a simple command.\n- **XC20 EVM addresses**: Generate XC20-compatible Ethereum addresses for assets by entering the asset ID, making it easy to integrate assets across Ethereum-compatible environments.\n- **Remote accounts**: Retrieve remote account addresses needed for multi-location compatibility, using flexible options to specify account types and parachain IDs.\n\nTo start using these tools, clone the [Astar repository](https://github.com/AstarNetwork/Astar){target=\\_blank} and compile the xcm-tools package:\n\n```bash\ngit clone https://github.com/AstarNetwork/Astar &&\ncd Astar &&\ncargo build --release -p xcm-tools\n```\n\nAfter compiling, verify the setup with the following command:\n\n```bash\n./target/release/xcm-tools --help\n```\nFor more details on using Astar xcm-tools, consult the [official documentation](https://docs.astar.network/docs/learn/interoperability/xcm/integration/tools/){target=\\_blank}."} {"page_id": "reference-tools-xcm-tools", "page_title": "XCM Tools", "index": 5, "depth": 3, "title": "Chopsticks", "anchor": "chopsticks", "start_char": 4207, "end_char": 4517, "estimated_token_count": 65, "token_estimator": "heuristic-v1", "text": "### Chopsticks\n\nThe Chopsticks library provides XCM functionality for testing XCM messages across networks, enabling you to fork multiple parachains along with a relay chain. For further details, see the [Chopsticks documentation](/tutorials/polkadot-sdk/testing/fork-live-chains/){target=\\_blank} about XCM."} {"page_id": "reference-tools-xcm-tools", "page_title": "XCM Tools", "index": 6, "depth": 3, "title": "Moonbeam XCM SDK", "anchor": "moonbeam-xcm-sdk", "start_char": 4517, "end_char": 6146, "estimated_token_count": 385, "token_estimator": "heuristic-v1", "text": "### Moonbeam XCM SDK\n\nThe [Moonbeam XCM SDK](https://github.com/moonbeam-foundation/xcm-sdk){target=\\_blank} enables developers to easily transfer assets between chains, either between parachains or between a parachain and the relay chain, within the Polkadot/Kusama ecosystem. With the SDK, you don't need to worry about determining the [Multilocation](https://github.com/polkadot-fellows/xcm-format?tab=readme-ov-file#7-universal-consensus-location-identifiers){target=\\_blank} of the origin or destination assets or which extrinsics are used on which networks.\n\nThe SDK consists of two main packages:\n\n- **[XCM SDK](https://github.com/moonbeam-foundation/xcm-sdk/tree/main/packages/sdk){target=\\_blank}**: Core SDK for executing XCM transfers between chains in the Polkadot/Kusama ecosystem.\n- **[MRL SDK](https://github.com/moonbeam-foundation/xcm-sdk/tree/main/packages/mrl){target=\\_blank}**: Extension of the XCM SDK for transferring liquidity into and across the Polkadot ecosystem from other ecosystems like Ethereum.\n\nKey features include:\n\n- **Simplified asset transfers**: Abstracts away complex multilocation determinations and extrinsic selection.\n- **Cross-ecosystem support**: Enables transfers between Polkadot/Kusama chains and external ecosystems.\n- **Developer-friendly API**: Provides intuitive interfaces for cross-chain functionality.\n- **Comprehensive documentation**: Includes usage guides and API references for both packages.\n\nFor detailed usage examples and API documentation, visit the [official Moonbeam XCM SDK documentation](https://moonbeam-foundation.github.io/xcm-sdk/latest/){target=\\_blank}."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 0, "end_char": 1097, "estimated_token_count": 199, "token_estimator": "heuristic-v1", "text": "## Introduction\n\nThe Technical Reference section provides comprehensive documentation of Polkadot's architecture, core concepts, and development tooling. Whether you're exploring how Polkadot's relay chain coordinates parachains, understanding governance mechanisms, or building applications on the network, this reference covers the technical foundations you need.\n\nPolkadot is a multi-chain network that enables diverse, interconnected blockchains to share security and communicate seamlessly. Understanding how these components interact from the [relay chain](/polkadot-protocol/glossary#relay-chain){target=\\_blank} that validates [parachains](/polkadot-protocol/glossary#parachain){target=\\_blank} to the [governance](/reference/glossary#governance){target=\\_blank} mechanisms that evolve the protocol is essential for developers, validators, and network participants.\n\nThis guide organizes technical documentation across five core areas: Polkadot Hub, Parachains, On-Chain Governance, Glossary, and Tools, each providing detailed information on different aspects of the Polkadot ecosystem."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 1, "depth": 2, "title": "Polkadot Hub", "anchor": "polkadot-hub", "start_char": 1097, "end_char": 2378, "estimated_token_count": 247, "token_estimator": "heuristic-v1", "text": "## Polkadot Hub\n\n[Polkadot Hub](/reference/polkadot-hub/){target=\\_blank} is the entry point to Polkadot for all users and application developers. It provides access to essential Web3 services, including smart contracts, staking, governance, identity management, and cross-ecosystem interoperability—without requiring you to deploy or manage a parachain.\n\nThe Hub encompasses a set of core functionality that enables developers and users to build and interact with applications on Polkadot. Key capabilities include:\n\n- **Smart contracts**: Deploy Ethereum-compatible smart contracts and build decentralized applications.\n- **Assets and tokens**: Create, manage, and transfer fungible tokens and NFTs across the ecosystem.\n- **Staking**: Participate in network security and earn rewards by staking DOT.\n- **Governance**: Vote on proposals and participate in Polkadot's decentralized decision-making through OpenGov.\n- **Identity services**: Register and manage on-chain identities, enabling access to governance roles and network opportunities.\n- **Cross-chain interoperability**: Leverage XCM messaging to interact securely with other chains in the Polkadot ecosystem.\n- **Collectives and DAOs**: Participate in governance collectives and decentralized autonomous organizations."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 2, "depth": 2, "title": "Parachains", "anchor": "parachains", "start_char": 2378, "end_char": 3697, "estimated_token_count": 293, "token_estimator": "heuristic-v1", "text": "## Parachains\n\n[Parachains](/reference/parachains/){target=\\_blank} are specialized blockchains that connect to the Polkadot relay chain, inheriting its security while maintaining their own application-specific logic. The parachains documentation covers:\n\n- **Accounts**: Deep dive into account types, storage, and management on parachains.\n- **Blocks, transactions and fees**: Understand block production, transaction inclusion, and fee mechanisms.\n- **Consensus**: Learn how parachain blocks are validated and finalized through the relay chain's consensus.\n- **Chain data**: Explore data structures, storage layouts, and state management.\n- **Cryptography**: Study cryptographic primitives used in Polkadot SDK-based chains.\n- **Data encoding**: Understand how data is encoded and decoded for blockchain compatibility.\n- **Networks**: Learn about networking protocols and peer-to-peer communication.\n- **Interoperability**: Discover [Cross-Consensus Messaging (XCM)](/parachains/interoperability/get-started/){target=\\_blank}, the standard for cross-chain communication.\n- **Randomness**: Understand how randomness is generated and used in Polkadot chains.\n- **Node and runtime**: Learn about parachain nodes, runtime environments, and the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\\_blank}."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 3, "depth": 2, "title": "On-Chain Governance", "anchor": "on-chain-governance", "start_char": 3697, "end_char": 4577, "estimated_token_count": 170, "token_estimator": "heuristic-v1", "text": "## On-Chain Governance\n\n[On-Chain governance](/reference/governance/){target=\\_blank} is the decentralized decision-making mechanism for the Polkadot network. It manages the evolution and modification of the network's runtime logic, enabling community oversight and approval for proposed changes. The governance documentation details:\n\n- **OpenGov framework**: Understand Polkadot's next-generation governance system with enhanced delegation, flexible tracks, and simultaneous referendums.\n- **Origins and tracks**: Learn how governance proposals are categorized, prioritized, and executed based on their privilege level and complexity.\n- **Voting and delegation**: Explore conviction voting, vote delegation, and how token holders participate in governance.\n- **Governance evolution**: See how Polkadot's governance has evolved from Governance V1 to the current OpenGov system."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 4, "depth": 2, "title": "Glossary", "anchor": "glossary", "start_char": 4577, "end_char": 5018, "estimated_token_count": 90, "token_estimator": "heuristic-v1", "text": "## Glossary\n\nThe [Glossary](/reference/glossary/){target=\\_blank} provides quick-reference definitions for Polkadot-specific terminology. Essential terms include:\n\n- Blockchain concepts (blocks, transactions, state)\n- Consensus mechanisms (validators, collators, finality)\n- Polkadot-specific terms (relay chain, parachain, XCM, FRAME)\n- Network components (nodes, runtimes, storage)\n- Governance terminology (origins, tracks, referendums)"} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 5, "depth": 2, "title": "Tools", "anchor": "tools", "start_char": 5018, "end_char": 6285, "estimated_token_count": 349, "token_estimator": "heuristic-v1", "text": "## Tools\n\nThe [Tools](/reference/tools/){target=\\_blank} section documents essential development and interaction tools for the Polkadot ecosystem:\n\n- **Light clients**: Lightweight solutions for interacting with the network without running full nodes.\n- **JavaScript/TypeScript tools**: Libraries like [Polkadot.js API](/reference/tools/polkadot-js-api/){target=\\_blank} and [PAPI](/reference/tools/papi/){target=\\_blank} for building applications.\n- **Rust tools**: [Polkadart](/reference/tools/polkadart/){target=\\_blank} and other Rust-based libraries for SDK development.\n- **Python tools**: [py-substrate-interface](/reference/tools/py-substrate-interface/){target=\\_blank} for Python developers.\n- **Testing and development**: Tools like [Moonwall](/reference/tools/moonwall/){target=\\_blank}, [Chopsticks](/reference/tools/chopsticks/){target=\\_blank}, and [Omninode](/reference/tools/omninode/){target=\\_blank} for smart contract and parachain testing.\n- **Indexing and monitoring**: [Sidecar](/reference/tools/sidecar/){target=\\_blank} for data indexing and [Dedot](/reference/tools/dedot/){target=\\_blank} for substrate interaction.\n- **Cross-chain tools**: [ParaSpell](/reference/tools/paraspell/){target=\\_blank} for XCM integration and asset transfers."} +{"page_id": "reference", "page_title": "Technical Reference Overview", "index": 6, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 6285, "end_char": 7648, "estimated_token_count": 334, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\nFor detailed exploration of specific areas, proceed to any of the main sections:\n\n
\n\n- Learn **Polkadot Hub**\n\n ---\n\n Understand the relay chain's role in coordinating parachains, providing shared security, and enabling governance.\n\n [:octicons-arrow-right-24: Reference](/reference/polkadot-hub/)\n\n- Learn **Parachains**\n\n ---\n\n Deep dive into parachain architecture, consensus, data structures, and building application-specific blockchains.\n\n [:octicons-arrow-right-24: Reference](/reference/parachains/)\n\n- Learn **On-Chain Governance**\n\n ---\n\n Explore Polkadot's decentralized governance framework and how to participate in network decision-making.\n\n [:octicons-arrow-right-24: Reference](/reference/governance/)\n\n- Guide **Glossary**\n\n ---\n\n Quick reference for Polkadot-specific terminology and concepts used throughout the documentation.\n\n [:octicons-arrow-right-24: Reference](/reference/glossary/)\n\n- Guide **Tools**\n\n ---\n\n Discover development tools, libraries, and frameworks for building and interacting with Polkadot.\n\n [:octicons-arrow-right-24: Reference](/reference/tools/)\n\n
"} {"page_id": "smart-contracts-connect", "page_title": "Connect to Polkadot", "index": 0, "depth": 2, "title": "Networks Details", "anchor": "networks-details", "start_char": 951, "end_char": 1604, "estimated_token_count": 137, "token_estimator": "heuristic-v1", "text": "## Networks Details\n\nDevelopers can leverage smart contracts across diverse networks, from TestNets to MainNet. This section outlines the network specifications and connection details for each environment.\n\n=== \"Polkadot Hub TestNet\"\n\n Network name\n\n ```text\n Polkadot Hub TestNet\n ```\n\n ---\n\n Currency symbol\n \n ```text\n PAS\n ```\n\n ---\n \n Chain ID\n \n ```text\n 420420422\n ```\n\n ---\n \n RPC URL\n \n ```text\n https://testnet-passet-hub-eth-rpc.polkadot.io\n ```\n\n ---\n \n Block explorer URL\n \n ```text\n https://blockscout-passet-hub.parity-testnet.parity.io/\n ```"} {"page_id": "smart-contracts-connect", "page_title": "Connect to Polkadot", "index": 1, "depth": 2, "title": "Test Tokens", "anchor": "test-tokens", "start_char": 1604, "end_char": 2618, "estimated_token_count": 233, "token_estimator": "heuristic-v1", "text": "## Test Tokens\n\nYou will need testnet tokens to perform transactions and engage with smart contracts on any chain. Here's how to obtain Paseo (PAS) tokens for testing purposes:\n\n1. Navigate to the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\\_blank}. If the desired network is not already selected, choose it from the Network drop-down.\n\n2. Copy your address linked to the TestNet and paste it into the designated field.\n\n ![](/images/smart-contracts/connect/connect-to-polkadot-01.webp)\n\n3. Click the **Get Some PASs** button to request free test PAS tokens. These tokens will be sent to your wallet shortly.\n\n ![](/images/smart-contracts/connect/connect-to-polkadot-02.webp)\n\nNow that you have obtained PAS tokens in your wallet, you’re ready to deploy and interact with smart contracts on Polkadot Hub TestNet! These tokens will allow you to pay for gas fees when executing transactions, deploying contracts, and testing your dApp functionality in a secure testnet environment."} {"page_id": "smart-contracts-connect", "page_title": "Connect to Polkadot", "index": 2, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 2618, "end_char": 3459, "estimated_token_count": 188, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\nFor your next steps, explore the various smart contract guides demonstrating how to use and integrate different tools and development environments into your workflow.\n\n
\n\n- Guide __Deploy your first contract with Remix__\n\n ---\n\n Explore the smart contract development and deployment process on Polkadot Hub using the Remix IDE.\n\n [:octicons-arrow-right-24: Build with Remix IDE](/smart-contracts/dev-environments/remix/get-started/)\n\n- Guide __Interact with the blockchain with viem__\n\n ---\n\n Use viem for interacting with Ethereum-compatible chains, to deploy and interact with smart contracts on Polkadot Hub.\n\n [:octicons-arrow-right-24: Build with viem](/smart-contracts/libraries/viem/)\n\n
"} @@ -1389,13 +1396,21 @@ {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-basic-remix", "page_title": "Deploy a Basic Contract with Remix IDE", "index": 3, "depth": 2, "title": "Compile", "anchor": "compile", "start_char": 1290, "end_char": 1639, "estimated_token_count": 94, "token_estimator": "heuristic-v1", "text": "## Compile\n\n1. Navigate to the **Solidity Compiler** tab, which is the third icon in the left sidebar.\n2. Click **Compile Storage.sol** or press `Ctrl+S`.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-02.webp)\n\nCompilation errors and warnings appear in the terminal panel at the bottom of the screen."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-basic-remix", "page_title": "Deploy a Basic Contract with Remix IDE", "index": 4, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 1639, "end_char": 2128, "estimated_token_count": 122, "token_estimator": "heuristic-v1", "text": "## Deploy\n\n1. Navigate to the **Deploy & Run Transactions** tab.\n2. Click the **Environment** dropdown and select **Injected Provider - MetaMask** (ensure your MetaMask wallet is connected to Polkadot Hub TestNet).\n3. Click **Deploy**.\n4. Approve the transaction in your MetaMask wallet.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-03.webp)\n\nYour deployed contract will appear in the **Deployed Contracts** section, ready for interaction."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-basic-remix", "page_title": "Deploy a Basic Contract with Remix IDE", "index": 5, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 2128, "end_char": 2978, "estimated_token_count": 228, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Verify Your Contract__\n\n ---\n\n Now that you've deployed a basic contract, learn how to verify it with Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/remix/verify-a-contract/)\n\n- Guide __Deploy an ERC-20__\n\n ---\n\n Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/remix/)\n\n- Guide __Deploy an NFT__\n\n ---\n\n Walk through deploying a NFT to the Polkadot Hub using Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) \n\n
"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 36, "end_char": 781, "estimated_token_count": 183, "token_estimator": "heuristic-v1", "text": "## Introduction\n\n[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.\n\nThis 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}."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 781, "end_char": 1233, "estimated_token_count": 114, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore starting, make sure you have:\n\n- Basic understanding of Solidity programming and fungible tokens.\n- Node.js v22.13.1 or later.\n- 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}."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 2, "depth": 2, "title": "Set Up Your Project", "anchor": "set-up-your-project", "start_char": 1233, "end_char": 1831, "estimated_token_count": 146, "token_estimator": "heuristic-v1", "text": "## Set Up Your Project\n\nThis 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:\n\n1. Clone the GitHub repository locally:\n\n ```bash\n git clone https://github.com/polkadot-developers/revm-hardhat-examples/\n cd revm-hardhat-examples/erc20-hardhat\n ```\n\n2. Install the dependencies:\n\n ```bash\n npm i\n ```\n\nThis will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 3, "depth": 2, "title": "Configure Hardhat", "anchor": "configure-hardhat", "start_char": 1831, "end_char": 3522, "estimated_token_count": 423, "token_estimator": "heuristic-v1", "text": "## Configure Hardhat\n\nOnce 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.\n\nTo 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:\n\n```bash\nnpx hardhat vars set TESTNET_PRIVATE_KEY\n```\n\nThe command will initiate a wizard in which you'll have to enter the value to be stored:\n\n
\n npx hardhat vars set TESTNET_PRIVATE_KEY\n ✔ Enter value: · •••••••••\n The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json\n
\n\n??? warning \"Key Encryption\"\n 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.\n\nYou can now use the account related to this private key by importing it into the Hardhat configuration file:\n\n```ts title=\"hardhat.config.ts\" hl_lines=\"1 17\"\n\nconst config: HardhatUserConfig = {\n solidity: {\n version: \"0.8.28\",\n settings: {\n optimizer: {\n enabled: true,\n runs: 200,\n },\n },\n },\n networks: {\n polkadotTestnet: {\n url: vars.get(\"TESTNET_URL\", \"http://127.0.0.1:8545\"),\n accounts: vars.has(\"TESTNET_PRIVATE_KEY\") ? [vars.get(\"TESTNET_PRIVATE_KEY\")] : [],\n },\n },\n mocha: {\n timeout: 40000,\n },\n};\n\nexport default config;\n```"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 4, "depth": 2, "title": "Compile your Contract", "anchor": "compile-your-contract", "start_char": 3522, "end_char": 4188, "estimated_token_count": 163, "token_estimator": "heuristic-v1", "text": "## Compile your Contract\n\nOnce you've configured Hardhat, you can compile the contract. \n\nIn this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command:\n\n```bash\nnpx hardhat compile\n```\n\nIf everything compiles successfully, you should see the following output:\n\n
\n npx hardhat compile\n Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6\n Successfully generated 62 typings!\n Compiled 21 Solidity files successfully (evm target: paris).\n
"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 5, "depth": 2, "title": "Test your Contract", "anchor": "test-your-contract", "start_char": 4188, "end_char": 6239, "estimated_token_count": 612, "token_estimator": "heuristic-v1", "text": "## Test your Contract\n\nHardhat 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\n\nThis 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:\n\n1. The token was deployed by verifying its **name** and **symbol**.\n2. The token has the right owner configured.\n3. The token has an initial supply of zero.\n4. The owner can mint tokens.\n5. The total supply is increased after a mint.\n6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply.\n\nTo run the test, you can execute the following command:\n\n```bash\nnpx hardhat test --network polkadotTestnet\n```\n\nIf tests are successful, you should see the following logs:\n\n
\n npx hardhat test --network polkadotTestnet\n \n   MyToken\n     Deployment\n       ✔ Should have correct name and symbol\n       ✔ Should set the right owner\n       ✔ Should have zero initial supply\n     Minting\n       ✔ Should allow owner to mint tokens\n       ✔ Should increase total supply on mint\n     Multiple mints\n       ✔ Should correctly track balance after multiple mints\n \n   6 passing (369ms)\n
"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 6, "depth": 2, "title": "Deploy your Contract", "anchor": "deploy-your-contract", "start_char": 6239, "end_char": 7751, "estimated_token_count": 414, "token_estimator": "heuristic-v1", "text": "## Deploy your Contract\n\nWith 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.\n\nTo deploy the contract, run the following command:\n\n```bash\nnpx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet\n```\n\nYou'll need to confirm the target network (by chain ID):\n\n
\n npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet\n ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes\n  \n Hardhat Ignition 🚀\n  \n Deploying [ TokenModule ]\n  \n Batch #1\n Executed TokenModule#MyToken\n  \n Batch #2\n Executed TokenModule#MyToken.mint\n  \n [ TokenModule ] successfully deployed 🚀\n  \n Deployed Addresses\n  \n TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3\n
\n\nAnd that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 7, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 7751, "end_char": 8131, "estimated_token_count": 101, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Deploy an NFT with Remix__\n\n ---\n\n Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/)\n\n
"} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 36, "end_char": 783, "estimated_token_count": 188, "token_estimator": "heuristic-v1", "text": "## Introduction\n\n[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.\n\nThis tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Remix IDE](https://remix.ethereum.org/){target=\\_blank}, a web-based development tool. 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}."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 783, "end_char": 1377, "estimated_token_count": 153, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore starting, make sure you have:\n\n- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\\_blank}.\n- 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}.\n- Basic understanding of Solidity and fungible tokens."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 2, "depth": 2, "title": "Create Your Contract", "anchor": "create-your-contract", "start_char": 1377, "end_char": 5589, "estimated_token_count": 1029, "token_estimator": "heuristic-v1", "text": "## Create Your Contract\n\nTo create the ERC-20 contract, you can follow the steps below:\n\n1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\\_blank}.\n2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`.\n\n ![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-1.webp)\n\n3. Now, paste the following ERC-20 contract code into the editor:\n\n ```solidity title=\"MyToken.sol\"\n // SPDX-License-Identifier: MIT\n // Compatible with OpenZeppelin Contracts ^5.4.0\n pragma solidity ^0.8.27;\n\n import {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n import {ERC20Permit} from \"@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol\";\n import {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\n\n contract MyToken is ERC20, Ownable, ERC20Permit {\n constructor(address initialOwner)\n ERC20(\"MyToken\", \"MTK\")\n Ownable(initialOwner)\n ERC20Permit(\"MyToken\")\n {}\n\n function mint(address to, uint256 amount) public onlyOwner {\n _mint(to, amount);\n }\n }\n ```\n\n The key components of the code above are:\n\n - Contract imports:\n\n - **[`ERC20.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20/ERC20.sol){target=\\_blank}**: The base contract for fungible tokens, implementing core functionality like transfers, approvals, and balance tracking.\n - **[`ERC20Permit.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20/extensions/ERC20Permit.sol){target=\\_blank}**: [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612){target=\\_blank} extension for ERC-20 that adds the [permit function](https://docs.openzeppelin.com/contracts/5.x/api/token/erc20#ERC20Permit-permit-address-address-uint256-uint256-uint8-bytes32-bytes32-){target=\\_blank}, allowing approvals via off-chain signatures (no on-chain tx from the holder). Manages nonces and EIP-712 domain separator and updates allowances when a valid signature is presented.\n - **[`Ownable.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/access/Ownable.sol){target=\\_blank}**: Provides basic authorization control, ensuring only the contract owner can mint new tokens.\n \n - Constructor parameters:\n\n - **`initialOwner`**: Sets the address that will have administrative rights over the contract.\n - **`\"MyToken\"`**: The full name of your token.\n - **`\"MTK\"`**: The symbol representing your token in wallets and exchanges.\n\n - Key functions:\n\n - **`mint(address to, uint256 amount)`**: Allows the contract owner to create new tokens for any address. The amount should include 18 decimals (e.g., 1 token = 1000000000000000000).\n - Inherited [Standard ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/){target=\\_blank} functions:\n - **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address.\n - **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner.\n - **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved.\n - **`balanceOf(address account)`**: Returns the token balance of a specific address.\n - **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address.\n\n !!! tip\n Use the [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\\_blank} to generate customized smart contracts quickly. Simply configure your contract, copy the generated code, and paste it into the Remix IDE for deployment. Below is an example of an ERC-20 token contract created with it:\n\n ![Screenshot of the OpenZeppelin Contracts Wizard showing an ERC-20 contract configuration.](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-2.webp)"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 3, "depth": 2, "title": "Compile", "anchor": "compile", "start_char": 5589, "end_char": 6312, "estimated_token_count": 156, "token_estimator": "heuristic-v1", "text": "## Compile \n\nThe compilation transforms your Solidity source code into bytecode that can be deployed on the blockchain. During this process, the compiler checks your contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. \n\nTo compile your contract, ensure you have it opened in the Remix IDE Editor, and follow the instructions below:\n\n1. Select the **Solidity Compiler** plugin from the left panel.\n2. Click the **Compile MyToken.sol** button.\n3. If the compilation succeeded, you'll see a green checkmark indicating success in the **Solidity Compiler** icon.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-3.gif)"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 4, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 6312, "end_char": 7533, "estimated_token_count": 275, "token_estimator": "heuristic-v1", "text": "## Deploy\n\nDeployment is the process of publishing your compiled smart contract to the blockchain, making it permanently available for interaction. During deployment, you'll create a new instance of your contract on the blockchain, which involves:\n\n1. Select the **Deploy & Run Transactions** plugin from the left panel.\n2. Configure the deployment settings:\n 1. From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (check the [Deploying Contracts](/smart-contracts/dev-environments/remix/deploy-a-contract/){target=\\_blank} section of the Remix IDE guide for more details).\n 2. (Optional) From the **ACCOUNT** dropdown, select the acccount you want to use for the deploy.\n\n3. Configure the contract parameters:\n 1. Enter the address that will own the deployed token contract.\n 2. Click the **Deploy** button to initiate the deployment.\n\n4. **MetaMask will pop up**: Review the transaction details. Click **Confirm** to deploy your contract.\n5. If the deployment process succeeded, you will see the transaction details in the terminal, including the contract address and deployment transaction hash.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-4.gif)"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 5, "depth": 2, "title": "Interact with Your Contract", "anchor": "interact-with-your-contract", "start_char": 7533, "end_char": 8729, "estimated_token_count": 280, "token_estimator": "heuristic-v1", "text": "## Interact with Your Contract\n\nOnce deployed, you can interact with your contract through Remix. Find your contract under **Deployed/Unpinned Contracts**, and click it to expand the available methods. In this example, you'll mint some tokens to a given address:\n\n1. Expand the **mint** function:\n 1. Enter the recipient address and the amount (remember to add 18 zeros for 1 whole token).\n 2. Click **transact**.\n\n2. Click **Approve** to confirm the transaction in the MetaMask popup.\n\n3. If the transaction succeeds, you will see a green check mark in the terminal.\n\n4. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-5.gif)\n\n\nOther standard functions you can use:\n\n- **`transfer(address to, uint256 amount)`**: Send tokens to another address.\n- **`approve(address spender, uint256 amount)`**: Allow another address to spend your tokens.\n\nFeel free to explore and interact with the contract's other functions using the same approach: select the method, provide any required parameters, and confirm the transaction in MetaMask when needed."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 6, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 8729, "end_char": 9109, "estimated_token_count": 101, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Deploy an NFT with Remix__\n\n ---\n\n Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/)\n\n
"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 783, "end_char": 1389, "estimated_token_count": 154, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore starting, make sure you have:\n\n- Basic understanding of Solidity programming and fungible tokens.\n- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\\_blank}.\n- 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}."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 2, "depth": 2, "title": "Create Your Contract", "anchor": "create-your-contract", "start_char": 1389, "end_char": 5601, "estimated_token_count": 1029, "token_estimator": "heuristic-v1", "text": "## Create Your Contract\n\nTo create the ERC-20 contract, you can follow the steps below:\n\n1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\\_blank}.\n2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`.\n\n ![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-1.webp)\n\n3. Now, paste the following ERC-20 contract code into the editor:\n\n ```solidity title=\"MyToken.sol\"\n // SPDX-License-Identifier: MIT\n // Compatible with OpenZeppelin Contracts ^5.4.0\n pragma solidity ^0.8.27;\n\n import {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n import {ERC20Permit} from \"@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol\";\n import {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\n\n contract MyToken is ERC20, Ownable, ERC20Permit {\n constructor(address initialOwner)\n ERC20(\"MyToken\", \"MTK\")\n Ownable(initialOwner)\n ERC20Permit(\"MyToken\")\n {}\n\n function mint(address to, uint256 amount) public onlyOwner {\n _mint(to, amount);\n }\n }\n ```\n\n The key components of the code above are:\n\n - Contract imports:\n\n - **[`ERC20.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20/ERC20.sol){target=\\_blank}**: The base contract for fungible tokens, implementing core functionality like transfers, approvals, and balance tracking.\n - **[`ERC20Permit.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20/extensions/ERC20Permit.sol){target=\\_blank}**: [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612){target=\\_blank} extension for ERC-20 that adds the [permit function](https://docs.openzeppelin.com/contracts/5.x/api/token/erc20#ERC20Permit-permit-address-address-uint256-uint256-uint8-bytes32-bytes32-){target=\\_blank}, allowing approvals via off-chain signatures (no on-chain tx from the holder). Manages nonces and EIP-712 domain separator and updates allowances when a valid signature is presented.\n - **[`Ownable.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/access/Ownable.sol){target=\\_blank}**: Provides basic authorization control, ensuring only the contract owner can mint new tokens.\n \n - Constructor parameters:\n\n - **`initialOwner`**: Sets the address that will have administrative rights over the contract.\n - **`\"MyToken\"`**: The full name of your token.\n - **`\"MTK\"`**: The symbol representing your token in wallets and exchanges.\n\n - Key functions:\n\n - **`mint(address to, uint256 amount)`**: Allows the contract owner to create new tokens for any address. The amount should include 18 decimals (e.g., 1 token = 1000000000000000000).\n - Inherited [Standard ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/){target=\\_blank} functions:\n - **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address.\n - **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner.\n - **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved.\n - **`balanceOf(address account)`**: Returns the token balance of a specific address.\n - **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address.\n\n !!! tip\n Use the [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\\_blank} to generate customized smart contracts quickly. Simply configure your contract, copy the generated code, and paste it into the Remix IDE for deployment. Below is an example of an ERC-20 token contract created with it:\n\n ![Screenshot of the OpenZeppelin Contracts Wizard showing an ERC-20 contract configuration.](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-2.webp)"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 3, "depth": 2, "title": "Compile", "anchor": "compile", "start_char": 5601, "end_char": 6324, "estimated_token_count": 156, "token_estimator": "heuristic-v1", "text": "## Compile \n\nThe compilation transforms your Solidity source code into bytecode that can be deployed on the blockchain. During this process, the compiler checks your contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. \n\nTo compile your contract, ensure you have it opened in the Remix IDE Editor, and follow the instructions below:\n\n1. Select the **Solidity Compiler** plugin from the left panel.\n2. Click the **Compile MyToken.sol** button.\n3. If the compilation succeeded, you'll see a green checkmark indicating success in the **Solidity Compiler** icon.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-3.gif)"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 4, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 6324, "end_char": 7545, "estimated_token_count": 275, "token_estimator": "heuristic-v1", "text": "## Deploy\n\nDeployment is the process of publishing your compiled smart contract to the blockchain, making it permanently available for interaction. During deployment, you'll create a new instance of your contract on the blockchain, which involves:\n\n1. Select the **Deploy & Run Transactions** plugin from the left panel.\n2. Configure the deployment settings:\n 1. From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (check the [Deploying Contracts](/smart-contracts/dev-environments/remix/deploy-a-contract/){target=\\_blank} section of the Remix IDE guide for more details).\n 2. (Optional) From the **ACCOUNT** dropdown, select the acccount you want to use for the deploy.\n\n3. Configure the contract parameters:\n 1. Enter the address that will own the deployed token contract.\n 2. Click the **Deploy** button to initiate the deployment.\n\n4. **MetaMask will pop up**: Review the transaction details. Click **Confirm** to deploy your contract.\n5. If the deployment process succeeded, you will see the transaction details in the terminal, including the contract address and deployment transaction hash.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-4.gif)"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 5, "depth": 2, "title": "Interact with Your Contract", "anchor": "interact-with-your-contract", "start_char": 7545, "end_char": 8741, "estimated_token_count": 280, "token_estimator": "heuristic-v1", "text": "## Interact with Your Contract\n\nOnce deployed, you can interact with your contract through Remix. Find your contract under **Deployed/Unpinned Contracts**, and click it to expand the available methods. In this example, you'll mint some tokens to a given address:\n\n1. Expand the **mint** function:\n 1. Enter the recipient address and the amount (remember to add 18 zeros for 1 whole token).\n 2. Click **transact**.\n\n2. Click **Approve** to confirm the transaction in the MetaMask popup.\n\n3. If the transaction succeeds, you will see a green check mark in the terminal.\n\n4. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance.\n\n![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-5.gif)\n\n\nOther standard functions you can use:\n\n- **`transfer(address to, uint256 amount)`**: Send tokens to another address.\n- **`approve(address spender, uint256 amount)`**: Allow another address to spend your tokens.\n\nFeel free to explore and interact with the contract's other functions using the same approach: select the method, provide any required parameters, and confirm the transaction in MetaMask when needed."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 6, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 8741, "end_char": 9121, "estimated_token_count": 101, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Deploy an NFT with Remix__\n\n ---\n\n Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/)\n\n
"} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 206, "end_char": 858, "estimated_token_count": 159, "token_estimator": "heuristic-v1", "text": "## Introduction\n\n[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 via PolkaVM.\n\nThis tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Polkadot Remix IDE](https://remix.polkadot.io){target=\\_blank}, a web-based development tool. [OpenZeppelin's ERC-20 contracts](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20){target=\\_blank} are used for security and compliance."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 858, "end_char": 1455, "estimated_token_count": 155, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\nBefore starting, make sure you have:\n\n- [MetaMask](https://metamask.io/){target=\\_blank} installed and connected to Polkadot Hub. For detailed instructions, see the [Connect Your Wallet](/smart-contracts/integrations/wallets){target=\\_blank} section.\n- A funded account with some PAS tokens (you can get them from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\\_blank}). To learn how to get test tokens, check out the [Test Tokens](/smart-contracts/connect/#test-tokens){target=\\_blank} section.\n- Basic understanding of Solidity and fungible tokens."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-erc20", "page_title": "Deploy an ERC-20 to Polkadot Hub", "index": 2, "depth": 2, "title": "Create the ERC-20 Contract", "anchor": "create-the-erc-20-contract", "start_char": 1455, "end_char": 4913, "estimated_token_count": 823, "token_estimator": "heuristic-v1", "text": "## Create the ERC-20 Contract\n\nTo create the ERC-20 contract, you can follow the steps below:\n\n1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\\_blank}.\n2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`.\n\n ![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/deploy-erc20-1.webp)\n\n3. Now, paste the following ERC-20 contract code into the editor:\n\n ```solidity title=\"MyToken.sol\"\n // SPDX-License-Identifier: MIT\n // Compatible with OpenZeppelin Contracts ^5.0.0\n pragma solidity ^0.8.22;\n\n import {ERC20} from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n import {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\n\n contract MyToken is ERC20, Ownable {\n constructor(address initialOwner)\n ERC20(\"MyToken\", \"MTK\")\n Ownable(initialOwner)\n {}\n\n function mint(address to, uint256 amount) public onlyOwner {\n _mint(to, amount);\n }\n }\n ```\n\n The key components of the code above are:\n\n - Contract imports:\n\n - **[`ERC20.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/token/ERC20/ERC20.sol){target=\\_blank}**: The base contract for fungible tokens, implementing core functionality like transfers, approvals, and balance tracking.\n - **[`Ownable.sol`](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v5.4.0/contracts/access/Ownable.sol){target=\\_blank}**: Provides basic authorization control, ensuring only the contract owner can mint new tokens.\n \n - Constructor parameters:\n\n - **`initialOwner`**: Sets the address that will have administrative rights over the contract.\n - **`\"MyToken\"`**: The full name of your token.\n - **`\"MTK\"`**: The symbol representing your token in wallets and exchanges.\n\n - Key functions:\n\n - **`mint(address to, uint256 amount)`**: Allows the contract owner to create new tokens for any address. The amount should include 18 decimals (e.g., 1 token = 1000000000000000000).\n - Inherited [Standard ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/){target=\\_blank} functions:\n - **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address.\n - **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner.\n - **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved.\n - **`balanceOf(address account)`**: Returns the token balance of a specific address.\n - **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address.\n\n !!! tip\n Use the [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\\_blank} to quickly generate customized smart contracts. Simply configure your contract, copy the generated code, and paste it into Polkadot Remix IDE for deployment. Below is an example of an ERC-20 token contract created with it:\n\n ![Screenshot of the OpenZeppelin Contracts Wizard showing an ERC-20 contract configuration.](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/deploy-erc20-2.webp)"} @@ -1418,14 +1433,14 @@ {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-foundry", "page_title": "Deploy an NFT to Polkadot Hub with Foundry", "index": 6, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 2548, "end_char": 2884, "estimated_token_count": 66, "token_estimator": "heuristic-v1", "text": "## Deploy\n\nDeploy to Polkadot Hub TestNet:\n\n```bash\nforge create MyNFT \\\n --rpc-url polkadot_hub_testnet \\\n --private-key YOUR_PRIVATE_KEY \\\n --constructor-args YOUR_OWNER_ADDRESS \\\n --broadcast\n```\n\nReplace `YOUR_PRIVATE_KEY` with your private key and `YOUR_OWNER_ADDRESS` with the address that will own the NFT contract."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-foundry", "page_title": "Deploy an NFT to Polkadot Hub with Foundry", "index": 7, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 2884, "end_char": 3489, "estimated_token_count": 163, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Verify Your Contract__\n\n ---\n\n Now that you've deployed an NFT contract, learn how to verify it with Foundry.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/foundry/verify-a-contract/)\n\n- Guide __Deploy an ERC-20__\n\n ---\n\n Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Foundry.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/foundry/)\n\n
"} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 30, "end_char": 840, "estimated_token_count": 191, "token_estimator": "heuristic-v1", "text": "## Introduction\n\nNon-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification.\n\nThis guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\\_blank}. You'll use [OpenZeppelin's battle-tested NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\\_blank} and [Hardhat](https://hardhat.org/docs/getting-started){target=\\_blank}, a comprehensive development environment with built-in testing, debugging, and deployment capabilities. Hardhat uses standard Solidity compilation to generate EVM bytecode, making it fully compatible with Polkadot Hub's EVM environment."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 840, "end_char": 1216, "estimated_token_count": 102, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\n- Basic understanding of Solidity programming and NFT standards.\n- Node.js v22.13.1 or later.\n- 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}.\n- A wallet with a private key for signing transactions."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 2, "depth": 2, "title": "Set Up Your Project", "anchor": "set-up-your-project", "start_char": 1216, "end_char": 1523, "estimated_token_count": 64, "token_estimator": "heuristic-v1", "text": "## Set Up Your Project\n\nTake the following steps to get started:\n\n1. Initialize your Hardhat project:\n\n ```bash\n mkdir hardhat-nft-deployment\n cd hardhat-nft-deployment\n npx hardhat --init\n ```\n\n2. Install OpenZeppelin contracts:\n\n ```bash\n npm install @openzeppelin/contracts\n ```"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 3, "depth": 2, "title": "Configure Hardhat", "anchor": "configure-hardhat", "start_char": 1523, "end_char": 2887, "estimated_token_count": 320, "token_estimator": "heuristic-v1", "text": "## Configure Hardhat\n\nEdit `hardhat.config.ts`:\n\n```typescript title=\"hardhat.config.ts\"\nimport type { HardhatUserConfig } from 'hardhat/config';\n\nimport hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem';\nimport { configVariable } from 'hardhat/config';\n\nconst config: HardhatUserConfig = {\n plugins: [hardhatToolboxViemPlugin],\n solidity: {\n profiles: {\n default: {\n version: '0.8.28',\n },\n production: {\n version: '0.8.28',\n settings: {\n optimizer: {\n enabled: true,\n runs: 200,\n },\n },\n },\n },\n },\n networks: {\n hardhatMainnet: {\n type: 'edr-simulated',\n chainType: 'l1',\n },\n hardhatOp: {\n type: 'edr-simulated',\n chainType: 'op',\n },\n sepolia: {\n type: 'http',\n chainType: 'l1',\n url: configVariable('SEPOLIA_RPC_URL'),\n accounts: [configVariable('SEPOLIA_PRIVATE_KEY')],\n },\n polkadotHubTestnet: {\n type: 'http',\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n chainId: 420420422,\n accounts: [configVariable('PRIVATE_KEY')],\n },\n },\n};\n\nexport default config;\n```\n\n!!! tip\n Learn how to use Hardhat's [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\\_blank} to handle your private keys in a secure way."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 4, "depth": 2, "title": "Create Your Contract", "anchor": "create-your-contract", "start_char": 2887, "end_char": 3473, "estimated_token_count": 135, "token_estimator": "heuristic-v1", "text": "## Create Your Contract\n\nCreate `contracts/MyNFT.sol`:\n\n```solidity title=\"contracts/MyNFT.sol\"\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MyNFT is ERC721, Ownable {\n uint256 private _nextTokenId;\n\n constructor(address initialOwner)\n ERC721(\"MyToken\", \"MTK\")\n Ownable(initialOwner)\n {}\n\n function safeMint(address to) public onlyOwner {\n uint256 tokenId = _nextTokenId++;\n _safeMint(to, tokenId);\n }\n}\n```"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 5, "depth": 2, "title": "Compile", "anchor": "compile", "start_char": 3473, "end_char": 3518, "estimated_token_count": 13, "token_estimator": "heuristic-v1", "text": "## Compile\n\n```bash\nnpx hardhat compile\n```"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 6, "depth": 2, "title": "Set Up Deployment", "anchor": "set-up-deployment", "start_char": 3518, "end_char": 3999, "estimated_token_count": 118, "token_estimator": "heuristic-v1", "text": "## Set Up Deployment\n\nCreate a deployment module in `ignition/modules/MyNFT.ts`:\n\n```typescript title=\"ignition/modules/MyNFT.ts\"\nimport { buildModule } from '@nomicfoundation/hardhat-ignition/modules';\n\nexport default buildModule('MyNFTModule', (m) => {\n const initialOwner = m.getParameter('initialOwner', 'INSERT_OWNER_ADDRESS');\n const myNFT = m.contract('MyNFT', [initialOwner]);\n return { myNFT };\n});\n```\n\nReplace `INSERT_OWNER_ADDRESS` with your desired owner address."} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 7, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 3999, "end_char": 4139, "estimated_token_count": 31, "token_estimator": "heuristic-v1", "text": "## Deploy\n\nDeploy to Polkadot Hub TestNet:\n\n```bash\nnpx hardhat ignition deploy ignition/modules/MyNFT.ts --network polkadotHubTestnet\n```"} -{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 8, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 4139, "end_char": 4745, "estimated_token_count": 163, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Verify Your Contract__\n\n ---\n\n Now that you've deployed an NFT contract, learn how to verify it with Hardhat.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/hardhat/verify-a-contract/)\n\n\n- Guide __Deploy an ERC-20__\n\n ---\n\n Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/hardhat/)\n\n
"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 840, "end_char": 1308, "estimated_token_count": 117, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\n- Basic understanding of Solidity programming and NFT standards.\n- Node.js v22.13.1 or later.\n- 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}.\n- A wallet with a private key for signing transactions."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 2, "depth": 2, "title": "Set Up Your Project", "anchor": "set-up-your-project", "start_char": 1308, "end_char": 1615, "estimated_token_count": 64, "token_estimator": "heuristic-v1", "text": "## Set Up Your Project\n\nTake the following steps to get started:\n\n1. Initialize your Hardhat project:\n\n ```bash\n mkdir hardhat-nft-deployment\n cd hardhat-nft-deployment\n npx hardhat --init\n ```\n\n2. Install OpenZeppelin contracts:\n\n ```bash\n npm install @openzeppelin/contracts\n ```"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 3, "depth": 2, "title": "Configure Hardhat", "anchor": "configure-hardhat", "start_char": 1615, "end_char": 2979, "estimated_token_count": 320, "token_estimator": "heuristic-v1", "text": "## Configure Hardhat\n\nEdit `hardhat.config.ts`:\n\n```typescript title=\"hardhat.config.ts\"\nimport type { HardhatUserConfig } from 'hardhat/config';\n\nimport hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem';\nimport { configVariable } from 'hardhat/config';\n\nconst config: HardhatUserConfig = {\n plugins: [hardhatToolboxViemPlugin],\n solidity: {\n profiles: {\n default: {\n version: '0.8.28',\n },\n production: {\n version: '0.8.28',\n settings: {\n optimizer: {\n enabled: true,\n runs: 200,\n },\n },\n },\n },\n },\n networks: {\n hardhatMainnet: {\n type: 'edr-simulated',\n chainType: 'l1',\n },\n hardhatOp: {\n type: 'edr-simulated',\n chainType: 'op',\n },\n sepolia: {\n type: 'http',\n chainType: 'l1',\n url: configVariable('SEPOLIA_RPC_URL'),\n accounts: [configVariable('SEPOLIA_PRIVATE_KEY')],\n },\n polkadotHubTestnet: {\n type: 'http',\n url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',\n chainId: 420420422,\n accounts: [configVariable('PRIVATE_KEY')],\n },\n },\n};\n\nexport default config;\n```\n\n!!! tip\n Learn how to use Hardhat's [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\\_blank} to handle your private keys in a secure way."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 4, "depth": 2, "title": "Create Your Contract", "anchor": "create-your-contract", "start_char": 2979, "end_char": 3565, "estimated_token_count": 135, "token_estimator": "heuristic-v1", "text": "## Create Your Contract\n\nCreate `contracts/MyNFT.sol`:\n\n```solidity title=\"contracts/MyNFT.sol\"\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MyNFT is ERC721, Ownable {\n uint256 private _nextTokenId;\n\n constructor(address initialOwner)\n ERC721(\"MyToken\", \"MTK\")\n Ownable(initialOwner)\n {}\n\n function safeMint(address to) public onlyOwner {\n uint256 tokenId = _nextTokenId++;\n _safeMint(to, tokenId);\n }\n}\n```"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 5, "depth": 2, "title": "Compile", "anchor": "compile", "start_char": 3565, "end_char": 3610, "estimated_token_count": 13, "token_estimator": "heuristic-v1", "text": "## Compile\n\n```bash\nnpx hardhat compile\n```"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 6, "depth": 2, "title": "Set Up Deployment", "anchor": "set-up-deployment", "start_char": 3610, "end_char": 4091, "estimated_token_count": 118, "token_estimator": "heuristic-v1", "text": "## Set Up Deployment\n\nCreate a deployment module in `ignition/modules/MyNFT.ts`:\n\n```typescript title=\"ignition/modules/MyNFT.ts\"\nimport { buildModule } from '@nomicfoundation/hardhat-ignition/modules';\n\nexport default buildModule('MyNFTModule', (m) => {\n const initialOwner = m.getParameter('initialOwner', 'INSERT_OWNER_ADDRESS');\n const myNFT = m.contract('MyNFT', [initialOwner]);\n return { myNFT };\n});\n```\n\nReplace `INSERT_OWNER_ADDRESS` with your desired owner address."} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 7, "depth": 2, "title": "Deploy", "anchor": "deploy", "start_char": 4091, "end_char": 4231, "estimated_token_count": 31, "token_estimator": "heuristic-v1", "text": "## Deploy\n\nDeploy to Polkadot Hub TestNet:\n\n```bash\nnpx hardhat ignition deploy ignition/modules/MyNFT.ts --network polkadotHubTestnet\n```"} +{"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-hardhat", "page_title": "Deploy an NFT to Polkadot Hub with Hardhat", "index": 8, "depth": 2, "title": "Where to Go Next", "anchor": "where-to-go-next", "start_char": 4231, "end_char": 4837, "estimated_token_count": 163, "token_estimator": "heuristic-v1", "text": "## Where to Go Next\n\n
\n\n- Guide __Verify Your Contract__\n\n ---\n\n Now that you've deployed an NFT contract, learn how to verify it with Hardhat.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/hardhat/verify-a-contract/)\n\n\n- Guide __Deploy an ERC-20__\n\n ---\n\n Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat.\n\n [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/hardhat/)\n\n
"} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-remix", "page_title": "Deploy an NFT to Polkadot Hub with Remix", "index": 0, "depth": 2, "title": "Introduction", "anchor": "introduction", "start_char": 28, "end_char": 763, "estimated_token_count": 178, "token_estimator": "heuristic-v1", "text": "## Introduction\n\nNon-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification.\n\nThis guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\\_blank}. You'll use [OpenZeppelin's battle-tested NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\\_blank} and [Remix](https://remix.ethereum.org/){target=\\_blank}, a visual, browser-based environment perfect for rapid prototyping and learning. It requires no local installation and provides an intuitive interface for contract development."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-remix", "page_title": "Deploy an NFT to Polkadot Hub with Remix", "index": 1, "depth": 2, "title": "Prerequisites", "anchor": "prerequisites", "start_char": 763, "end_char": 1109, "estimated_token_count": 89, "token_estimator": "heuristic-v1", "text": "## Prerequisites\n\n- Basic understanding of Solidity programming and NFT standards.\n- 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}\n- A wallet with a private key for signing transactions."} {"page_id": "smart-contracts-cookbook-smart-contracts-deploy-nft-remix", "page_title": "Deploy an NFT to Polkadot Hub with Remix", "index": 2, "depth": 2, "title": "Access Remix", "anchor": "access-remix", "start_char": 1109, "end_char": 1426, "estimated_token_count": 71, "token_estimator": "heuristic-v1", "text": "## Access Remix\n\nNavigate to [Remix](https://remix.ethereum.org/){target=\\_blank} in your web browser.\n\nThe interface will load with a default workspace containing sample contracts. In this interface, you can access a file explorer, edit your code, interact with various plugins for development, and use a terminal."} diff --git a/llms.txt b/llms.txt index f20ee9e34..6867b0eb5 100644 --- a/llms.txt +++ b/llms.txt @@ -6,7 +6,7 @@ This directory lists URLs for raw Markdown pages that complement the rendered pages on the documentation site. Use these Markdown files to retain semantic context when prompting models while avoiding passing HTML elements. ## Metadata -- Documentation pages: 269 +- Documentation pages: 270 - Categories: 13 ## Docs @@ -45,6 +45,8 @@ Docs: Basics - [Parachains Overview](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-parachains.md): Learn about parachains, specialized blockchains on Polkadot that gain shared security and interoperability. Discover how they work and the tools to build them. - [Overview of the Polkadot Relay Chain](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-polkadot-hub-consensus-and-security-relay-chain.md): Explore Polkadot's core architecture, including its multi-chain vision, shared security, and the DOT token's governance and staking roles. - [XCM Tools](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-tools-xcm-tools.md): Explore essential XCM tools across Polkadot, crafted to enhance cross-chain functionality and integration within the ecosystem. +- [Technical Reference Overview](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md): Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. +- [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md): Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. - [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md): Deploy an ERC-20 token contract on Polkadot Hub. This guide covers contract creation, compilation, deployment, and interaction via the Remix IDE. - [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20.md): Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Polkadot Remix IDE. - [Deploy an NFT to Polkadot Hub with Ethers.js](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-ethers.md): Learn how to deploy an ERC-721 NFT contract to Polkadot Hub using Ethers.js, giving you complete programmatic control over the deployment process. @@ -83,6 +85,7 @@ Docs: Smart Contracts - [Deploy a Basic Contract with Hardhat](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-basic-hardhat.md): Learn how to deploy a basic smart contract to Polkadot Hub using Hardhat, Perfect for professional workflows requiring comprehensive testing and debugging. - [Deploy a Basic Contract to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-basic-pvm.md): Learn how to deploy a basic smart contract to Polkadot Hub using the PolkaVM. - [Deploy a Basic Contract with Remix IDE](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-basic-remix.md): Learn how to deploy a basic smart contract to Polkadot Hub using Remix IDE Ideal for rapid prototyping, learning, and visual development. +- [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-hardhat.md): Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. - [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20-erc20-remix.md): Deploy an ERC-20 token contract on Polkadot Hub. This guide covers contract creation, compilation, deployment, and interaction via the Remix IDE. - [Deploy an ERC-20 to Polkadot Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-erc20.md): Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Polkadot Remix IDE. - [Deploy an NFT to Polkadot Hub with Ethers.js](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-nft-ethers.md): Learn how to deploy an ERC-721 NFT contract to Polkadot Hub using Ethers.js, giving you complete programmatic control over the deployment process. @@ -202,6 +205,7 @@ Docs: Polkadot Protocol - [Proof of Stake Consensus](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-polkadot-hub-consensus-and-security-pos-consensus.md): Explore Polkadot's consensus protocols for secure, scalable, and decentralized network operation, including NPoS, BABE, GRANDPA, and BEEFY. - [Overview of the Polkadot Relay Chain](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-polkadot-hub-consensus-and-security-relay-chain.md): Explore Polkadot's core architecture, including its multi-chain vision, shared security, and the DOT token's governance and staking roles. - [People Chain](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-polkadot-hub-people-and-identity.md): Learn how People chain secures decentralized identity management, empowering users to control and verify digital identities without central authorities. +- [Technical Reference Overview](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md): Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. - [Accounts in Asset Hub Smart Contracts](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-for-eth-devs-accounts.md): Bridges Ethereum's 20-byte addresses with Polkadot's 32-byte accounts, enabling seamless interaction while maintaining compatibility with Ethereum tooling. - [Transactions and Fees on Asset Hub](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-for-eth-devs-blocks-transactions-fees.md): Explore how Asset Hub smart contracts handle blocks, transactions, and fees with EVM compatibility, supporting various Ethereum transaction types. - [Dual Virtual Machine Stack](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-for-eth-devs-dual-vm-stack.md): Compare Polkadot’s dual smart contract VMs—REVM for EVM compatibility and PolkaVM for RISC-V performance, flexibility, and efficiency. @@ -264,6 +268,7 @@ Docs: Reference - [XCM Config](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/develop-interoperability-xcm-config.md): Learn how the XCM Executor configuration works for your custom Polkadot SDK-based runtime with detailed guidance and references. - [XCM Runtime APIs](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/develop-interoperability-xcm-runtime-apis.md): Learn about XCM Runtime APIs in Polkadot for cross-chain communication. Explore the APIs to simulate and test XCM messages before execution on the network. - [Glossary](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-glossary.md): Glossary of terms used within the Polkadot ecosystem, Polkadot SDK, its subsequent libraries, and other relevant Web3 terminology. +- [Technical Reference Overview](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md): Learn about Polkadot's technical architecture, governance framework, parachain ecosystem, and the tools you need to build and interact with the network. - [JSON-RPC APIs](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-for-eth-devs-json-rpc-apis.md): JSON-RPC APIs guide for Polkadot Hub, covering supported methods, parameters, and examples for interacting with the chain. Docs: Chain Interactions @@ -356,7 +361,6 @@ Docs: Uncategorized - [reference-tools-chopsticks](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-tools-chopsticks.md): No description available. - [ParaSpell XCM SDK](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-tools-paraspell.md): A powerful open-source library that simplifies XCM integration, enabling developers to easily build interoperable dApps on Polkadot. - [reference-tools-zombienet](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference-tools-zombienet.md): No description available. -- [reference](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/reference.md): No description available. - [smart-contracts-cookbook-smart-contracts-deploy-basic](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-cookbook-smart-contracts-deploy-basic.md): No description available. - [smart-contracts-dev-environments-foundry-compile-and-test](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-dev-environments-foundry-compile-and-test.md): No description available. - [smart-contracts-dev-environments-foundry-deploy-a-contract](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/smart-contracts-dev-environments-foundry-deploy-a-contract.md): No description available. diff --git a/smart-contracts/cookbook/.nav.yml b/smart-contracts/cookbook/.nav.yml index 639e1c8a0..967a352ff 100644 --- a/smart-contracts/cookbook/.nav.yml +++ b/smart-contracts/cookbook/.nav.yml @@ -1,6 +1,6 @@ nav: - 'Overview': index.md # TODO: Update name of page - 'Get Tokens from the Faucet': /smart-contracts/faucet/ -- 'EVM/PVM Smart Contracts': smart-contracts +- 'EVM Smart Contracts': smart-contracts - 'Create a DApp': dapps - 'Port Ethereum DApps': eth-dapps diff --git a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md new file mode 100644 index 000000000..04ded0978 --- /dev/null +++ b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md @@ -0,0 +1,177 @@ +--- +title: Deploy an ERC-20 to Polkadot Hub +description: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. +tutorial_badge: Intermediate +categories: Basics, Smart Contracts +tools: Hardhat +--- + +# Deploy an ERC-20 to Polkadot Hub + +## Introduction + +[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. + +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}. + +## Prerequisites + +Before starting, make sure you have: + +- Basic understanding of Solidity programming and fungible tokens. +- Node.js v22.13.1 or later. +- 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}. + +## Set Up Your Project + +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: + +1. Clone the GitHub repository locally: + + ```bash + git clone https://github.com/polkadot-developers/revm-hardhat-examples/ + cd revm-hardhat-examples/erc20-hardhat + ``` + +2. Install the dependencies: + + ```bash + npm i + ``` + +This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + +## Configure Hardhat + +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. + +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: + +```bash +npx hardhat vars set TESTNET_PRIVATE_KEY +``` + +The command will initiate a wizard in which you'll have to enter the value to be stored: + +
+ npx hardhat vars set TESTNET_PRIVATE_KEY + ✔ Enter value: · ••••••••• + The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json +
+ +??? warning "Key Encryption" + 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. + +You can now use the account related to this private key by importing it into the Hardhat configuration file: + +```ts title="hardhat.config.ts" hl_lines="1 17" +--8<-- "https://raw.githubusercontent.com/polkadot-developers/revm-hardhat-examples/refs/heads/master/erc20-hardhat/hardhat.config.ts::2" + +--8<-- "https://raw.githubusercontent.com/polkadot-developers/revm-hardhat-examples/refs/heads/master/erc20-hardhat/hardhat.config.ts:24:45" +``` + +## Compile your Contract + +Once you've configured Hardhat, you can compile the contract. + +In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: + +```bash +npx hardhat compile +``` + +If everything compiles successfully, you should see the following output: + +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). +
+ +## Test your Contract + +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 + +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: + +1. The token was deployed by verifying its **name** and **symbol**. +2. The token has the right owner configured. +3. The token has an initial supply of zero. +4. The owner can mint tokens. +5. The total supply is increased after a mint. +6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. + +To run the test, you can execute the following command: + +```bash +npx hardhat test --network polkadotTestnet +``` + +If tests are successful, you should see the following logs: + +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       ✔ Should have correct name and symbol +       ✔ Should set the right owner +       ✔ Should have zero initial supply +     Minting +       ✔ Should allow owner to mint tokens +       ✔ Should increase total supply on mint +     Multiple mints +       ✔ Should correctly track balance after multiple mints + +   6 passing (369ms) +
+ +## Deploy your Contract + +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. + +To deploy the contract, run the following command: + +```bash +npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet +``` + +You'll need to confirm the target network (by chain ID): + +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ✔ Confirm deploy to network polkadotTestnet (420420420)? … yes +   + Hardhat Ignition 🚀 +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed 🚀 +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 +
+ +And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. + +## Where to Go Next + +
+ +- Guide __Deploy an NFT with Remix__ + + --- + + Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + +
\ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md index a80bd040f..48da3e2a3 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md +++ b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md @@ -18,9 +18,9 @@ This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet us Before starting, make sure you have: +- Basic understanding of Solidity programming and fungible tokens. - An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. - 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}. -- Basic understanding of Solidity and fungible tokens. ## Create Your Contract diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md index 98a59a2fc..22f09f8fb 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md +++ b/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md @@ -18,7 +18,7 @@ This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIP - Basic understanding of Solidity programming and NFT standards. - Node.js v22.13.1 or later. -- 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}. +- 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}. - A wallet with a private key for signing transactions. ## Set Up Your Project