Declaring classes
In Starknet, all deployed contracts are instances of certain declared classes. Therefore, the first step of deploying a contract is declaring a class, if it hasn't been declared already.
With Starkli, this is done with the starkli declare
command.
ℹ️ Note
You need both a signer and an account for this. The commands shown in this page omit the signer and account options for better readability, and assume you've properly configured the environment variables.
You can declare the following types of contract artifacts:
- Sierra classes: output of the
starknet-compile
command; and - (Deprecated) Legacy Cairo 0 classes: output of the
starknet-compile-deprecated
command
To declare any class, simply run:
starkli declare /path/to/class/file
Starkli is capable of determining the type of class provided. There are no separate commands for Sierra and legacy classes.
Once the declaration is successful, Starkli displays the class hash declared. The class hash is needed for deploying contracts.
Sierra class compilation
When declaring Sierra classes, Starknet requires a so-called CASM hash to be provided. This is important because as of this writing, the Sierra-to-CASM compilation process isn't proven by the OS. Should the CASM hash not be provided and signed by the user, a malicious sequencer would be able to claim anything to be the CASM output, effectively deploying arbitrary code.
To come up with the CASM hash, Starkli compiles the Sierra class provided under the hood. By default, it automatically chooses one of the compiler versions shipped with Starkli itself based on the network. Users can override the compiler version used by providing a --compiler-version <VERSION>
option.
ℹ️ Note
Unless you're working with custom networks where it's infeasible for Starkli to detect the right compiler version, you shouldn't need to manually choose a version with
--compiler-version
.If Starkli does choose the wrong compiler version, try upgrading Starkli, or file a bug if you're already on the latest release.
ℹ️ Note
For advanced users, it's possible to skip the Sierra-to-CASM compilation process by directly providing a
--casm-hash <CASM_HASH>
.
Redeclaring classes
While the normal process of declaring a class involves getting the compiled contract artifact from the compiler and following the steps documented above, it's sometimes helpful to redeclare a class you found from another network.
To do so, simply run starkli declare
on any class fetched from class-at
or class-by-hash
commands. For example:
starkli class-by-hash --network sepolia SOME_CLASS_HASH_HERE > class.json
starkli declare --network mainnet ./class.json
💡 Tips
While Starkli is capable of handling its declaration, the class format retrieved from JSON-RPC is different from the original compiler output. To obtain the format identical to what comes out of the compiler, use the
--parse
flag when retrieving the class (e.g. in aclass-by-hash
command).Note that while
--parse
should work just fine most of the time, unfortunately, certain exotic classes might not be parsable. Nevertheless, Starkli would still be able to redeclare the format without parsing.