|
1 | | -⚠️ Archived: Use https://github.com/paritytech/create-polkadot-dapp instead |
2 | | - |
3 | 1 | # Getting started with Dapp on Asset Hub |
4 | 2 |
|
5 | | -This repository contains 2 boilerplates Dapp to help you getting started building contracts on Asset Hub. |
| 3 | +This repository contains a sample project that you can use as the starting point to develop your Dapp on Polkadot. |
| 4 | +It's also a great fit for learning the basics of smart contract development. |
| 5 | + |
| 6 | +## Quick start |
| 7 | + |
| 8 | +### Prerequisites |
| 9 | + |
| 10 | +The first things you need to do are cloning this repository and installing its |
| 11 | +dependencies: |
| 12 | + |
| 13 | +```sh |
| 14 | +git clone https://github.com/paritytech/contracts-boilerplate.git |
| 15 | +cd contracts-boilerplate |
| 16 | +``` |
| 17 | + |
| 18 | +Then install the dependencies: |
| 19 | + |
| 20 | +```sh |
| 21 | +npm install |
| 22 | +``` |
| 23 | + |
| 24 | +We will use [deno](https://deno.com), a modern alternative to Node that can work with TypeScript out of the box. |
| 25 | +You can install it by running: |
| 26 | + |
| 27 | +```sh |
| 28 | +curl -fsSL https://deno.land/install.sh | sh |
| 29 | +``` |
| 30 | + |
| 31 | +### Building contracts |
| 32 | + |
| 33 | +We can now compile the contracts located in the `contracts/` directory: |
| 34 | + |
| 35 | +```sh |
| 36 | +deno task build [--filter <contract-name>] [--clean] |
| 37 | +``` |
| 38 | + |
| 39 | +This does the following: |
| 40 | + |
| 41 | +- Compile the bytecode for each contract into `codgen/bytecode/*` |
| 42 | +- Generate the abi for each contract into `codgen/abi/*.ts` and the index `codegen/abis.ts` |
| 43 | + |
| 44 | +### Deploying contracts |
| 45 | + |
| 46 | +Before you can deploy contracts, let's copy the `.env.example` file to `.env` and fill in the required environment variables. |
| 47 | + |
| 48 | +```sh |
| 49 | +cp .env.example .env |
| 50 | +``` |
| 51 | + |
| 52 | +Update `tools/deploy.ts` to include new contracts you want to deploy. |
| 53 | +Make sure to specify the constructor arguments and the value, if needed. |
| 54 | + |
| 55 | +#### Deploying to Testnet |
| 56 | + |
| 57 | +To deploy to Westend Testnet, you will need to specify the `TESTNET_PRIVATE_KEY`. |
| 58 | +Check the instructions [here](https://contracts.polkadot.io/connect-to-asset-hub) to connect with your wallet and request funds. |
| 59 | + |
| 60 | +#### Deploying to a local chain |
| 61 | + |
| 62 | +For local development, checkout the instructions [here](https://contracts.polkadot.io/work-with-a-local-node) to setup and start a local chain. |
| 63 | + |
| 64 | +> Note: You can also test against `geth`, the deployment code, will detect the chain and deploy the right bytecode (evm or pvm). |
| 65 | +
|
| 66 | +> 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. |
| 67 | +
|
| 68 | +Now that you have the environment variables setup, ensure that your chain is running and deploy the contracts by running: |
| 69 | + |
| 70 | +```sh |
| 71 | +deno task deploy [--filter <contract-name>] |
| 72 | +``` |
| 73 | + |
| 74 | +This command will update the `codegen/addresses.ts` file with the deployed contract addresses, so that you can easily reference them in your apps. |
| 75 | + |
| 76 | +### Running the web app |
| 77 | + |
| 78 | +Once the contracts are deployed you can run the frontend by running: |
| 79 | + |
| 80 | +```sh |
| 81 | +deno dev --open |
| 82 | +``` |
| 83 | + |
| 84 | +This will start a development server with live reload and open your browser to the local url. |
| 85 | +The default app let you do the following actions: |
| 86 | + |
| 87 | +- Connect to different wallets |
| 88 | +- Display the connected account |
| 89 | +- Mint an NFT. |
| 90 | +- Display the minted NFT. |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +# Run cli |
| 95 | + |
| 96 | +There is an example cli in the `cli` directory that you can run to interact with the deployed contracts. |
| 97 | + |
| 98 | +```sh |
| 99 | +deno --env-file --allow-all ./cli/dao-hack.tsx |
| 100 | +``` |
| 101 | + |
| 102 | +### Running tests |
6 | 103 |
|
7 | | -## Build Dapp with ethers.js & react |
| 104 | +Use the following command to run the tests located in the `tests/` directory: |
8 | 105 |
|
9 | | -This is a Dapp boilerplate that uses ethers.js along with react to build a Dapp. |
| 106 | +```sh |
| 107 | +# start the eth-rpc and substrate node |
| 108 | +export SUBSTRATE_BIN="$POLKADOT_SDK/target/debug/substrate-node" |
| 109 | +export ETH_RPC_BIN="$POLKADOT_SDK/target/debug/eth-rpc" |
10 | 110 |
|
11 | | -See [ethers/README.md](./ethers) |
| 111 | +# start the servers in the background and run the tests in watch mode against substrate |
| 112 | +ETH_RPC=true START_SUBSTRATE_NODE=true npm run test:dev |
12 | 113 |
|
13 | | -## Build Dapp with wagmi & react & viem |
| 114 | +# start geth in the background and run the tests in watch mode against geth |
| 115 | +START_GETH=true npm run test:dev |
14 | 116 |
|
15 | | -This is a more modern Dapp boilerplate that uses Viem and Wagmi. |
16 | | -Viem is a lightweight TypeScript library for interacting with Ethereum, focusing on providing a simple, type-safe API for Ethereum JSON-RPC methods. Wagmi is a collection of React hooks for Ethereum. |
| 117 | +# use live server (http://localhost:{$RPC_PORT:-8545}) and run the tests in watch mode |
| 118 | +npm run test:dev |
| 119 | +``` |
17 | 120 |
|
18 | | -See [viem/README.md](./viem) |
| 121 | +# Learn more |
19 | 122 |
|
| 123 | +- [Asset Hub documentation](https://contracts.polkadot.io) to learn more about building Smart Contracts on Asset Hub. |
| 124 | +- [wagmi documentation](https://wagmi.sh/) to learn more about building EVM Dapps with React. |
| 125 | +- [viem documentation](https://viem.sh/) to learn more about the library used to interact with EVM contracts. |
0 commit comments