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
Getting Started with AssemblyScriptAn introduction to using AssemblyScript with the Casper Platform
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
Upgrading and Maintaining Smart ContractsAn introduction to versioning smart contracts
Calling Contracts
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
Using Contract Hash vs. Package HashAdvantages and disadvantages of using contract_hash vs. contract_package_hash when calling a contract
Best Practices for Casper Smart Contract AuthorsAn outline of best practices when developing smart contracts on a Casper network

Interacting with Contracts on the Blockchain

Additionally, the section on Interacting with the Blockchain covers installing and calling contracts using the Casper command-line client written in Rust.

TitleDescription
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
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.

Tutorials

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
A Counter on the TestnetAn example contract that maintains a counter variable on the Casper Testnet
Smart Contract UpgradesLearn how to upgrade smart contracts
NFTs on Casper with the CEP-78 NFT StandardImplementing the Casper CEP-78 NFT standard
Fungible Tokens on CasperImplement the Casper Fungible Token standard
Interacting with Runtime Return ValuesLearning how to return a value using contract code
Working with Authorization KeysRetrieving and using the authorization keys associated with a deploy
Safely Transfer Tokens to a ContractHow to handle tokens via a contract