Skip to content

Commit

Permalink
Merge pull request #1 from Concordium/initial-starter
Browse files Browse the repository at this point in the history
Initial starter template
  • Loading branch information
limemloh authored Jan 31, 2024
2 parents bfc21dd + 8645eb8 commit 3914385
Show file tree
Hide file tree
Showing 31 changed files with 11,691 additions and 25 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/frontend" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/contracts/my-contract" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/contracts/my-contract/deploy-scripts" # Location of package manifests
schedule:
interval: "daily"
103 changes: 103 additions & 0 deletions .github/workflows/format-lint-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Format, Lint, Build and Test
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review
env:
NODE_VERSION: "lts/*"
RUST_VERSION: "1.75"
CARGO_CONCORDIUM_VERSION: "3.2"
MY_CONTRACT_PATH: contracts/my-contract
MY_CONTRACT_DEPLOY_SCRIPT_PATH: contracts/my-contract/deploy-scripts
jobs:
rustfmt-clippy:
name: Formatting and linting smart contracts
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Install Rust toolchain with rustfmt available
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
target: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Run cargo fmt - ${{ env.MY_CONTRACT_PATH }}
working-directory: ${{ env.MY_CONTRACT_PATH }}
run: cargo fmt --check
- name: Run cargo fmt - ${{ env.MY_CONTRACT_DEPLOY_SCRIPT_PATH }}
working-directory: ${{ env.MY_CONTRACT_DEPLOY_SCRIPT_PATH }}
run: cargo fmt --check
- name: Run cargo clippy - ${{ env.MY_CONTRACT_PATH }}
working-directory: ${{ env.MY_CONTRACT_PATH }}
run: cargo clippy --locked -- -D warnings
- name: Run cargo clippy - ${{ env.MY_CONTRACT_DEPLOY_SCRIPT_PATH }}
working-directory: ${{ env.MY_CONTRACT_DEPLOY_SCRIPT_PATH }}
run: cargo clippy --locked -- -D warnings
prettier-eslint:
name: Formatting and linting frontend
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup Node for frontend
uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install NPM dependencies
working-directory: frontend
run: npm clean-install
- name: Run prettier
working-directory: frontend
run: npm run format-check
- name: Run eslint
working-directory: frontend
run: npm run lint-check
build-and-test:
name: Build and test everything
needs: [rustfmt-clippy, prettier-eslint]
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-unknown-unknown
toolchain: ${{ env.RUST_VERSION }}
- name: Install cargo-concordium from crates.io
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-concordium
version: ${{env.CARGO_CONCORDIUM_VERSION}}
- name: Build and test smart contract
working-directory: ${{ env.MY_CONTRACT_PATH }}
run: cargo concordium test --out "./concordium-out/module.wasm.v1"

# Frontend build and test
- name: Setup Node for frontend
uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install NPM dependencies
working-directory: frontend
run: npm clean-install
# This must be run after building the smart contracts.
- name: Generate smart contract clients
working-directory: frontend
run: npm run generate
- name: Build all libraries and samples
working-directory: frontend
run: npm run build
25 changes: 0 additions & 25 deletions .gitignore

This file was deleted.

8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"rust-lang.rust-analyzer",
"Concordium.concordium-smart-contracts",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rust-analyzer.linkedProjects": [
"./contracts/my-contract/Cargo.toml",
"./contracts/my-contract/deploy-scripts/Cargo.toml"
],
"[typescript][typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
}
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "concordium",
"command": "build",
"cwd": "contracts/my-contract",
"args": [
"--out",
"concordium-out/module.wasm.v1",
"--schema-embed"
],
"problemMatcher": [],
"label": "contracts/my-contract: Build smart contract"
}
]
}
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Concordium DApp starter
<!-- After fetching you can remove from here: -->

Starter project template for build DApps for the [Concordium blockchain](https://concordium.com).

**This template includes:**

- Smart contract setup with:
- Simple counter smart contract.
- Deploy script for smart contract deployment.
- Setup for integration tests.
- VSCode tasks for running build.
- GitHub Workflow, checking formatting, linter warnings and running tests.
- TypeScript dApp setup with:
- Basic setup using [Vite build tool](https://vitejs.dev/) and [React](https://react.dev/).
- [`@concordium/ccd-js-gen`](https://www.npmjs.com/package/@concordium/ccd-js-gen) to generate TypeScript smart contract clients directly from the smart contract.
- [Prettier](https://prettier.io/) and [ESLint](https://eslint.org/) recommeded setup.
- GitHub Workflow, checking formatting, linter warnings and running tests.

_Fetch this repository follow the setup instructions below._

<!-- To here -->

## Setup

Make sure to have the following installed:

- [NodeJs](https://nodejs.org).
- Rust and cargo (Recommended to install using [rustup](https://rustup.rs)).
- Recent version of [cargo concordium](https://crates.io/crates/cargo-concordium) (Install using `cargo install --locked cargo-concordium` or use it through the Concordium VS-Code extension).

## Smart contracts

### Build

To build the smart contract, navigate to the `contracts/my-contract` directory and run:

```bash
cargo concordium build --out ./concordium-out/module.wasm.v1 --schema-embed
```

_The `--out ./concordium-out/module.wasm.v1` is important, since the frontend assumes this is the location of the built smart contract._

### Run tests

To run the tests for the smart contract, navigate to the `contracts/my-contract` directory and run:

```bash
cargo concordium test --out ./concordium-out/module.wasm.v1 --schema-embed
```

_This will also build the contract, the `--out ./concordium-out/module.wasm.v1` is important, since the frontend assumes this is the location of the built smart contract._

### Contract deploy-script

Scripts for deploying and setting up the smart contract can be found in `contract/my-contract`. [See the documentation here](./contracts/my-contract/deploy-scripts/README.md).

## Frontend

To setup and install dependencies for the frontend navigate to the `frontend` directory and run:

```bash
npm install
```

### Generate smart contract clients

This project is setup to generate TypeScript smart contract clients, directly from the smart contract module and the embedded schema. Make sure to build the smart contract modules as descriped above.

To generate the smart contract clients for the frontend navigate to the `frontend` directory and run:

```bash
npm run generate
```

### Development

To start a development environment make sure to first generate the smart contract clients, then run the following from the `frontend` directory:

```bash
npm run dev
```

This will launch a development server with hot module replacement enabled.

### Build

To start build the frontend make sure to first generate the smart contract clients, then run the following from the `frontend` directory:

```bash
npm run build
```

This will bundle the project into `frontend/dist` directory.
2 changes: 2 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
concordium-out
Loading

0 comments on commit 3914385

Please sign in to comment.