Skip to main content

Writing On-Chain Code

This section shows you how to write session code and smart contracts in Rust and WebAssembly (Wasm) for a Casper network. When referring to session code, these documents outline logic that executes in the context of an account. In contrast, smart contracts consist of logic installed on-chain, for use by multiple parties. There is a large overlap between the processes of writing session code versus contract code, with some semantic differences outlined in their respective documentation. The Video Series for Writing On-Chain Code accompanies the topics below.

TitleDescription
Getting Started with RustAn introduction to using Rust with the Casper Platform
Best Practices for Casper Smart Contract AuthorsAn outline of best practices when developing smart contracts on a Casper network
Writing a Basic Smart Contract in RustAn example of a smart contract built in Rust
Unit Testing Smart ContractsSteps to test contract code using the unit testing framework
Smart Contracts and Session CodeUnderstand what session code is and when you would use it over contract code
Writing Session CodeAn introduction to writing session code
Unit Testing Session CodeSteps to test session code using the unit testing framework
Installing Smart Contracts and Querying Global StateA guide on installing smart contracts and querying global state
Calling Smart Contracts with the Rust ClientSteps to call a smart contract with the Rust command-line client
Upgrading and Maintaining Smart ContractsAn introduction to versioning smart contracts
Reading and Writing to DictionariesInformation on Dictionaries and how to read and write to them on the Casper Platform.
Execution Error CodesPossible error codes when writing smart contracts.
Getting Started with AssemblyScriptAn introduction to using AssemblyScript with the Casper Platform

Additionally, the following tutorials outline some aspects of writing smart contracts on a Casper network.

TitleDescription
Getting Started VideoStep-by-step video tutorial for setting up the Casper development environment
NFTs on Casper with the CEP-78 NFT StandardImplementing the Casper CEP-78 NFT standard
A Counter on an NCTL NetworkAn example contract that maintains a counter variable on a local Casper Network with NCTL
A Counter on the TestnetAn example contract that maintains a counter variable on the Casper Testnet
Fungible Tokens on CasperImplement the Casper Fungible Token standard
Interacting with Runtime Return ValuesLearning how to return a value using contract code
Safely Transfer Tokens to a ContractHow to handle tokens via a contract
Smart Contract UpgradesLearn how to upgrade smart contracts