⚠️ Warning: Hardhat plugins are not available yet for Contracts on Asset Hub. This repository serves as a temporary solution until we can use the hardhat tools.
This repository contains a sample project that you can use as the starting point for your Smart Contracts on Asset Hub project. It's also a great fit for learning the basics of smart contract development.
The first things you need to do are cloning this repository and installing its dependencies:
git clone https://github.com/paritytech/contracts-boilerplate.git
cd contracts-boilerplate/viem
We will use Bun, a modern alternative to node/npm with batteries included. To install Bun, run the following command:
curl -fsSL https://bun.sh/install | bash
Once installed, you can use Bun to install the project dependencies:
bun install
We can now compile the contracts located in the contracts/
directory:
bun tools/build.ts
This does the following:
- Compile the bytecode for each contract into
codgen/bytecode/*.polkavm
- Generate the abi for each contract into
codgen/abi/*.ts
and the indexcodegen/abis.ts
Update tools/deploy.ts
to include new contracts you want to deploy. Make sure to specify the constructor arguments and the value, if needed.
Before you can deploy contracts, let's copy the .env.example
file to .env
and fill in the required environment variables.
cp .env.example .env
To deploy to Westend, you will need to specify the WESTEND_PRIVATE_KEY
.
For local development, checkout the instructions here to setup and start a local chain.
Now that you have the environment variables setup, you can deploy the contracts by running:
bun tools/deploy.ts
This command will update the codegen/addresses.ts
file with the deployed contract addresses, so that you can easily import them in your frontend.
Once the contracts are deployed you can run the frontend by running:
bun dev --open
This will start a development server with live reload and open your browser to the local url. The default app let you do the following actions:
- Connect to different wallets
- Display the connected account
- Mint an NFT.
- Display the minted NFT.
- Asset Hub documentation to learn more about building Smart Contracts on Asset Hub.
- wagmi documentation to learn more about building EVM Dapps with React.
- viem documentation to learn more about the library used to interact with EVM contracts.