Skip to content

paritytech/contracts-boilerplate

Repository files navigation

Getting started with Dapp on Asset Hub

This repository contains a sample project that you can use as the starting point to develop your Dapp on Polkadot. It's also a great fit for learning the basics of smart contract development.

Quick start

Prerequisites

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

Then install the dependencies:

npm install

We will use deno, a modern alternative to Node that can work with TypeScript out of the box. You can install it by running:

curl -fsSL https://deno.land/install.sh | sh

Building contracts

We can now compile the contracts located in the contracts/ directory:

deno task build [--filter <contract-name>] [--clean]

This does the following:

  • Compile the bytecode for each contract into codgen/bytecode/*
  • Generate the abi for each contract into codgen/abi/*.ts and the index codegen/abis.ts

Deploying contracts

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

Update tools/deploy.ts to include new contracts you want to deploy. Make sure to specify the constructor arguments and the value, if needed.

Deploying to Testnet

To deploy to Westend Testnet, you will need to specify the TESTNET_PRIVATE_KEY. Check the instructions here to connect with your wallet and request funds.

Deploying to a local chain

For local development, checkout the instructions here to setup and start a local chain.

Note: You can also test against geth, the deployment code, will detect the chain and deploy the right bytecode (evm or pvm).

Local deployments will use the account 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac already configured in your .env file, This account is pre-funded at genesis, so you can use it to deploy contracts.

Now that you have the environment variables setup, ensure that your chain is running and deploy the contracts by running:

deno task deploy [--filter <contract-name>]

This command will update the codegen/addresses.ts file with the deployed contract addresses, so that you can easily reference them in your apps.

Running the web app

Once the contracts are deployed you can run the frontend by running:

deno 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.

screenshot

Run cli

There is an example cli in the cli directory that you can run to interact with the deployed contracts.

deno --env-file --allow-all ./cli/dao-hack.tsx

Running tests

Use the following command to run the tests located in the tests/ directory:

# start the eth-rpc and substrate node
export SUBSTRATE_BIN="$POLKADOT_SDK/target/debug/substrate-node"
export ETH_RPC_BIN="$POLKADOT_SDK/target/debug/eth-rpc"

# start the servers in the background and run the tests in watch mode against substrate
ETH_RPC=true START_SUBSTRATE_NODE=true npm run test:dev

# start geth in the background and run the tests in watch mode against geth
START_GETH=true npm run test:dev

# use live server (http://localhost:{$RPC_PORT:-8545}) and run the tests in watch mode
npm run test:dev

Learn more

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published