This tutorial is compatible with:
- Scarb:
2.4.0
- Cairo:
2.4.0
- Sierra:
1.4.0
To install the latest version of the scarb package manager, visit Scarb Installation Page
In your project directory, you'll find a scarb.toml
file containing all necessary information for Scarb to compile your project.
To build Starknet contracts, add the Starknet version and target.starknet-contract
to your [dependencies]
in the .toml
file.
A Cairo smart contract, similar to other smart contracts, involves functions interacting with the contract's storage. These functions enable the contract to maintain and update its state.
To compile a smart contract in Cairo, add the #[starknet::contract]
attribute. This is akin to declaring a smart contract in Solidity.
Modules in Starknet organize code, encompassing the contract's storage, events, and external functions.
Consider the storage variables token_supply
and decimals
as part of the contract’s state. Functions in the contract interact with these variables, manipulating or interacting with data on the blockchain.
Use the #[abi(embed_v0)]
attribute to allow external access to functions. Implement the set and get functions as defined. Note that the set function incurs gas fees due to storage modifications, while the get function, used for reading storage values, incurs lower gas fees.
Use self.stored_data.read()
to read the stored_data
variable, where self
refers to the ContractState
type.
A contract defines the interaction between its storage and functions. The public functions allow modification or reading of the contract's storage.