Welcome to the release notes for Scarb v2.21.0!
This release updates Scarb to Cairo v2.21.0. It brings static contract forwarding for Starknet contracts, more correct dependency resolution when a lockfile is present, and more accurate proc macro diagnostics in the language server.
Static Contract Forwarding
Want a contract that exposes another contract's functions without copying their code? With static forwarding, your contract can pass calls straight through to another contract's class. Unlike a typical proxy, which reads the target class hash from storage, the hash is baked in at compile time: no storage reads, no setup.
Here's how to use it. Say you have a counter_contract that implements ICounterContract, and you want static_proxy to expose the same interface:
#[starknet::contract]
#[feature("forward-impl")]
pub mod static_proxy {
#[storage]
struct Storage {}
// Which class to forward to: the compiled `counter_contract`.
impl CounterClassHash =
super::counter_contract__class_hash__::ForwardingClassHashImpl<ContractState>;
// Expose every `ICounterContract` function by forwarding it to that class.
#[abi(embed_v0)]
impl ForwardedImpl = super::ICounterContractForwardImpl<ContractState>;
}You don't write either of those impls yourself. Cairo generates ICounterContractForwardImpl from the interface, and Scarb generates counter_contract__class_hash__ from the contract.
Then turn forwarding on in Scarb.toml:
[[target.starknet-contract]]
forwarding = trueThat's it. Scarb compiles counter_contract first, computes its class hash, and embeds it into static_proxy automatically. Test targets pick up the same setting, so your tests run against the same hashes.
A few things to keep in mind:
- The contract you forward to must be built together with yours. It should be defined in your package or listed in
build-external-contracts. - Contracts can't forward to each other in a loop.
See the Starknet contract target docs for the full details.
Cairo Version
This version of Scarb comes with Cairo v2.21.0.
What's Changed
- Bump Cairo by @wawel37 in #3257
- Impl forwarding by @wawel37 in #3251
- Locked dependency sources by @wawel37 in #3255
- Pass a call site per derive to the proc macro server by @hakiers in #3275
Full Changelog: v2.20.1...v2.21.0