### Install Linera Toolchain from Source Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Installs the Linera storage service and client tool binaries locally from the source code. This is useful for development and debugging purposes. ```bash cargo install --locked --path linera-storage-service cargo install --locked --path linera-service ``` -------------------------------- ### Install Linera Binaries from crates.io Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Installs the Linera storage service and client tool binaries from the crates.io registry. This is the recommended way to install the latest stable versions of the Linera command-line tools. ```bash cargo install --locked linera-storage-service@1.0.0 cargo install --locked linera-service@1.0.0 ``` -------------------------------- ### Clone Linera Protocol Repository Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Clones the Linera protocol source code from GitHub and checks out the specified release branch. This is required for installing Linera from source. ```bash git clone https://github.com/linera-io/linera-protocol.git cd linera-protocol git checkout -t origin/mainnet ``` -------------------------------- ### Start Linera Service Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Starts the Linera service in 'service' mode, exposing local APIs for interacting with the network. This is a prerequisite for querying applications. ```bash linera service --port 8080 ``` -------------------------------- ### Create XFS Partition for ScyllaDB Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md These commands guide the creation and mounting of an XFS partition, intended for ScyllaDB data in high-performance scenarios. It involves formatting a device, creating a mount point, and mounting the partition. Ensure to replace '/dev/nvme1n1' with the actual device name. ```bash sudo mkfs.xfs /dev/nvme1n1 # Replace with your device sudo mkdir -p /mnt/xfs-scylla sudo mount /dev/nvme1n1 /mnt/xfs-scylla ``` -------------------------------- ### Start Local Linera Development Network Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Starts a local Linera development network, including a validator and a faucet service running on a specified port. This command is used to set up a local testing environment. ```bash linera net up --with-faucet --faucet-port 8080 ``` -------------------------------- ### Install Rust and Wasm Toolchain Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Installs the Rust programming language and WebAssembly toolchain, which are prerequisites for developing with Linera. This command downloads and runs the official Rust installer script. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup target add wasm32-unknown-unknown ``` -------------------------------- ### Install Linera from GitHub Source Source: https://context7.com/linera-io/linera-documentation/llms.txt Clones the Linera protocol repository from GitHub, checks out a specific release branch, and then installs the storage service and client binaries from the local source. ```bash # Clone repository and checkout release branch git clone https://github.com/linera-io/linera-protocol.git cd linera-protocol git checkout -t origin/devnet_2025_01_15 # Install from source cargo install --locked --path linera-storage-service cargo install --locked --path linera-service ``` -------------------------------- ### Run Local Linera Development Network Source: https://context7.com/linera-io/linera-documentation/llms.txt Instructions for starting a local Linera validator network, including setting up a faucet and initializing a wallet. This is essential for local development and testing. ```bash # Start local network with faucet linera net up --with-faucet --faucet-port 8080 # In separate shell, create wallet linera wallet init --faucet http://localhost:8080 linera wallet request-chain --faucet http://localhost:8080 ``` -------------------------------- ### Install Linera Client Library using npm Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/setup.md Installs the Linera client library, including its WebAssembly components, from the Node package repository. This command fetches the client and adds it to your project's node_modules directory. ```shell npm install @linera/client@{{#include ../../../RELEASE_VERSION}} ``` -------------------------------- ### Build Counter Application (Wasm) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Compiles the 'counter' example application for Linera into Wasm bytecode using Cargo. This step is necessary before publishing the application. ```bash cd examples/counter && cargo build --release --target wasm32-unknown-unknown ``` -------------------------------- ### Install Protobuf Compiler (Protoc) on Linux Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Installs the Protocol Buffers compiler (protoc) for Linux x86_64 systems. This is necessary for working with Protocol Buffers, which Linera uses for defining data structures. ```bash curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.11/protoc-21.11-linux-x86_64.zip unzip protoc-21.11-linux-x86_64.zip -d $HOME/.local export PATH="$HOME/.local/bin:$PATH" ``` -------------------------------- ### Linera Validator Deployment Output Example Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/one-click.md An example of the output from the `deploy-validator.sh` script, specifically showing the generated Public Key and Account Key. These keys are essential for communicating with the Linera Protocol core team for onboarding. ```bash $ scripts/deploy-validator.sh linera.mydomain.com admin@mydomain.com ... Public Key: 02a580bbda90f0ab10f015422d450b3e873166703af05abd77d8880852a3504e4d,009b2ecc5d39645e81ff01cfe4ceeca5ec207d822762f43b35ef77b2367666a7f8 ``` -------------------------------- ### Install Linera Toolchain with Kubernetes Feature Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/kind.md Clones the Linera protocol repository, checks out a specific release branch, and then installs the Linera service with the 'kubernetes' feature enabled using Cargo. ```bash git clone https://github.com/linera-io/linera-protocol.git cd linera-protocol git checkout -t origin/{{#include ../../../RELEASE_BRANCH}} # Current release branch cargo install --locked --path linera-service --features kubernetes ``` -------------------------------- ### Start Local Linera Network Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/advanced_topics/validators.md Starts a local Linera network using the `linera net up` command. This is typically sufficient for local development and testing environments. ```bash linera net up ``` -------------------------------- ### Verify Linera Validator Installation (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/verify-installation.md This snippet demonstrates how to verify your Linera validator installation using the `linera query-validator` command. It includes prerequisite wallet initialization and chain request commands. Successful execution confirms the validator is operational and provides API hashes and the network genesis configuration hash. ```bash $ linera wallet init --faucet https://faucet.{{#include ../../../RELEASE_DOMAIN}}.linera.net $ linera wallet request-chain --faucet https://faucet.{{#include ../../../RELEASE_DOMAIN}}.linera.net $ linera query-validator grpcs:my-domain.com:443 RPC API hash: kd/Ru73B4ZZjXYkFqqSzoWzqpWi+NX+8IJLXOODjSko GraphQL API hash: eZqzuBlLT0bcoQUjOCPf2j22NfZUWG95id4pdlUmhgs WIT API hash: 4/gsw8G+47OUoEWK6hJRGt9R69RanU/OidmX7OKhqfk Source code: https://github.com/linera-io/linera-protocol/tree/ 0cd20d06af5262540535347d4cc6e5952a921d1a6a7f6dd0982159c9311cfb3e ``` -------------------------------- ### Run Validator Node with Docker Compose (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to start the Linera validator node using Docker Compose. Ensure you are in the `docker` directory and that `genesis.json` and `server.json` are present. The `-d` flag runs containers in detached mode. ```bash # Using the default pre-built image cd docker && docker compose up -d ``` -------------------------------- ### Vite Configuration for Linera Client and Workers Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/setup.md Example Vite configuration to correctly handle the Linera client library and its Web Worker entry points. This setup ensures that the client library and workers are treated as separate entries, preserving their signatures and excluding them from dependency optimization, which is necessary for proper functionality. ```typescript export default defineConfig({ build: { rollupOptions: { input: { index: 'index.html', linera: '@linera/client', }, preserveEntrySignatures: 'strict', }, }, optimizeDeps: { exclude: [ '@linera/client', ], }, }) ``` -------------------------------- ### Install Protobuf Compiler (Protoc) for Linux Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/kind.md Downloads and installs the Protocol Buffers compiler version 21.11 for Linux x86_64, used for generating code from .proto files. ```bash curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.11/protoc-21.11-linux-x86_64.zip unzip protoc-21.11-linux-x86_64.zip -d $HOME/.local export PATH="$PATH:$HOME/.local/bin" ``` -------------------------------- ### Validator Configuration Template (TOML) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md A TOML template for configuring a Linera validator. It specifies server configuration path, network protocols, proxy settings, and shard configurations. Adjust shard details based on your setup. ```toml server_config_path = "server.json" host = "" # e.g. my-subdomain.my-domain.net port = 443 [external_protocol] Grpc = "Tls" [internal_protocol] Grpc = "ClearText" [[proxies]] host = "proxy" public_port = 443 private_port = 20100 metrics_port = 21100 # Adjust depending on the number of shards you have [[shards]] host = "docker-shard-1" port = 19100 metrics_port = 21100 [[shards]] host = "docker-shard-2" port = 19100 metrics_port = 21100 [[shards]] host = "docker-shard-3" port = 19100 metrics_port = 21100 [[shards]] host = "docker-shard-4" port = 19100 metrics_port = 21100 ``` -------------------------------- ### Create and Mount XFS Partition for ScyllaDB (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/one-click.md This snippet provides an example of creating and mounting an XFS partition, recommended for production deployments with high I/O requirements, particularly for ScyllaDB. It includes formatting a device with XFS, creating a mount point, and mounting the partition. Remember to replace '/dev/nvme1n1' with your actual device name. ```bash # Example: Create and mount XFS partition sudo mkfs.xfs /dev/nvme1n1 # Replace with your device sudo mkdir -p /mnt/xfs-scylla sudo mount /dev/nvme1n1 /mnt/xfs-scylla # Then use: --xfs-path /mnt/xfs-scylla ``` -------------------------------- ### Download Genesis Configuration (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to download the genesis configuration file using `wget`. This file is essential for validators to function as it defines the initial network state. Ensure the `TESTNET_DOMAIN` variable is correctly set. ```bash wget "https://storage.googleapis.com/linera-io-dev-public/{{#include ../../../TESTNET_DOMAIN}}/genesis.json" ``` -------------------------------- ### Add Linera SDK as a Project Dependency Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Adds the Linera SDK as a dependency to a Rust project using Cargo. This allows developers to use the Linera SDK library for building Wasm applications. ```bash cargo add linera-sdk@1.0.0 ``` -------------------------------- ### Set Linera Development PATH Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/installation.md Adds the directory containing locally compiled Linera binaries to the system's PATH environment variable. This allows running Linera commands directly from the terminal when developing from source. ```bash export PATH="$PWD/target/debug:$PATH" ``` -------------------------------- ### Install Linera Toolchain using Cargo Source: https://context7.com/linera-io/linera-documentation/llms.txt Installs the Linera storage service and client binaries from crates.io using cargo. It also adds the Linera SDK as a library dependency to your project. ```bash # Install storage service and main client binaries cargo install --locked linera-storage-service@0.15.3 cargo install --locked linera-service@0.15.3 # Add SDK as library dependency cargo add linera-sdk@0.15.3 ``` -------------------------------- ### Initialize Wallet and Request Chain on Local Network Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Initializes a developer wallet and requests a new microchain using a local faucet service. This is done after starting a local development network. ```bash linera wallet init --faucet http://localhost:8080 linera wallet request-chain --faucet http://localhost:8080 ``` -------------------------------- ### Start Linera Devnet with Kind Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/kind.md Starts a local Linera development network using Kind, which manages Kubernetes clusters within Docker containers. This command builds Docker images from the Linera source and sets up the network. ```bash linera net up --kubernetes ``` -------------------------------- ### Start Linera Proxy and Server Shards Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/advanced_topics/validators.md Starts the Linera proxy for a specific server and then runs the Linera server for each shard. This involves specifying the server configuration, shard number, genesis configuration, and storage location for each shard. ```bash linera-proxy server_n.json & linera-server run --storage rocksdb:server_n_i.db --server server_n.json --shard i --genesis genesis.json & ``` -------------------------------- ### Interact with Linera Devnet (Sync Balance) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/kind.md Demonstrates interacting with the Linera devnet by synchronizing chain information and querying the local balance. It shows an example output and a warning about a deprecated command, suggesting `linera sync && linera query-balance` as a replacement. ```bash $ linera sync-balance 2024-05-21T22:30:12.061199Z INFO linera: Synchronizing chain information and querying the local balance 2024-05-21T22:30:12.061218Z WARN linera: This command is deprecated. Use `linera sync && linera query-balance` instead. 2024-05-21T22:30:12.065787Z INFO linera::client_context: Saved user chain states 2024-05-21T22:30:12.065792Z INFO linera: Operation confirmed after 4 ms 1000000. ``` -------------------------------- ### Deploy Linera Application to Testnet Source: https://context7.com/linera-io/linera-documentation/llms.txt This bash script guides through deploying a Linera application to a testnet. It includes steps for initializing a wallet for the testnet, requesting a chain from the faucet, and then publishing and creating the application using the compiled Wasm bytecode and an initial argument. ```bash # Initialize wallet for testnet linera wallet init --faucet https://faucet.devnet-2025-01-15.linera.net linera wallet request-chain --faucet https://faucet.devnet-2025-01-15.linera.net # Publish application linera publish-and-create \ target/wasm32-unknown-unknown/release/my_counter_{contract,service}.wasm \ --json-argument "42" ``` -------------------------------- ### Install mdbook and Plugins (Shell) Source: https://github.com/linera-io/linera-documentation/blob/main/README.md Installs the mdbook documentation generator and its associated plugins (linkcheck, mermaid, admonish) using cargo. The specific version of mdbook is important due to template overrides. ```shell cargo install mdbook@0.4.48 mdbook-linkcheck mdbook-mermaid mdbook-admonish ``` -------------------------------- ### Start Linera Devnet with Docker Compose Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/compose.md This command navigates to the docker directory within the linera-protocol repository and executes the compose.sh script to start a local development network. This process involves building Docker images and setting up a temporary wallet and database. ```bash cd docker && ./compose.sh ``` -------------------------------- ### Counter Example Service ABI with GraphQL Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/abi.md This Rust code illustrates the ServiceAbi implementation for a Counter example application using GraphQL. It includes the necessary imports for async_graphql Request and Response, and defines the service's query and response types. ```rust use async_graphql::{Request, Response}; type Query = Request; type Response = Response; ``` -------------------------------- ### Nginx Configuration for Linera Validator Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/requirements.md An example Nginx configuration to meet Linera validator infrastructure requirements, including HTTP2, gRPC proxying, SSL termination, and various header settings. This configuration assumes Nginx is used as a manual load balancer. ```nginx server { listen 80 http2; location / { grpc_pass grpc://127.0.0.1:19100; } } server { listen 443 ssl http2; server_name ; # e.g. my-subdomain.my-domain.net # SSL certificates ssl_certificate ; # e.g. /etc/letsencrypt/live/my-subdomain.my-domain.net/fullchain.pem ssl_certificate_key ; # e.g. /etc/letsencrypt/live/my-subdomain.my-domain.net/privkey.pem; # Proxy traffic to the service running on port 19100. location / { grpc_pass grpc://127.0.0.1:19100; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Access-Control-Allow-Origin *; } keepalive_timeout 10m 60s; grpc_read_timeout 10m; grpc_send_timeout 10m; client_header_timeout 10m; client_body_timeout 10m; } ``` -------------------------------- ### Counter Example Contract ABI Implementation Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/abi.md This Rust snippet shows a specific implementation of the ContractAbi for a Counter example application. It demonstrates how to change the 'Operation' type to 'u64' for the contract. ```rust type Operation = u64; ``` -------------------------------- ### Generate Validator Keys (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to generate validator private keys and a `server.json` configuration file using the `linera-server` binary. Requires the path to the validator configuration TOML file. The public key is outputted after execution. ```bash linera-server generate --validators /path/to/validator/configuration.toml ``` -------------------------------- ### Build Linera Docker Image Locally (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to build the Linera Docker image from source locally. It uses the `Dockerfile` in the `docker` directory and tags the image as `linera`. This process may take several minutes. ```bash docker build --build-arg git_commit="$(git rev-parse --short HEAD)" -f docker/Dockerfile . -t linera ``` -------------------------------- ### Fungible Application Transfer Operation (Rust Example) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/composition.md Illustrates a `Transfer` operation within the `fungible` application. This operation is part of a cross-application call initiated by the crowd-funding example. It specifies the owner, amount, and target account for the token transfer. This code snippet is part of a larger example and relies on the fungible application's defined operations. ```rust // ... let call = fungible::Operation::Transfer { owner, amount, target_account, }; // ... self.runtime .call_application(/* authenticated by owner */ true, fungible_id, &call); ``` -------------------------------- ### Linera Validator Deployment with Custom Options Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/one-click.md Examples of using environment variables and script flags to customize Linera validator deployment. This includes deploying with more shards, optimizing ScyllaDB performance with XFS and cache size, using custom Docker image tags for testing, and building Docker images locally. ```bash # Deploy with more shards NUM_SHARDS=8 scripts/deploy-validator.sh validator.example.com admin@example.com # Deploy with XFS partition for optimal ScyllaDB performance scripts/deploy-validator.sh validator.example.com admin@example.com \ --xfs-path /mnt/xfs-scylla --cache-size 8G # Deploy with custom image tag (for testing) scripts/deploy-validator.sh validator.example.com admin@example.com \ --custom-tag devnet_2025_08_21 # Build Docker image locally instead of using registry scripts/deploy-validator.sh validator.example.com admin@example.com --local-build ``` -------------------------------- ### Deploy Linera Validator Script Example Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/one-click.md This Bash script demonstrates the basic usage of the `deploy-validator.sh` script to deploy a Linera validator. It requires a hostname and an email address for SSL certificate generation. The script automates the configuration of Caddy, ScyllaDB, monitoring tools, and validator keys. ```bash git fetch origin git checkout -t origin/{{#include ../../../RELEASE_BRANCH}} scripts/deploy-validator.sh linera.mydomain.com admin@mydomain.com ``` -------------------------------- ### Format Code with Prettier (Shell) Source: https://github.com/linera-io/linera-documentation/blob/main/README.md Formats the project's source code using Prettier. This command requires Prettier to be installed globally. ```shell npm install -g prettier prettier --write src ``` -------------------------------- ### Run Linera Docker Compose Deployment Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md This command initiates the Linera Docker Compose deployment in detached mode. It requires the user to be in the 'docker' directory and sets the LINERA_IMAGE environment variable. The deployment includes Caddy, ScyllaDB, Proxy, Validator Shards, Prometheus, Grafana, and Watchtower. ```bash cd docker && LINERA_IMAGE=linera docker compose up -d ``` -------------------------------- ### Set Permissions for ScyllaDB Data Directory Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md These commands ensure the correct ownership and permissions are set for the ScyllaDB data directory on the mounted XFS partition. This is crucial for ScyllaDB to properly write and manage its data files. ```bash sudo mkdir -p /mnt/xfs-scylla/scylla-data sudo chown -R 999:999 /mnt/xfs-scylla/scylla-data ``` -------------------------------- ### Configure ScyllaDB for XFS Optimization Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md This YAML configuration is for a 'docker-compose.override.yml' file to optimize ScyllaDB. It specifies a volume for ScyllaDB data on the XFS partition and sets environment variables for automatic configuration, direct I/O mode, and cache size. Adjust SCYLLA_CACHE_SIZE based on available RAM. ```yaml services: scylla: volumes: - /mnt/xfs-scylla/scylla-data:/var/lib/scylla environment: SCYLLA_AUTO_CONF: 1 SCYLLA_DIRECT_IO_MODE: 'true' SCYLLA_CACHE_SIZE: '8G' # Adjust based on available RAM ``` -------------------------------- ### Rust Contract Finalization Example Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/advanced_topics/contract_finalize.md Demonstrates the `Contract::store` implementation in Rust for a Linera application. This example includes state saving and asserts that all active sessions have ended before finalizing. It defines contract state, operations, and the main contract logic. ```rust # extern crate serde; # extern crate linera_sdk; # use serde::{Deserialize, Serialize}; # use linera_sdk::linera_base_types::* # use linera_sdk::* # use linera_sdk::abi::* # use std::collections::HashSet; # use linera_sdk::views::{linera_views, RegisterView, RootView, ViewStorageContext}; # use crate::linera_sdk::views::View as _; # use linera_sdk::linera_base_types::ApplicationId; #[derive(RootView)] #[view(context = ViewStorageContext)] pub struct MyState { pub value: RegisterView, // ... } #[derive(Serialize, Deserialize, Debug)] pub enum Operation { StartSession, EndSession } pub struct MyAbi; impl ContractAbi for MyAbi { type Operation = Operation; type Response = (); } pub struct MyContract { state: MyState, runtime: ContractRuntime, active_sessions: HashSet, } impl WithContractAbi for MyContract { type Abi = MyAbi; } impl Contract for MyContract { type Message = (); type InstantiationArgument = (); type Parameters = (); type EventValue = (); async fn load(runtime: ContractRuntime) -> Self { let state = MyState::load(runtime.root_view_storage_context()) .await .expect("Failed to load state"); MyContract { state, runtime, active_sessions: HashSet::new(), } } async fn instantiate(&mut self, (): Self::InstantiationArgument) {} async fn execute_operation(&mut self, operation: Self::Operation) -> Self::Response { let caller_id = self.runtime .authenticated_caller_id() .expect("Missing caller ID"); match operation { Operation::StartSession => { assert!( self.active_sessions.insert(caller_id), "Can't start more than one session for the same caller" ); } Operation::EndSession => { assert!( self.active_sessions.remove(&caller_id), "Session was not started" ); } } } async fn execute_message(&mut self, message: Self::Message) { unreachable!("This example doesn't support messages"); } async fn store(mut self) { assert!( self.active_sessions.is_empty(), "Some sessions have not ended" ); self.state.save().await.expect("Failed to save state"); } } ``` -------------------------------- ### Serve Frontend with Cross-Origin Isolation Headers using http-server Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/setup.md Command to serve the HTML page using http-server with necessary headers for cross-origin isolation. This is crucial for using SharedArrayBuffer, which is required by the Linera client library for security reasons. Ensure Node.js is installed. ```shell npx http-party/http-server \ --header Cross-Origin-Embedder-Policy:require-corp \ --header Cross-Origin-Opener-Policy:same-origin ``` -------------------------------- ### Configure Linera Validator Node Source: https://context7.com/linera-io/linera-documentation/llms.txt Example TOML configuration file for a Linera validator node. It specifies server settings, external and internal communication protocols, and proxy and shard configurations. ```toml # validator.toml server_config_path = "server.json" host = "validator.example.com" port = 443 [external_protocol] Grpc = "Tls" [internal_protocol] Grpc = "ClearText" [[proxies]] host = "proxy" public_port = 443 private_port = 20100 metrics_port = 21100 [[shards]] host = "docker-shard-1" port = 19100 metrics_port = 21100 ``` -------------------------------- ### Define Simple Application State (Rust) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/state.md A basic Rust struct to represent the application's state. This serves as a foundational example before introducing more complex state management. ```rust struct Counter { value: u64 } ``` -------------------------------- ### Run Linera Validator Node with Docker Source: https://context7.com/linera-io/linera-documentation/llms.txt Steps to run a Linera validator node using Docker. This involves pulling a pre-built image, setting SSL environment variables, and starting the Docker Compose services. ```bash # Use pre-built image docker pull us-docker.pkg.dev/linera-io-dev/linera-public-registry/linera:latest # Set environment variables for SSL export DOMAIN="validator.example.com" export ACME_EMAIL="admin@example.com" # Start services cd docker && docker compose up -d ``` -------------------------------- ### Set Caddy SSL/TLS Environment Variables (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Environment variables to configure Caddy for SSL/TLS certificate management. `DOMAIN` should be your validator's public domain, and `ACME_EMAIL` is for Let's Encrypt notifications. Ports 80 and 443 must be accessible. ```bash export DOMAIN="your-validator.example.com" export ACME_EMAIL="admin@example.com" ``` -------------------------------- ### Pull Linera Docker Image (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to pull the latest pre-built Linera Docker image from the official registry. This is the recommended method for obtaining the Docker image. Replace `{tag}` with the desired image tag (e.g., `latest`). ```bash docker pull us-docker.pkg.dev/linera-io-dev/linera-public-registry/linera:latest ``` -------------------------------- ### Configure Docker Log Rotation (YAML) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/monitoring-logging.md Example configuration for setting up log rotation for Docker containers within a docker-compose.yml file. Specifies the logging driver and options for maximum file size and number of files. ```yaml services: proxy: logging: driver: 'json-file' options: max-size: '100m' max-file: '10' ``` -------------------------------- ### Define GraphQL QueryRoot for Linera Service Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/service.md Defines the `QueryRoot` for a Linera application's service, enabling GraphQL compatibility. This example includes a single `value` query that returns the current counter's value, interacting with the application's state. ```rust #[derive(GraphQLQuery)] #[graphql(schema_module = "crate::service") ] pub struct QueryRoot; #[derive(async_graphql::ObjectType)] impl QueryRoot { async fn value(&self, ctx: &async_graphql::Context<'_>) -> &u64 { ctx.data::().unwrap().value } } ``` -------------------------------- ### Set LINERA_IMAGE Environment Variable (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/manual-installation.md Command to set the `LINERA_IMAGE` environment variable when using Docker Compose with a locally built image. This ensures Docker Compose uses your custom image instead of a pre-built one. ```bash export LINERA_IMAGE=linera ``` -------------------------------- ### Pledge Mutation for Crowd-Funding Application (JSON) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/composition.md Shows a GraphQL mutation to pledge tokens to a crowd-funding campaign. This is an example of how a user interacts with the crowd-funding application through the Linera service. It requires the owner's identifier and the amount to pledge. ```json mutation { pledge(owner: "User:841…6c0", amount: "10") } ``` -------------------------------- ### Define GraphQL MutationRoot for Linera Service Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/service.md Defines the `MutationRoot` for a Linera application's service, allowing for the creation of serialized `Operation` values. This example includes an `increment` method that accepts a value and returns a serialized operation to increment the counter. ```rust #[derive(GraphQLQuery)] #[graphql(schema_module = "crate::service") ] pub struct MutationRoot; #[derive(async_graphql::ObjectType)] impl MutationRoot { async fn increment(&self, ctx: &async_graphql::Context<'_>, value: u64) -> Operation { Operation::NewCounterOperation(counter::Operation::Increment { value }) } } ``` -------------------------------- ### Interact with Linera Application (JavaScript) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/interactivity.md This snippet shows how to get a reference to a Linera application backend using its ID and then query its state. It specifically demonstrates querying the 'value' of a counter application and updating a UI element. Assumes the 'linera' client and 'COUNTER_APP_ID' are defined. ```javascript const COUNTER_APP_ID = '2b1a0df8868206a4b7d6c2fdda911e4355d6c0115b896d4947ef8e535ee3c6b8'; const backend = await client.frontend().application(COUNTER_APP_ID); async function updateCount() { const response = await backend.query('{ "query": "query { value }" }'); document.getElementById('count').innerText = JSON.parse(response).data.value; } updateCount(); ``` -------------------------------- ### Run Linera Node Service Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/core_concepts/node_service.md Starts the Linera node service in service mode. By default, it runs on port 8080, but this can be changed using the --port flag. The service executes blocks and exposes GraphQL APIs. ```bash linera service ``` -------------------------------- ### Check ScyllaDB aio-max-nr Kernel Parameter Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/requirements.md This command checks the current value of the maximum number of asynchronous I/O operations allowed in ScyllaDB's kernel context. This value is critical for performance, and ensuring it meets the recommended threshold is important. ```bash cat /proc/sys/fs/aio-max-nr ``` -------------------------------- ### Persist ScyllaDB aio-max-nr Kernel Parameter Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/requirements.md These commands make the `fs.aio-max-nr` kernel parameter change persistent across system reboots. It first adds the setting to the sysctl configuration file and then applies the changes. This ensures ScyllaDB maintains optimal performance settings after a restart. ```bash echo "fs.aio-max-nr = 1048576" | sudo tee -a /etc/sysctl.conf sudo sysctl -p /etc/sysctl.conf ``` -------------------------------- ### Configure Custom Wallet Directory Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Sets environment variables to specify custom locations for Linera wallet files, keystore, and storage. Useful for managing multiple wallets and networks. ```bash DIR=$HOME/my_directory mkdir -p $DIR export LINERA_WALLET="$DIR/wallet.json" export LINERA_KEYSTORE="$DIR/keystore.json" export LINERA_STORAGE="rocksdb:$DIR/wallet.db" ``` -------------------------------- ### List Applications Query (GraphQL) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md A GraphQL query to list all applications deployed on a specified chain ID. It retrieves the ID, description, and link for each application. Requires a valid chain ID. ```graphql query { applications(chainId: "...") { id description link } } ``` -------------------------------- ### Publish and Create Linera Application Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Publishes the contract and service Wasm bytecode for an application and creates an instance of it on the network, initializing it with provided JSON arguments. This command deploys the application. ```bash linera publish-and-create \ ../target/wasm32-unknown-unknown/release/counter_{contract,service}.wasm \ --json-argument "42" ``` -------------------------------- ### Configure Linera Wallet and Storage Source: https://context7.com/linera-io/linera-documentation/llms.txt This snippet demonstrates setting up Linera wallet and storage configurations using environment variables or command-line flags. It shows how to specify wallet files and database paths for different Linera operations. ```bash export LINERA_WALLET="$HOME/wallet2.json" export LINERA_KEYSTORE="$HOME/keystore2.json" export LINERA_STORAGE="rocksdb:$HOME/wallet2.db" # Or use command-line flags linera --wallet wallet2.json --storage rocksdb:wallet2.db wallet show # Or use numbered wallet shortcuts export LINERA_WALLET_2="$HOME/wallet2.json" export LINERA_STORAGE_2="rocksdb:$HOME/wallet2.db" linera -w 2 wallet show ``` -------------------------------- ### Synchronize Chain and Query Balance Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/getting_started/hello_linera.md Synchronizes the current chain with the Linera network and displays the chain's balance. These commands are used to verify network connectivity and state. ```bash linera sync linera query-balance ``` -------------------------------- ### Initialize Wallet and Request Chain (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/deploy.md Initializes a Linera wallet for a specific testnet and requests a new chain from the faucet. This is a prerequisite for deploying applications to devnets and testnets, ensuring the new chain has sufficient tokens. ```bash linera wallet init --faucet https://faucet.{{#include ../../../RELEASE_DOMAIN}}.linera.net linera wallet request-chain --faucet https://faucet.{{#include ../../../RELEASE_DOMAIN}}.linera.net ``` -------------------------------- ### Create New Linera Project Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/creating_a_project.md Creates a new Linera project with the specified name. This command bootstraps the project by generating core files like Cargo.toml, src/lib.rs, src/state.rs, src/contract.rs, and src/service.rs. Ensure this command is run outside the 'linera-protocol' directory. ```bash linera project new my-counter ``` -------------------------------- ### Create and Initialize a Linera Wallet Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/core_concepts/wallets.md Initializes a new Linera developer wallet and requests a chain from the faucet. Requires a faucet URL to be set as an environment variable. This is the primary method for developers to set up their initial wallet on a Linera network. ```bash linera wallet init --faucet $FAUCET_URL linera wallet request-chain --faucet $FAUCET_URL ``` -------------------------------- ### Create Developer Wallet and Chain on Linera Testnet Source: https://context7.com/linera-io/linera-documentation/llms.txt Initializes a Linera developer wallet, requests a chain from the faucet on the specified testnet, and then synchronizes the wallet and queries the balance. ```bash # Initialize wallet and request chain from faucet linera wallet init --faucet https://faucet.devnet-2025-01-15.linera.net linera wallet request-chain --faucet https://faucet.devnet-2025-01-15.linera.net # Verify setup linera sync linera query-balance ``` -------------------------------- ### Create Initial Network Genesis Configuration Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/advanced_topics/validators.md Creates the initial state configuration for the Linera network, including defining the number of chains, initial funding, and the genesis configuration file. It also sets up a wallet for a client and initializes the local node storage. ```bash linera --wallet wallet.json --storage rocksdb:linera.db create-genesis-config 10 --genesis genesis.json --initial-funding 10 --committee committee.json ``` -------------------------------- ### Initialize Linera Client (JavaScript) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/interactivity.md Initializes the Linera client library. This crucial step downloads the WebAssembly binary, sets up memory, and prepares the client for interaction with the Linera network. It's the first step after importing the library. ```javascript await linera.default(); ``` -------------------------------- ### Publish and Create Application (Bash) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/deploy.md Deploys a Linera application by publishing its contract and service bytecode and creating a new microchain. Requires specifying the paths to the WASM bytecode and the JSON-encoded initialization arguments. This command is used for both local network and devnet/testnet deployments after wallet configuration. ```bash linera publish-and-create \ target/wasm32-unknown-unknown/release/my_counter_{contract,service}.wasm \ --json-argument "42" ``` -------------------------------- ### Configure Linera Wallet for Devnet Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/devnets/kind.md Exports environment variables required to connect your Linera wallet to the locally running devnet. These variables specify the paths to the wallet and keystore JSON files, and the client database. ```bash export LINERA_WALLET="/tmp/.tmpIOelqk/wallet_0.json" export LINERA_KEYSTORE="/tmp/.tmpIOelqk/keystore_0.json" export LINERA_STORAGE="rocksdb:/tmp/.tmpIOelqk/client_0.db" ``` -------------------------------- ### Request Chain from Faucet for New Wallet Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/core_concepts/wallets.md Initializes a new wallet and requests a chain directly from a faucet. This is a simplified method for test networks. ```bash linera --wallet wallet2.json --storage rocksdb:linera2.db wallet init --faucet $FAUCET_URL linera --wallet wallet2.json --storage rocksdb:linera2.db wallet request-chain --faucet $FAUCET_URL ``` -------------------------------- ### External Caddy Configuration for Linera Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/requirements.md Configuration for an external Caddy server (v2.4.3+) to handle Linera validator proxying, automatic SSL with Let's Encrypt, and security headers. This is an alternative to the built-in Caddy service. ```caddy { email {$EMAIL} } {$DOMAIN:localhost} { # Automatic HTTPS with Let's Encrypt # Reverse proxy to the Linera proxy container (gRPC over HTTPS) reverse_proxy https://proxy:443 { transport http { versions h2c 2 dial_timeout 60s response_header_timeout 60s tls_insecure_skip_verify } header_up Host {host} header_up X-Real-IP {remote} header_up X-Forwarded-For {remote} header_up X-Forwarded-Proto {scheme} } # Security headers header { Strict-Transport-Security "max-age=31536000; includeSubDomains" X-Frame-Options "SAMEORIGIN" X-Content-Type-Options "nosniff" X-XSS-Protection "1; mode=block" -Server } encode gzip } ``` -------------------------------- ### Set ScyllaDB aio-max-nr Kernel Parameter Source: https://github.com/linera-io/linera-documentation/blob/main/src/operators/testnets/requirements.md This command temporarily sets the `fs.aio-max-nr` kernel parameter to 1048576. This value is recommended for optimal ScyllaDB performance, especially in resource-constrained environments. The change takes effect immediately but will not persist across reboots. ```bash echo 1048576 | sudo tee /proc/sys/fs/aio-max-nr ``` -------------------------------- ### Serve mdbook Documentation Locally (Shell) Source: https://github.com/linera-io/linera-documentation/blob/main/README.md Serves the mdbook documentation locally, allowing developers to preview changes before deployment. After running this command, open the provided URL in your browser. ```shell mdbook serve ``` -------------------------------- ### Basic HTML Structure for Linera Frontend Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/frontend/setup.md A simple HTML file to serve as the foundation for the Linera frontend application. This file includes elements for displaying chain ID, click count, and a button to trigger an action. It's the primary file for frontend development. ```html Counter

Chain: requesting chain…

Clicks: 0

``` -------------------------------- ### Implement Contract Instantiation (Rust) Source: https://github.com/linera-io/linera-documentation/blob/main/src/developers/backend/contract.md Implements the `Contract::instantiate` method, called only once when an application is created. It initializes the application's state, potentially using provided parameters. ```rust async fn instantiate(argument: Self::InitializationArgument, runtime: sled::Runtime) -> Self { let state = S::try_from(argument).await.expect("Failed to create state"); CounterContract { state, runtime } } ``` -------------------------------- ### Create New Linera Application Project Source: https://context7.com/linera-io/linera-documentation/llms.txt Generates a scaffolded project structure for a new Linera application outside of the main linera-protocol directory. This includes essential files like Cargo.toml, lib.rs, state.rs, contract.rs, and service.rs. ```bash # Create new project outside linera-protocol directory linera project new my-counter cd my-counter # Generated files: # - Cargo.toml: project manifest with dependencies # - src/lib.rs: ABI definition # - src/state.rs: application state # - src/contract.rs: contract binary target # - src/service.rs: service binary target ``` -------------------------------- ### Manage Linera Chains: List and Create Source: https://context7.com/linera-io/linera-documentation/llms.txt This section provides bash commands for managing Linera chains within a wallet. It includes instructions for displaying all chains, creating a new chain for the current wallet or another wallet using a public key, and assigning a newly created chain. It also covers creating multi-owner chains with specified owners and leader rounds. ```bash # Display all chains linera wallet show # Output shows chain IDs, owners, block heights # Default chain displayed in green # Create chain for current wallet linera open-chain # Create chain for another wallet using their public key linera keygen # on wallet2 to get public key linera open-chain --to-public-key 6443634d872afbbfcc3059ac87992c4029fa88e8feb0fff0723ac6c914088888 # Assign chain to wallet2 linera --wallet wallet2.json assign \ --key 6443634d872afbbfcc3059ac87992c4029fa88e8feb0fff0723ac6c914088888 \ --message-id e476187f6ddfeb9d588c7b45d3df334d5501d6499b3f9ad5595cae86cce16a65010000000000000000000000 # Create multi-owner chain # Create chain with multiple owners and multi-leader rounds linera open-multi-owner-chain \ --chain-id e476187f6ddfeb9d588c7b45d3df334d5501d6499b3f9ad5595cae86cce16a65010000000000000000000000 \ --owner-public-keys 6443634d872afbbfcc3059ac87992c4029fa88e8feb0fff0723ac6c914088888 \ ca909dcf60df014c166be17eb4a9f6e2f9383314a57510206a54cd841ade455e \ --multi-leader-rounds 2 ```