#syscalls #module #contract #ckb #help #write #memory

ckb-std

This library contains serveral modules help you write CKB contract with Rust

32 releases

0.15.3 Mar 25, 2024
0.15.1 Jan 31, 2024
0.14.3 Aug 25, 2023
0.14.2 Jul 4, 2023
0.1.1 Mar 25, 2020

#899 in Magic Beans

Download history 185/week @ 2023-12-22 146/week @ 2023-12-29 377/week @ 2024-01-05 97/week @ 2024-01-12 152/week @ 2024-01-19 273/week @ 2024-01-26 153/week @ 2024-02-02 115/week @ 2024-02-09 212/week @ 2024-02-16 240/week @ 2024-02-23 137/week @ 2024-03-01 223/week @ 2024-03-08 293/week @ 2024-03-15 456/week @ 2024-03-22 322/week @ 2024-03-29 106/week @ 2024-04-05

1,253 downloads per month
Used in 4 crates

MIT license

240KB
6K SLoC

C 4K SLoC // 0.1% comments Rust 2K SLoC // 0.0% comments

ckb-std

Crates.io

This library contains several modules that help you write CKB contract with Rust.

Usage

Documentation

Modules

  • syscalls module: defines CKB syscalls
  • high_level module: defines high level APIs
  • dynamic_loading module: dynamic loading primitives
  • debug! macro: a println! like macro helps debugging
  • entry! macro: defines contract entry point
  • default_alloc! macro: defines global allocator for no-std rust

Memory allocator

Default allocator uses a mixed allocation strategy:

  • Fixed block heap, only allocate fixed size(64B) memory block
  • Dynamic memory heap, allocate any size memory block

User can invoke macro with arguments to customize the heap size. The default heap size arguments are:

(fixed heap size 4KB, dynamic heap size 516KB, dynamic heap min memory block 64B)

Use the macro with arguments to change it:

default_alloc!(4 * 1024, 516 * 1024, 64)

Beware, use difference heap size or memory block size may affect the verification result of the contract, some runtime errors such as out of memory may occur; you should always test the contract after customizing.

Examples

Check examples and tests to learn how to use.

See also ckb-tool which helps you write tests.

Dependencies

~1.4–2.4MB
~55K SLoC