Scrypto [ /’skrɪptoʊ/ ] is an open-source, smart-contract programming language, designed specifically for the development of decentralized applications (dApps) on the Radix Network.
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.
- Page Sponsor
- Blueprints
- Packages
- Components
- Asset-based Token Engineering
- Installation
- MacOS
- Windows
- Linux
- Example
- Resources
Page Sponsor
DEVELOPMENT | |
Paradigm | Imperative (Procedural, Object-Oriented);
Supports Functional programming;
Structured; |
Developer(s) | |
Initial Release | 2021-12-15 |
Official Announcement | |
Latest Release | |
Documentation | |
Github Repo | |
Language | Rust |
License | |
Community |
Blueprints
Blueprints are inactive stateless source codes that live on the ledger.
Packages
Packages cater for when these blueprints need to work together. Packages verify the existence of blueprints because it instantiates them as part of their operations. Grouping blueprints together is expected to help save deployment costs.
Components
Components are like the smart contract of Radix DLT. It is created by instantiating the constructor of the blueprint, and it is responsible for distributing resources according to the logic provided in its' associated blueprint. The address of a newly created instance is generated once the creation process is completed.
Asset-based Token Engineering
Tokens are important in the DeFi space. Many DeFi protocols have tokens that either has a monetary value or are used for accounting purposes. Uniswap, the second largest DEX in the ecosystem with over $3.91 billion in total value locked (TVL), according to DeFillama, also has its token, UNI.
One of the flaws of smart contract design with the languages available today is that tokens are an afterthought when they are a big part of the ecosystem. This is what Scrypto claims to rectify as an asset-oriented language.
Asset-oriented programming is largely associated with Radix and vice versa. Tokens are built into Radix Engine. Tokens are not implemented in smart contracts but can be created by directly requesting them from the platform with some desired parameters. This negates what is obtainable as developers have to deploy a smart contract to create tokens which can open them up to security risks from incorrect contract logic.
Assets are a part of the fabric of the platform. Developers could develop their tokens in seconds by passing desired parameters to suit their needs. Radix built its engine this way to enable developers to create safe and secure tokens (assets).
Installation
MacOS
- Download and install VS Code.
- In VS Code, click on Terminal > New Terminal.
- Install xcode command line tools with the following command line:
- Install the Homebrew package manager and follow the prompts:
- Install the Java SDK, C++ compiler and LLVM:
- Install Rust compiler
- If you already have Rustup installed, make sure you are running the latest stable version:
- Enable cargo:
- Add WebAssembly target:
- Install simulator and command-line tools:
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install openjdk gcc llvm
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup update stable
source $HOME/.cargo/env
rustup target add wasm32-unknown-unknown
git clone https://github.com/radixdlt/radixdlt-scrypto.git
cd radixdlt-scrypto
cargo install --path ./simulator
Windows
- Install git by running the installer from here.
- Install Visual Studio Build Tools for Visual Studio 2019
- Install Rust from here.
- If you already have Rustup installed, make sure you are running the latest stable version:
- Install LLVM 13.0.1 (tick the option that adds LLVM to the system PATH).
- Install the Homebrew package manager and follow the prompts:
- Install cmake:
- Install Rust compiler:
- Start a new PowerShell
- Add WebAssembly target:
- Install simulator and command-line tools:
rustup update stable
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install cmake
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup target add wasm32-unknown-unknown
git clone https://github.com/radixdlt/radixdlt-scrypto.git
cd radixdlt-scrypto
cargo install --path ./simulator
Linux
- Install C++ compiler and LLVM is installed:
- Install Rust compiler
- If you already have Rustup installed, make sure you are running the latest stable version:
- Enable
cargo
in the current shell: - Add WebAssembly target:
- Install simulator and command-line tools:
sudo apt install clang build-essential llvm
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup update stable
source $HOME/.cargo/env
rustup target add wasm32-unknown-unknown
git clone https://github.com/radixdlt/radixdlt-scrypto.git
cd radixdlt-scrypto
cargo install --path ./simulator
Example
An example Scrypto blueprint that creates a fixed supply of 1000 ‘HelloTokens’.
// Import Scrypto library. Access to types such as buckets and vaults as well as methods.
use scrypto::prelude::*;
// Blueprint macro
blueprint! {
struct Hello {
// Define what resources and data will be managed by Hello components
sample_vault: Vault
}
impl Hello {
// Implement the functions and methods which will manage those resources and data
// This is a function, and can be called directly on the blueprint once deployed
pub fn instantiate_hello() -> ComponentAddress {
// Create a new token called "HelloToken," with a fixed supply of 1000, and put that supply into a bucket
let my_bucket: Bucket = ResourceBuilder::new_fungible()
.metadata("name", "HelloToken")
.metadata("symbol", "HT")
.initial_supply(1000);
// Instantiate a Hello component, populating its vault with our supply of 1000 HelloToken.
// Initialize a state.
Self {
sample_vault: Vault::with_bucket(my_bucket)
}
// Instantiate local function and globalize it to assign an address. No semi-colon returns an address.
.instantiate().globalize()
}
// This is a method, because it needs a reference to self. Methods can only be called on components
pub fn free_token(&mut self) -> Bucket {
info!("My balance is: {} HelloToken. Now giving away a token!", self.sample_vault.amount());
// If the semi-colon is omitted on the last line, the last value seen is automatically returned
// In this case, a bucket containing 1 HelloToken is returned
self.sample_vault.take(1)
}
}
}