Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/tools/create-kadena-app/.eslintrc.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions packages/tools/create-kadena-app/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions packages/tools/create-kadena-app/.prettierignore

This file was deleted.

35 changes: 0 additions & 35 deletions packages/tools/create-kadena-app/CHANGELOG.md

This file was deleted.

165 changes: 60 additions & 105 deletions packages/tools/create-kadena-app/README.md
Original file line number Diff line number Diff line change
@@ -1,136 +1,91 @@
<!-- genericHeader start -->
# Kadena dApp Template – Local Link Guide

# @kadena/create-kadena-app
This repository contains a CLI plus a ready-to-use `template/` (contracts + frontend).
Follow these steps to download the repo and link it locally so you can use the CLI.

CLI tool to create a starter project with @kadena/client integration
---

<picture>
<source srcset="https://raw.githubusercontent.com/kadena-community/kadena.js/main/common/images/Kadena.JS_logo-white.png" media="(prefers-color-scheme: dark)"/>
<img src="https://raw.githubusercontent.com/kadena-community/kadena.js/main/common/images/Kadena.JS_logo-black.png" width="200" alt="kadena.js logo" />
</picture>
## Prerequisites

<!-- genericHeader end -->
- Node.js 18+ and npm
- Git

## Create Kadena App
Optional:

The create-kadena-app CLI tool enables you to quickly start a new application
that has Kadena Blockchain integration set up and ready to go. The application
supports Typescript and makes use of `@kadena/client` and `@kadena/pactjs-cli`.
- Docker (needed later to run the devnet inside the template)

The application is backed by a [**smart contract**][1] written in Pact that is
included for convenience and also deployed on the Kadena Blockchain, so you have
a working application from the start.
---

The two most common blockchain use cases are covered in this starter app:
## 1) Clone and install

- Reading a message from the chain (requires no transaction).
- Writing a message on the chain, which includes signing and sending a
transaction on chain and waiting for it to be mined.
```bash
git clone <this-repo-url> kadena-trial
cd kadena-trial
npm install
```

[Chainweaver][2] is used for signing transactions, since it's the Official
Kadena wallet for advanced blockchain usage and smart contract development.
---

## Supported Templates
## 2) Build the CLI

Create Kadena App supports a number of well known and widely used frameworks to
choose from when starting a new project. The following project templates are
currently available:
```bash
npm run build
```

- [Nextjs][3]
- [Vuejs][4]
- [Angular][5]
This compiles the CLI to `dist/` and copies `template/` alongside it.

## Usage
---

The recommended way of using Create Kadena App is through npx.
## 3) Link globally

```sh
npx @kadena/create-kadena-app
```bash
npm link
```

Create Kadena app allows you to pass command line arguments to set up a new
project non-interactively. While we might further expand functionality in the
future currently there's one command available, `generate-project`. See
create-kadena-app generate --help:

```sh
Usage: create-kadena-app generate-project [options]
This makes the `create-kadena` command available on your system.

Generate starter project
Verify:

Options:
-n, --name <value> Project name
-t, --template <value> Project template to use
-h, --help display help for command
```bash
create-kadena --help
```

### Options:

- `name` determines the name of the project but also the folder on the
filesystem that will contain the project. The same general operating system
folder name rules apply and are being validated.
- `template` determines the template being used for the project that is being
created. Valid values are:
- nextjs
- vuejs
- angular
- `help` displays the help menu

## The Pact smart contract

The smart contract is called `cka-message-store` and can be found [here][6]. The
folder contains two files `message-store.pact` which is the smart contract
written in Pact but also `message-store.repl` which contains a supporting test
suite. The contract is also deployed on testnet chain 0 as
`free.cka-message-store`.

The two main functions of the contract are `read-message` and `write-message`
which are shown below:

```pact
(defun read-message (account:string)
"Read a message for a specific account"

(with-default-read messages account
{ "message": "You haven't written any message yet" }
{ "message" := message }
message
)
)
---

## 4) Scaffold a new project (using the linked CLI)

```bash
mkdir my-kadena-app && cd my-kadena-app
create-kadena
```

Reading a message is unrestricted, so everyone can access the smart contract and
read the message a user has written, given the account is provided.
The CLI will scaffold a new project using the bundled `template/`.
After creation, follow the new project’s README for setup and commands.

```pact
(defun write-message (account:string message:string)
"Write a message"
---

(enforce (<= (length message) 150) "Message can be a maximum of 150 characters long")
## Alternative: Use the template directly (without the CLI)

;; Try to acquire the `ACCOUNT-OWNER` capability which checks
;; that the transaction owner is also the owner of the KDA account provided as parameter to our `write-messages` function.
(with-capability (ACCOUNT-OWNER account)
(write messages account { "message" : message })
)
)
```
You can also work straight from the `template/` folder in this repo:

- Read `template/README.md` first
- Then follow the quick start there to:
- Install `contracts` and `frontend` dependencies
- Start the devnet
- Create a dev account
- Deploy the contract
- Run the Next.js UI

---

Writing a message is guarded by a capability `ACCOUNT-OWNER`, so only the
account owner kan write a message.
## Unlink (optional)

The contract contains a single table `messages` that stores the messages for all
users.
If you want to remove the globally linked CLI:

```bash
npm unlink -g create-kadena
```

This readme doesn't aim to be a tutorial for Pact therefore we aren't going into
the complete details of the contract nor the Pact language. For more detailed
info on Pact development visit the **Build** section on [docs.kadena.io][7].
---

[1]: ##The-Pact-smart-contract
[2]: https://docs.kadena.io/basics/chainweaver/chainweaver-user-guide
[3]: https://nextjs.org/
[4]: https://vuejs.org/
[5]: https://angular.io/
[6]:
https://github.com/kadena-community/kadena.js/tree/main/packages/tools/create-kadena-app/pact
[7]: https://docs.kadena.io/
Need help? See `template/README.md` for end-to-end usage of the contracts and frontend.
2 changes: 0 additions & 2 deletions packages/tools/create-kadena-app/bin/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions packages/tools/create-kadena-app/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

import fs from "fs-extra";
import path from "path";
import inquirer from "inquirer";
import { fileURLToPath } from "url";

// Required to emulate __dirname in ES Modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function init() {
const { folder } = await inquirer.prompt<{ folder: string }>([
{
type: "input",
name: "folder",
message: "Enter your project name:",
default: "kadena-project",
},
]);
const targetPath = path.resolve(process.cwd(), folder);
const templatePath = path.resolve(__dirname, "template");

await fs.copy(templatePath, targetPath);

console.log(`\n✅ Project created in ${folder}`);
console.log("Next steps:");
console.log(` cd ${folder}`);
console.log(` npm install\n`);
}

init();
Loading