You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via the Remix IDE.
3357
+
3358
+
# Deploy an ERC-20 to Polkadot Hub
3359
+
3360
+
## Introduction
3361
+
3362
+
[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.
3363
+
3364
+
This 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}.
3365
+
3366
+
## Prerequisites
3367
+
3368
+
Before starting, make sure you have:
3369
+
3370
+
- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}.
3371
+
- 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/connect/#test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}.
3372
+
- Basic understanding of Solidity and fungible tokens.
3373
+
3374
+
## Create the ERC-20 Contract
3375
+
3376
+
To create the ERC-20 contract, you can follow the steps below:
3377
+
3378
+
1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\_blank}.
3379
+
2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`.
3. Now, paste the following ERC-20 contract code into the editor:
3384
+
3385
+
```solidity title="MyToken.sol"
3386
+
// SPDX-License-Identifier: MIT
3387
+
// Compatible with OpenZeppelin Contracts ^5.4.0
3388
+
pragma solidity ^0.8.27;
3389
+
3390
+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
3391
+
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
3392
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
3393
+
3394
+
contract MyToken is ERC20, Ownable, ERC20Permit {
3395
+
constructor(address initialOwner)
3396
+
ERC20("MyToken", "MTK")
3397
+
Ownable(initialOwner)
3398
+
ERC20Permit("MyToken")
3399
+
{}
3400
+
3401
+
function mint(address to, uint256 amount) public onlyOwner {
3402
+
_mint(to, amount);
3403
+
}
3404
+
}
3405
+
```
3406
+
3407
+
The key components of the code above are:
3408
+
3409
+
- Contract imports:
3410
+
3411
+
- **[`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.
3412
+
- **[`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, 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.
3413
+
- **[`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.
3414
+
3415
+
- Constructor parameters:
3416
+
3417
+
- **`initialOwner`**: Sets the address that will have administrative rights over the contract.
3418
+
- **`"MyToken"`**: The full name of your token.
3419
+
- **`"MTK"`**: The symbol representing your token in wallets and exchanges.
3420
+
3421
+
- Key functions:
3422
+
3423
+
- **`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).
- **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address.
3426
+
- **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner.
3427
+
- **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved.
3428
+
- **`balanceOf(address account)`**: Returns the token balance of a specific address.
3429
+
- **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address.
3430
+
3431
+
!!! tip
3432
+
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:
3433
+
3434
+

3435
+
3436
+
3437
+
## Compile the Contract
3438
+
3439
+
The 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.
3440
+
3441
+
To compile your contract, ensure you have it opened in the Remix IDE Editor, and follow the instructions below:
3442
+
3443
+
1. Select the **Solidity Compiler** plugin from the left panel.
3444
+
2. Click the **Compile MyToken.sol** button.
3445
+
3. If the compilation succeeded, you'll see a green checkmark indicating success in the **Solidity Compiler** icon.
Deployment 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:
3452
+
3453
+
1. Select the **Deploy & Run Transactions** plugin from the left panel.
3454
+
2. Configure the deployment settings.
3455
+
1. From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (check the [Deploying Contracts](TODO){target=\_blank} section of the Remix IDE guide for more details).
3456
+
2. (Optional) From the **ACCOUNT** dropdown, select the account you want to use for the deploy.
3457
+
3458
+
3. Configure the contract parameters:
3459
+
1. Enter the address that will own the deployed token contract.
3460
+
2. Click the **Deploy** button to initiate the deployment.
3461
+
3462
+
4. **MetaMask will pop up**: Review the transaction details. Click **Confirm** to deploy your contract.
3463
+
5. If the deployment process succeeded, you will see the transaction details in the terminal, including the contract address and deployment transaction hash.
Once 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:
3470
+
3471
+
1. Expand the **mint** function:
3472
+
1. Enter the recipient address and the amount (remember to add 18 zeros for 1 whole token).
3473
+
2. Click **transact**.
3474
+
3475
+
2. Click **Approve** to confirm the transaction in the Talisman popup.
3476
+
3477
+
3. If the transaction succeeds, you will see a green check mark in the terminal.
3478
+
3479
+
4. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance.
- **`transfer(address to, uint256 amount)`**: Send tokens to another address.
3487
+
- **`approve(address spender, uint256 amount)`**: Allow another address to spend your tokens.
3488
+
3489
+
Feel 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.
- Summary: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via the Remix IDE.
4580
+
4581
+
# Deploy an ERC-20 to Polkadot Hub
4582
+
4583
+
## Introduction
4584
+
4585
+
[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.
4586
+
4587
+
This 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}.
4588
+
4589
+
## Prerequisites
4590
+
4591
+
Before starting, make sure you have:
4592
+
4593
+
- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}.
4594
+
- 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/connect/#test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}.
4595
+
- Basic understanding of Solidity and fungible tokens.
4596
+
4597
+
## Create the ERC-20 Contract
4598
+
4599
+
To create the ERC-20 contract, you can follow the steps below:
4600
+
4601
+
1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\_blank}.
4602
+
2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`.
3. Now, paste the following ERC-20 contract code into the editor:
4607
+
4608
+
```solidity title="MyToken.sol"
4609
+
// SPDX-License-Identifier: MIT
4610
+
// Compatible with OpenZeppelin Contracts ^5.4.0
4611
+
pragma solidity ^0.8.27;
4612
+
4613
+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
4614
+
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
4615
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
4616
+
4617
+
contract MyToken is ERC20, Ownable, ERC20Permit {
4618
+
constructor(address initialOwner)
4619
+
ERC20("MyToken", "MTK")
4620
+
Ownable(initialOwner)
4621
+
ERC20Permit("MyToken")
4622
+
{}
4623
+
4624
+
function mint(address to, uint256 amount) public onlyOwner {
4625
+
_mint(to, amount);
4626
+
}
4627
+
}
4628
+
```
4629
+
4630
+
The key components of the code above are:
4631
+
4632
+
- Contract imports:
4633
+
4634
+
- **[`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.
4635
+
- **[`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, 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.
4636
+
- **[`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.
4637
+
4638
+
- Constructor parameters:
4639
+
4640
+
- **`initialOwner`**: Sets the address that will have administrative rights over the contract.
4641
+
- **`"MyToken"`**: The full name of your token.
4642
+
- **`"MTK"`**: The symbol representing your token in wallets and exchanges.
4643
+
4644
+
- Key functions:
4645
+
4646
+
- **`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).
- **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address.
4649
+
- **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner.
4650
+
- **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved.
4651
+
- **`balanceOf(address account)`**: Returns the token balance of a specific address.
4652
+
- **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address.
4653
+
4654
+
!!! tip
4655
+
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:
4656
+
4657
+

4658
+
4659
+
4660
+
## Compile the Contract
4661
+
4662
+
The 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.
4663
+
4664
+
To compile your contract, ensure you have it opened in the Remix IDE Editor, and follow the instructions below:
4665
+
4666
+
1. Select the **Solidity Compiler** plugin from the left panel.
4667
+
2. Click the **Compile MyToken.sol** button.
4668
+
3. If the compilation succeeded, you'll see a green checkmark indicating success in the **Solidity Compiler** icon.
Deployment 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:
4675
+
4676
+
1. Select the **Deploy & Run Transactions** plugin from the left panel.
4677
+
2. Configure the deployment settings.
4678
+
1. From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (check the [Deploying Contracts](TODO){target=\_blank} section of the Remix IDE guide for more details).
4679
+
2. (Optional) From the **ACCOUNT** dropdown, select the account you want to use for the deploy.
4680
+
4681
+
3. Configure the contract parameters:
4682
+
1. Enter the address that will own the deployed token contract.
4683
+
2. Click the **Deploy** button to initiate the deployment.
4684
+
4685
+
4. **MetaMask will pop up**: Review the transaction details. Click **Confirm** to deploy your contract.
4686
+
5. If the deployment process succeeded, you will see the transaction details in the terminal, including the contract address and deployment transaction hash.
Once 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:
4693
+
4694
+
1. Expand the **mint** function:
4695
+
1. Enter the recipient address and the amount (remember to add 18 zeros for 1 whole token).
4696
+
2. Click **transact**.
4697
+
4698
+
2. Click **Approve** to confirm the transaction in the Talisman popup.
4699
+
4700
+
3. If the transaction succeeds, you will see a green check mark in the terminal.
4701
+
4702
+
4. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance.
- **`transfer(address to, uint256 amount)`**: Send tokens to another address.
4710
+
- **`approve(address spender, uint256 amount)`**: Allow another address to spend your tokens.
4711
+
4712
+
Feel 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.
0 commit comments