Starknet by Example is a collection of examples of how to use the Cairo programming language to create smart contracts on Starknet.
- Clone this repository.
- Rust related packages:
- Install
scarbusing asdf withasdf install. Alternatively, you can installscarbmanually by following the instructions here.
All the Markdown files MUST be edited in english. To work locally in english:
-
Start a local server with
mdbook serveand visit localhost:3000 to view the book. You can use the--openflag to open the browser automatically:mdbook serve --open. -
Make changes to the book and refresh the browser to see the changes.
-
Open a PR with your changes.
To work with translations, those are the steps to update the translated content:
-
Run a local server for the language you want to edit:
./translations.sh zh-cnfor instance. If no language is provided, the script will only extract translations from english. -
Open the translation file you are interested in
po/zh-cn.pofor instance. You can also use editors like poedit to help you on this task. -
When you are done, you should only have changes into the
po/xx.pofile. Commit them and open a PR. The PR must stars withi18nto let the maintainers know that the PR is only changing translation.
The translation work is inspired from Comprehensive Rust repository.
If you wish to initiate a new translation for your language without running a local server, consider the following tips:
- Execute the command
./translations.sh new xx(replacexxwith your language code). This method can generate thexx.pofile of your language for you. - To update your
xx.pofile, execute the command./translations.sh xx(replacexxwith your language code), as mentioned in the previous chapter. - If the
xx.pofile already exists (which means you are not initiating a new translation), you should not run this command.
The current book has script that verifies the compilation of all Cairo programs in the book.
Instead of directly writing Cairo programs in the markdown files, we use code blocks that import the Cairo programs from the listing directory.
These programs are bundled into scarb packages, which makes it easier to test and build entire packages.
To run the script locally, ensure that you are at the root of the repository (same directory as this README.md file),
and run:
bash scripts/cairo_programs_verifier.sh
This will check that all the Cairo programs in the book compile successfully using scarb build, that every tests passes using scarb test, and that the scarb fmt -c command does not identify any formatting issues.
You can also use bash scripts/cairo_programs_format.sh to format all the Cairo programs in the book using scarb fmt automatically.
If you want to add a new smart contract to the book, you can follow these steps:
- Create a new directory in the
listingdirectory. - Initialize a scarb project in the new directory with
scarb init. - Add
[[target.starknet-contract]]and the starknet dependency to theScarb.tomlfile.