Skip to main content

Development Prerequisites

This section explains how to fulfill the prerequisites to interact with a Casper network.

This section covers the following:

  1. Setting up a Rust development environment
  2. Installing the official Casper command-line client
  3. Setting up an Account on a Casper network
  4. Acquiring the IP address of a peer on the official Testnet or Mainnet

To develop comfortably for the Casper network, you should use Linux Ubuntu 20.04 or macOS. Developing on Windows is not advised.

caution

Casper does not officially support macOS. If you encounter any problems, reach out to the community on Telegram or Discord.

Follow the steps below to install the necessary software for your development environment.

Preparing your Development Environment

Installing curl

sudo apt install curl

Installing essential Linux packages

sudo apt install build-essential

Installing packages required for Casper tools

sudo apt-get install pkg-config
sudo apt-get install openssl
sudo apt-get install libssl-dev

Installing cargo on Linux

sudo apt install cargo

Installing Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After your next login, the installation script automatically adds Rust to your system PATH. To start using Rust immediately, run the following command in your shell instead of restarting your terminal. The command will add Rust to your system PATH.

source $HOME/.cargo/env

Verify the installation:

rustup --version

Installing cargo-casper

cargo install cargo-casper

Verify the installation:

cargo-casper --version

Installing the Casper client

The default Casper client is on crates.io. This client can transmit your deploys to a Casper network.

cargo install casper-client

Verify the installation:

casper-client --version

The Casper client can print out help information, which provides an up-to-date list of supported commands. To do so, use the following command:

casper-client --help

You can use help for each command to get the most up-to-date arguments and descriptions.

casper-client <command> --help

Accessing the Casper client source code

You can access the Casper client source code here. The lib directory contains the source for the client library, which may be called directly rather than through the CLI binary. The CLI app casper-client uses this library to implement its functionality.

If you wish to compile it, you will need to first install the nightly Rust compiler with this command:

rustup toolchain install nightly

Then, compile the source code:

cargo build --release

You will find the casper-client executable in the target/release directory.

Installing cmake

If you plan to compile contracts from the source code, including those provided in the casper-node repository, install cmake with the commands below.

sudo apt-get -y install cmake

Verify the installation with

cmake --version

Installing an IDE

We advise using an integrated development environment such as Visual Studio Code (VSC) for development. Follow these instructions to set up VSC and install plugins that would be helpful during development.

Setting up a Casper Account

The Account creation process consists of two steps:

  1. Creating an Account
  2. Funding the Account

The following video complements the instructions below, showing you the expected output.

Creating an account

The Casper blockchain uses an on-chain account-based model, uniquely identified by an AccountHash derived from a specific PublicKey.

By default, a transactional interaction with the blockchain takes the form of a Deploy cryptographically signed by the key-pair corresponding to the PublicKey used to create the account.

Users can create accounts using the Casper command-line client.

Alternatively, some Casper networks, such as the official Testnet and Mainnet, provide a browser-based block explorer that allows account creation as outlined here.

Use either method to generate an account and its corresponding cryptographic key-pair.

Generating the account hash

As a developer, you will often use an account hash, which is a 32-byte hash of the public key. This is because responses from the node contain AccountHashes instead of the direct hexadecimal-encoded public key. To view the account hash for a public key, use the account-address option of the Casper CLI client:

casper-client account-address --public-key <path-to-public_key.pem/public-key-hex>

Funding an Account

After generating the cryptographic key-pair for an Account, you must fund the account's main purse to create it on-chain.

On Testnet, you can fund an account by requesting test tokens according to this guide. You can request test tokens only once for each account.

On Mainnet, a pre-existing account must transfer CSPR tokens to the newly created account's main purse to finalize the setup. The source account needs to transfer CSPR tokens to the hexadecimal-encoded public key of the target account. This transfer will automatically create the target account if it does not exist. Currently, this is the only way to create an account on Mainnet.

Acquiring a Node Address from the Network

Clients can interact with a node on the blockchain via requests sent to that node's JSON-RPC endpoint, http://<node-ip-address>:7777 by default.

The node address is the IP of a peer node.

Both the official Testnet and Mainnet provide block explorers that list the IP addresses of nodes on their respective networks.

You can get the node-ip-address of a node on the network by visiting the following block explorers:

You will see a list of peers, and you can select the IP of any peer on the list.

Note: If the selected peer is unresponsive, pick a different peer and try again.