|
1 | | -# temp-template |
| 1 | +# offckb-template |
2 | 2 |
|
3 | | -TODO: Write this readme |
| 3 | +This is a Minimal Template for CKB Full-Stack Dapps generated by [offckb](https://github.com/RetricSu/offckb). |
4 | 4 |
|
5 | | -_This project was bootstrapped with [ckb-script-templates]._ |
| 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 | 6 |
|
7 | | -[ckb-script-templates]: https://github.com/cryptape/ckb-script-templates |
| 7 | +- [ckb-scripts-template](https://github.com/cryptape/ckb-script-templates) for smart contract development |
| 8 | +- [remix-vite](https://remix.run/tutorials/blog) and [CCC](https://github.com/ckb-devrel/ccc) for frontend development |
| 9 | + |
| 10 | +## Smart contract development |
| 11 | + |
| 12 | +By default, this template comes with a single simple smart contract `hello-world`: `contracts/hello-world/src/main.rs`. |
| 13 | + |
| 14 | +The smart contract is written in Rust lang. In order to develop, the following dependencies are required: |
| 15 | + |
| 16 | +- `git`, `make`, `sed`, `bash`, `sha256sum` and others Unix utilities. |
| 17 | +- `Rust` with `riscv64 target`: `rustup target add riscv64imac-unknown-none-elf` |
| 18 | +- `Clang 18+` |
| 19 | +- `cargo-generate` |
| 20 | + |
| 21 | +Check out the ckb-script-templates for more [detail](https://github.com/cryptape/ckb-script-templates/blob/main/README.md#dependencies) |
| 22 | + |
| 23 | +### Usage |
| 24 | + |
| 25 | +add a new smart-contract: |
| 26 | + |
| 27 | +```sh |
| 28 | +make generate |
| 29 | +``` |
| 30 | + |
| 31 | +build smart-contract: |
| 32 | + |
| 33 | +```sh |
| 34 | +make build |
| 35 | +``` |
| 36 | + |
| 37 | +run test: |
| 38 | + |
| 39 | +```sh |
| 40 | +make test |
| 41 | +``` |
| 42 | + |
| 43 | +run test with contract-debug logs: |
| 44 | + |
| 45 | +```sh |
| 46 | +cargo test -- --nocapture |
| 47 | +``` |
| 48 | + |
| 49 | +For more detail, check out [ckb-script-templates](https://github.com/cryptape/ckb-script-templates) |
| 50 | + |
| 51 | +## Dapp frontend development |
| 52 | + |
| 53 | +first, enter the frontend workspace: |
| 54 | + |
| 55 | +```sh |
| 56 | +cd frontend |
| 57 | +``` |
| 58 | + |
| 59 | +start the app: |
| 60 | + |
| 61 | +```sh |
| 62 | +npm i && npm run dev |
| 63 | +``` |
| 64 | + |
| 65 | +change the CKB blockchain network: |
| 66 | + |
| 67 | +```sh |
| 68 | +export NETWORK=devnet # or testnet, mainnet |
| 69 | +npm run dev |
| 70 | +``` |
| 71 | + |
| 72 | +or |
| 73 | + |
| 74 | +```sh |
| 75 | +NETWORK=devnet npm run dev |
| 76 | +``` |
| 77 | + |
| 78 | +## Deploy to devnet/testnet with offckb |
| 79 | + |
| 80 | +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. |
| 81 | + |
| 82 | +If you want to test them in devnet/testnet blockchain, then `offckb` might be the ideal selection. |
| 83 | + |
| 84 | +`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: |
| 85 | + |
| 86 | +```sh |
| 87 | +cd frontend |
| 88 | +offckb deploy --network devnet |
| 89 | +``` |
| 90 | + |
| 91 | +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. |
| 92 | + |
| 93 | +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. |
| 94 | + |
| 95 | +You can also deploy smart contracts to the CKB Testnet like this: |
| 96 | + |
| 97 | +```sh |
| 98 | +cd frontend |
| 99 | +offckb deploy --network testnet |
| 100 | +``` |
| 101 | + |
| 102 | +and start your frontend Dapp targeting Testnet: |
| 103 | + |
| 104 | +```sh |
| 105 | +cd frontend |
| 106 | +NETWORK=testnet npm run dev |
| 107 | +``` |
| 108 | + |
| 109 | +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. |
0 commit comments