Skip to content

Commit 6383102

Browse files
authored
feat(template): add js-script-next-js template (#231)
* feat(template): add js-script-next-js template * fix add packages/* in pnpm-workspace * fix(template): name js script to hello-world * fix js-script tempalte package.json * fix(template): js-script isScriptDeployed * fix(template): script info of hello-world.bc * docs(template): update script descript in js-scrip template
1 parent 91ffc1c commit 6383102

37 files changed

Lines changed: 8251 additions & 2 deletions

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
onlyBuiltDependencies:
22
- cpu-features
33
- secp256k1
4+
5+
packages:
6+
- "packages/*"

src/template/option.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ export interface BareTemplateOption {
88

99
const templates: Array<BareTemplateOption> = [
1010
{
11-
name: 'Remix-Vite Bare Templates',
11+
name: 'JS Script with Next.js fullstack template',
12+
value: 'js-script-next-js',
13+
description: 'A full-stack template with Next-js and ckb-js-vm script',
14+
tag: ['next.js', 'tailwindcss', 'ckb-js-vm', 'typescript'],
15+
author: 'retric@cryptape.com',
16+
},
17+
{
18+
name: 'Rust Script with Remix-Vite fullstack template',
1219
value: 'remix-vite-template',
1320
description: 'A full-stack template with Remix-vite and ckb-script-templates',
1421
tag: ['remix', 'vite', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
1522
author: 'retric@cryptape.com',
1623
},
1724
{
18-
name: 'Next.js Bare Templates',
25+
name: 'Rust Script with Next.js fullstack template',
1926
value: 'next-js-template',
2027
description: 'A full-stack template with Next.js framework and ckb-script-templates',
2128
tag: ['next.js', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# offckb-template
2+
3+
This is a Minimal Template for CKB Full-Stack Dapps generated by [offckb](https://github.com/RetricSu/offckb).
4+
5+
Offckb does not do the magic. It just wraps the new CKB smart contract template and the CKB javascript Dapp framework into one mono-repo. Under the hook, it uses:
6+
7+
- [ckb-js-vm](https://github.com/nervosnetwork/ckb-js-vm) for smart contract development
8+
- [next-js](https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app) and [ccc](https://github.com/ckb-devrel/ccc) for frontend development
9+
10+
To start the project, install the dependecies:
11+
12+
```bash
13+
pnpm i
14+
```
15+
16+
## Script(Smart Contract)
17+
18+
The on-chain script project is powered by [ckb-js-vm](https://github.com/nervosnetwork/ckb-js-vm) bootstrapped with [`create-ckb-js-vm-app`](https://github.com/nervosnetwork/ckb-js-vm).
19+
20+
Build on-chain script:
21+
22+
```bash
23+
pnpm build
24+
```
25+
26+
Test on-chain script:
27+
28+
```bash
29+
pnpm test
30+
```
31+
32+
## dApp frontend development
33+
34+
first, enter the frontend workspace:
35+
36+
```sh
37+
cd frontend
38+
```
39+
40+
start the app:
41+
42+
```sh
43+
pnpm dev
44+
```
45+
46+
change the CKB blockchain network:
47+
48+
edit `.env` file:
49+
50+
```bash
51+
NEXT_PUBLIC_NETWORK=devnet # devnet, testnet or mainnet
52+
```
53+
54+
## Deploy to devnet/testnet with offckb
55+
56+
Once you build your smart contracts, you can deploy them to CKB blockchain with [ckb-cli](https://github.com/nervosnetwork/ckb-cli) or any other tools.
57+
58+
If you want to test them in devnet/testnet blockchain, then `offckb` might be the ideal selection.
59+
60+
`offckb` will look for the `offckb.config.ts` file to read config information. so you will need to enter the frontend workspace to do the instruction:
61+
62+
```sh
63+
cd frontend
64+
offckb deploy --network devnet
65+
```
66+
67+
If successfully deployed, you will see the deploy script info for your smart contract recorded in the path recorded in the `offckb.config.ts` file.
68+
69+
Every time you deploy a new version of your smart contracts, those script infos will be updated by `offckb` in the place recorded in `offckb.config.ts` and work out-of-box in your frontend.
70+
71+
You can also deploy smart contracts to the CKB Testnet like this:
72+
73+
```sh
74+
cd frontend
75+
offckb deploy --network testnet
76+
```
77+
78+
and start your frontend Dapp targeting Testnet:
79+
80+
edit `.env` file:
81+
82+
```bash
83+
NEXT_PUBLIC_NETWORK=testnet # devnet, testnet or mainnet
84+
```
85+
86+
```bash
87+
cd frontend
88+
pnpm dev
89+
```
90+
91+
Note that the `mainnet` network is not supported in `offckb` since `offckb` is focusing on building a friendly development environment for CKB. To gain better security, it is recommended to use production tools like [ckb-cli](https://github.com/nervosnetwork/ckb-cli) to deploy smart contracts and do transactions for the CKB mainnet.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"private": true,
3+
"workspaces": [
4+
"packages/*"
5+
],
6+
"scripts": {
7+
"build": "pnpm -r run build",
8+
"clean": "pnpm -r run clean",
9+
"test": "pnpm -r run test",
10+
"format": "pnpm -r run format"
11+
},
12+
"devDependencies": {
13+
"prettier": "~3.5.3",
14+
"prettier-plugin-organize-imports": "~4.1.0",
15+
"rimraf": "~6.0.1",
16+
"typescript": "~5.8.2"
17+
},
18+
"pnpm": {
19+
"onlyBuiltDependencies": [
20+
"esbuild"
21+
]
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_NETWORK=devnet
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22+
23+
## Targeting on Different CKB Networks
24+
25+
edit `.env` file:
26+
27+
```bash
28+
NEXT_PUBLIC_NETWORK=devnet # devnet, testnet or mainnet
29+
```
30+
31+
## Learn More
32+
33+
To learn more about Next.js, take a look at the following resources:
34+
35+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
36+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
37+
38+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
39+
40+
## Deploy on Vercel
41+
42+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
43+
44+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
25.3 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
a {
6+
@apply underline text-blue-600 hover:text-blue-800 visited:text-purple-600;
7+
}

0 commit comments

Comments
 (0)