Scrypto [ /’skrɪptoʊ/ ] is an open-source, smart-contract programming language, designed specifically for the development of decentralized applications (dApps) on Radix.
THE MEME STUDIO | Web3 Marketing Agency
Page Sponsor: The Meme Studio: Web3 Marketing Agency
https://youtu.be/-keCfLzcYv0?si=hVyYv5G-El5Vwsup
Overview
Scrypto exists as a set of libraries and compiler extensions that add features, syntax and data types to the Rust programming language, allowing for an ‘asset-oriented’ style of programming that treats tokens, NFTs and other ‘resources’ as native objects.
Features
Scrypto introduces several key features designed specifically for Radix development:
- Asset-oriented programming model: Unlike account-based models like Ethereum, Scrypto has native support for tokens, NFTs, and other digital assets as first-class primitives. Resources like tokens can be directly stored, transferred, and manipulated.
- Finite state machine model for tokens: Token behavior in Scrypto adheres to a predefined finite state machine. This provides predictable rules around things like minting, burning, transferring, and admin capabilities. The model improves security and avoids surprises.
- Access control using ‘badges': Instead of checking the message caller's address for authorization like Solidity, Scrypto uses "badges" - tokens or NFTs - to dictate access rules. This enables complex permissions not tied to accounts.
- Built-in royalty system: Smart contract developers can configure royalties to be automatically collected when their contracts are used. This incentivizes creation of reusable blueprints.
- Strong typing and compile-time checks: Scrypto leverages Rust's strong type system and compile-time checks to improve security and developer experience. Many common bugs are caught during compilation.
- Developer tooling: Scrypto includes a command line tool, simulator, testing framework, and other tooling to enable rapid smart contract development.
Syntax and Tools
Scrypto adopts a syntax similar to the Rust programming language, as it is built on the Rust compiler toolchain. Like Rust, Scrypto utilizes:
- Statically typed variables
- Immutability by default
- Explicit variable ownership
- Pattern matching
- Trait-based generics
- Closure expressions
However, Scrypto extends Rust by adding:
- New primitive data types like tokens, NFTs, badges, etc.
- Attributes like #[blueprint] to denote smart contract blueprints
- Built-in functions for blockchain interaction
- Removal of non-deterministic features like floating point numbers
Scrypto code compiles to WebAssembly (WASM) to run on the Radix virtual machine. The key tools available in the Scrypto developer toolkit include:
- Scrypto CLI: Command line tool for building, testing, and deploying Scrypto packages. It wraps cargo for blockchain workflows.
- Radix Engine Simulator (Resim): Local simulator that emulates the Radix ledger and runtime. Useful for development testing.
- Testing Framework: Tools designed for unit testing Scrypto blueprints and components.
- Radix Dashboard: GUI for deploying and interacting with Scrypto packages and components.
- Wallet SDK: APIs for connecting Scrypto dApps with the Radix Wallet.
- ROLA: Off-ledger authentication system allowing server apps to connect with on-ledger identities.
The toolkit enables rapid development, testing, and deployment of end-to-end decentralized applications with Scrypto.
Blueprints
Scrypto introduces a concept called ‘blueprints’ - similar to classes in object oriented programming - to build reusable, modular smart contract components.
Blueprints define the structure and logic for components, including:
- State variables to hold token supplies, user balances etc.
- Functions to instantiate new component instances
- Methods to modify state and execute business logic
Components are then live instances created from blueprints, like objects instantiated from classes.
This separation of blueprints and components enables:
- Reusable code: Components created from the same blueprint have shared logic but separate state. Similar to how classes define objects.
- Upgradability: Components can be instantiated from new blueprint versions to get upgrades. The blueprint system facilitates iterating code.
- Composability: Components can easily call other components to form complex decentralized apps, with clear interfaces between the parts.
- Developer incentives: Blueprint authors can charge royalties when others utilize their blueprints to build applications. This funds open source development.
Scrypto developers are encouraged to build small, modular blueprints that "do one thing well" - following Unix philosophy - rather than massive monolithic contracts.
Packages
A Scrypto package is a bundle of one or more blueprints that is published to the Radix ledger.