Deploy a Basic Contract with Hardhat¶
Introduction¶
This guide demonstrates how to deploy a basic Solidity smart contract to Polkadot Hub TestNet using Hardhat, which provides a comprehensive development environment with built-in testing, debugging, and deployment capabilities. It's ideal for professional development workflows and team projects.
Prerequisites¶
Before you begin, ensure you have the following:
- A basic understanding of Solidity programming.
- Node.js v22.13.1 or later installed.
- Test tokens for gas fees, available from the Polkadot faucet. See Get Test Tokens for a guide to using the faucet.
- A wallet with a private key for signing transactions.
Set Up Your Project¶
Use the following terminal commands to create a directory and initialize your Hardhat project inside of it:
Configure Hardhat¶
Open hardhat.config.ts and update to add polkadotTestnet to the networks configuration as highlighted in the following example code:
import type { HardhatUserConfig } from 'hardhat/config';
import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem';
import { vars } from 'hardhat/config';
const config: HardhatUserConfig = {
plugins: [hardhatToolboxViemPlugin],
solidity: {
version: '0.8.28',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
polkadotTestnet: {
url: 'https://services.polkadothub-rpc.com/testnet',
chainId: 420420417,
accounts: [vars.get('PRIVATE_KEY')],
},
},
};
export default config;
Tip
Visit the Hardhat Configuration variables documentation to learn how to use Hardhat to handle your private keys securely.
Create the Contract¶
Follow these steps to create your smart contract:
-
Delete the default contract file(s) in the
contractsdirectory. -
Create a new file named
Storage.solinside thecontractsdirectory. -
Add the following code to create the
Storage.solsmart contract:
Compile the Contract¶
Compile your Storage.sol contract using the following command:
You will see a message in the terminal confirming the contract was successfully compiled, similar to the following:
Deploy the Contract¶
You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows:
-
Delete the default file(s) inside the
ignition/modulesdirectory. -
Create a new file named
Storage.tsinside theignition/modulesdirectory. -
Open
ignition/modules/Storage.tsand add the following code to create your deployment module: -
Deploy your contract to Polkadot Hub TestNet using the following command:
-
Confirm the target deployment network name and chain ID when prompted:
npx hardhat ignition deploy ignition/modules/Storage.ts --network polkadotTestnet ✔ Confirm deploy to network polkadotTestnet (420420417)? … yes Hardhat Ignition 🚀 Deploying [ StorageModule ] [ StorageModule ] successfully deployed 🚀 Deployed Addresses Storage - 0x12345.....
Congratulations! You've now deployed a basic smart contract to Polkadot Hub TestNet using Hardhat. Consider the following resources to build upon your progress.
Where to Go Next¶
-
Guide Deploy an ERC-20
Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat.
-
Guide Deploy an NFT
Walk through deploying an NFT to the Polkadot Hub using Hardhat.
| Created: January 14, 2026