https://github.com/code-monad/ckb-tutorial-contract
a simple tutorial for how to write ckb contract using rust
https://github.com/code-monad/ckb-tutorial-contract
ckb contract rust template-project tutorial
Last synced: 4 months ago
JSON representation
a simple tutorial for how to write ckb contract using rust
- Host: GitHub
- URL: https://github.com/code-monad/ckb-tutorial-contract
- Owner: code-monad
- Created: 2024-06-02T05:17:27.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-02T06:38:30.000Z (about 1 year ago)
- Last Synced: 2024-12-27T21:42:12.836Z (5 months ago)
- Topics: ckb, contract, rust, template-project, tutorial
- Language: Rust
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tutorial-contract
## How to generate/init a contract project
### Prerequisite
Follow https://github.com/cryptape/ckb-script-templates
- `git`, `make`, `sed`, `bash`, `sha256sum` (you have these on most unix compatible systems)
- `rust`, follow: https://rustup.rs/ , and do: `rustup target add riscv64imac-unknown-none-elf`
- `llvm` > 16
- `cargo-generate`, `cargo install cargo-generate`### Generate a project
```bash
cargo generate gh:cryptape/ckb-script-templates workspace --name my-first-contract
cd my-first-contract
```### Generate a contract inside the project
Generate a contract with a given name
```bash
make generate
🤷 Project Name: my-contract
🔧 Destination: ./my-first-contract/contracts/my-contract ...
🔧 project-name: my-contract ...
🔧 Generating template ...
🔧 Moving generated files into: `./tutorial-contract/contracts/my-contract`...
🔧 Initializing a fresh Git repository
✨ Done! New project created ./tutorial-contract/contracts/my-contract
```## Implement it!
open `./contracts/my-contract`, fill your logic in `src/main.rs`
## Write your test in `tests/src/tests.rs` !
test cases goes into `tests/tests.rs`, you can also use your own project structure.
## Build it, test it!
1. run `make build MODE=debug` to build your contract
2. run `make test` to test your contract## Distribute your contract!
0. build your contract a release binary: `make build MODE=release`
1. ensure you have installed ckb-cli: https://github.com/nervosnetwork/ckb-cli
2. generate a deployment info: `ckb-cli --url https://testnet.ckb.dev/rpc deploy init-config --deployment-config deploy.yaml --output-format yaml`
3. generate your deployment tx, and sign it: `mkdir -p ./migration && ckb-cli --url https://testnet.ckb.dev/rpc deploy gen-txs --info-file deploy.toml --migration-dir migration --from-address YOUR_ADDRESS --fee-rate 1000 --deployment-config deploy.yaml --sign-now`
4. send your tx: `deploy apply-txs --info-file deploy.toml --migration-dir ./migration`