Starknet Smart Contracts
En todas las secciones anteriores, principalmente ha escrito programas con un punto de entrada main
. En las próximas secciones, aprenderá a escribir e implementar contratos inteligentes en Starknet.
One of the applications of the Cairo language is to write smart contracts for the Starknet network. Starknet is a permissionless network that leverages zk-STARKs technology for scalability. As a Layer-2 scalability solution for Ethereum, Starknet's goal is to offer fast, secure, and low-cost transactions. It functions as a Validity Rollup (commonly known as a zero-knowledge Rollup) and is built on top of the Cairo language and the Starknet VM.
Un contrato inteligente en Starknet en términos simples, es un programa que puede ejecutarse en la VM de Starknet. Dado que se ejecutan en la VM, tienen acceso al estado persistente de Starknet, pueden modificar variables en los estados de Starknet, comunicarse con otros contratos e interactuar sin problemas con la L1 subyacente.
Starknet contracts are denoted by the #[contract]
attribute. We'll dive deeper into this in the next sections.
If you want to learn more about the Starknet network itself, its architecture and the tooling available, you should read the Starknet Book. This section will focus on writing smart contracts in Cairo.
Scarb
Scarb supports smart contract development for Starknet. To enable this functionality, you'll need to make some configurations in your Scarb.toml
file (see Installation for how to install Scarb).
You have to add the starknet
dependency and add a [[target.starknet-contract]]
section to enable contract compilation.
Below is the minimal Scarb.toml file required to compile a crate containing Starknet contracts:
[package]
name = "package_name"
version = "0.1.0"
[dependencies]
starknet = ">=2.4.0"
[[target.starknet-contract]]
For additional configuration, such as external contract dependencies, please refer to the Scarb documentation.
Each example in this chapter can be used with Scarb.