### Install and Run Avail Docs Source: https://github.com/availproject/docs/blob/main/README.md Install project dependencies and start the development server. Ensure Node.js 20+ and pnpm are installed. ```bash pnpm install pnpm dev ``` -------------------------------- ### Minimal Staking Validation Example Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/staking-validate/index.mdx This Go code snippet demonstrates the minimal setup required to create and execute a staking validation transaction. It includes creating transaction preferences, executing the transaction, and checking its success. Ensure you have the necessary SDK and account setup before running. ```go package main import ( "fmt" "log" "github.com/availproject/avail-sdk-go/avail" ) func main() { // Replace with your actual account and SDK initialization acc := avail.NewKeypair("//Alice") // Example account SDK := avail.NewSDK(avail.NewHTTPProvider("http://localhost:18871")) // Example provider // Define validation preferences prefs := avail.StakingPreferences{ // Set your desired preferences here // For example: // Commission: 0.05, // 5% commission // MaxCommission: 0.10, // 10% max commission // Blocked: false, // Not blocked } // Create the validate transaction tx := SDK.Tx.Staking.Validate(prefs) // Execute the transaction res, err := tx.ExecuteAndWatchInclusion(acc, SDK.NewTransactionOptions()) if err != nil { log.Fatalf("Transaction failed: %v", err) } // Check if the transaction was successful if !res.IsSuccessful().UnsafeUnwrap() { log.Fatal("Transaction was not successful") } fmt.Println("Validation transaction successful") // Printing out all the values of the transaction fmt.Println(fmt.Sprintf(`Block Hash: %v, Block Index: %v, Tx Hash: %v, Tx Index: %v`, res.BlockHash.ToHexWith0x(), res.BlockNumber, res.TxHash.ToHexWith0x(), res.TxIndex)) } ``` -------------------------------- ### Run Avail Node on Development Network Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/become-a-validator/basics/index.mdx Execute this command to start an Avail Node connected to the development network. This is useful for testing and initial setup. ```bash ./avail-node --chain dev ``` -------------------------------- ### Start Development Server Source: https://github.com/availproject/docs/blob/main/content/docs/nexus/nexus-sdk/quickstart/index.mdx Run this command to start the local development server and access your application in the browser. ```bash npm run dev ``` -------------------------------- ### Install avail-go-sdk Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/index.mdx Installs the Avail Go SDK version 0.2.7 into your Go project. This command adds the SDK as a dependency. ```bash go get github.com/availproject/avail-go-sdk@v0.2.7 ``` -------------------------------- ### Install Go Dependencies Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/da-create-application-key/index.mdx If you encounter errors related to missing dependencies, run this command to download and install them. ```bash go mod tidy ``` -------------------------------- ### Start Avail Node Service Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/become-a-validator/upgrade-your-validator/index.mdx Use this command to start the Avail node service after the upgrade process. ```bash sudo systemctl start avail.service ``` -------------------------------- ### Example Avail Node Output Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-full-node/full-node/index.mdx This is an example of the terminal output you should expect after successfully running the Avail node. ```text 2024-04-29 07:48:22 Avail Node 2024-04-29 07:48:22 โœŒ๏ธ version 2.1.1-8608dc47f00 2024-04-29 07:48:22 โค๏ธ by Avail Project , 2017-2024 2024-04-29 07:48:22 ๐Ÿ“‹ Chain specification: Avail Turing Network 2024-04-29 07:48:22 ๐Ÿท Node name: possible-point-3102 2024-04-29 07:48:22 ๐Ÿ‘ค Role: FULL 2024-04-29 07:48:22 ๐Ÿ’พ Database: ParityDb at ./output/chains/avail_turing_network/paritydb/full 2024-04-29 07:48:27 ๐Ÿ”จ Initializing Genesis block/state (state: 0x5603โ€ฆ9c01, header-hash: 0xd3d2โ€ฆ8b70) 2024-04-29 07:48:27 ๐Ÿ‘ด Loading GRANDPA authority set from genesis on what appears to be first startup. 2024-04-29 07:48:29 ๐Ÿ‘ถ Creating empty BABE epoch changes on what appears to be first startup. 2024-04-29 07:48:29 ๐Ÿท Local node identity is: 12D3KooWELgzaRZqsHNyUodhZZF7A1ydsRpgLsY7fojDegKni4YF 2024-04-29 07:48:29 Prometheus metrics extended with avail metrics 2024-04-29 07:48:29 ๐Ÿ’ป Operating system: linux 2024-04-29 07:48:29 ๐Ÿ’ป CPU architecture: x86_64 2024-04-29 07:48:29 ๐Ÿ’ป Target environment: gnu 2024-04-29 07:48:29 ๐Ÿ’ป CPU: DO-Premium-Intel 2024-04-29 07:48:29 ๐Ÿ’ป CPU cores: 4 2024-04-29 07:48:29 ๐Ÿ’ป Memory: 7937MB 2024-04-29 07:48:29 ๐Ÿ’ป Kernel: 5.15.0-105-generic 2024-04-29 07:48:29 ๐Ÿ’ป Linux distribution: Ubuntu 22.04.4 LTS 2024-04-29 07:48:29 ๐Ÿ’ป Virtual machine: yes 2024-04-29 07:48:29 ๐Ÿ“ฆ Highest known block at #0 2024-04-29 07:48:29 Running JSON-RPC server: addr=127.0.0.1:9944, allowed origins=["http://localhost:*", "http://127.0.0.1:*", "https://localhost:*", "https://127.0.0.1:*", "https://polkadot.js.org"] 2024-04-29 07:48:29 ๐Ÿ CPU score: 950.72 MiBs 2024-04-29 07:48:29 ๐Ÿ Memory score: 4.02 GiBs 2024-04-29 07:48:29 ๐Ÿ Disk score (seq. writes): 845.72 MiBs 2024-04-29 07:48:29 ๐Ÿ Disk score (rand. writes): 338.52 MiBs 2024-04-29 07:48:29 ใ€ฝ๏ธ Prometheus exporter started at 127.0.0.1:9615 2024-04-29 07:48:30 ๐Ÿ” Discovered new external address for our node: /ip4/139.59.94.121/tcp/30333/ws/p2p/12D3KooWELgzaRZqsHNyUodhZZF7A1ydsRpgLsY7fojDegKni4YF 2024-04-29 07:48:34 โš™๏ธ Syncing, target=#137399 (9 peers), best: #1000 (0x9e8fโ€ฆ55ab), finalized #512 (0x0a9aโ€ฆ875a), โฌ‡ 316.3kiB/s โฌ† 14.2kiB/s 2024-04-29 07:48:39 โš™๏ธ Syncing 235.4 bps, target=#137399 (9 peers), best: #2177 (0x5828โ€ฆe9da), finalized #2048 (0x2f65โ€ฆ3b2e), โฌ‡ 113.3kiB/s โฌ† 5.5kiB/s 2024-04-29 07:48:43 [3097] ๐Ÿ’ธ generated 8 npos targets 2024-04-29 07:48:43 [3097] ๐Ÿ’ธ generated 8 npos voters, 8 from validators and 0 nominators 2024-04-29 07:48:43 [#3097] ๐Ÿ—ณ creating a snapshot with metadata SolutionOrSnapshotSize { voters: 8, targets: 8 } 2024-04-29 07:48:43 [#3097] ๐Ÿ—ณ Starting phase Signed, round 1. ``` -------------------------------- ### Create Next.js App and Install SDK Source: https://github.com/availproject/docs/blob/main/content/docs/nexus/nexus-sdk/get-started/nexus-sdk-setup/index.mdx Scaffolds a new Next.js project and installs the Nexus SDK using pnpm. ```bash pnpm create next-app@latest my-nexus-app --ts --eslint --app --src-dir cd my-nexus-app pnpm add @avail-project/nexus-core ``` -------------------------------- ### Install avail-js-sdk Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/index.mdx Install the avail-js-sdk version 0.4.1. This SDK is used for interacting with the Avail network using JavaScript. ```bash pnpm add avail-js-sdk@0.4.1 ``` -------------------------------- ### Example Avail Head Response Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-bridge-api/avail-head/index.mdx This is an example JSON response from the /avl/head endpoint, showing the start and end block numbers tracked by the bridge. ```json { "data":{ "end":512738, "start":488581 } } ``` -------------------------------- ### Initialize Avail SDK with Go Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/system-account/index.mdx This Go snippet demonstrates the initialization of the Avail SDK and fetching the latest block hash. It serves as a starting point for interacting with the Avail network using Go. ```go package main import ( "fmt" "log" prim "github.com/availproject/avail-go-sdk/primitives" "github.com/availproject/avail-go-sdk/sdk" syPallet "github.com/availproject/avail-go-sdk/metadata/pallets/system" "github.com/availproject/avail-go-sdk/primitives" ) func main() { // Initialize the SDK sdk, err := sdk.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } // Get the latest block hash latestBlockHash, err := sdk.Client.BestBlockHash() if err != nil { log.Fatalf("Failed to get latest block hash: %v", err) } ``` -------------------------------- ### Initialize Avail SDK and Account Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-bridge-api/vector-send-message/index.mdx Initializes the Avail SDK with the provided RPC URL and sets up the account using a mnemonic phrase from a configuration file. ```rust use alloy_network::EthereumWallet; use alloy_provider::ProviderBuilder; use anyhow::Result; use avail_bridge_tools::{address_to_h256, AvailBridgeContract, BridgeApiMerkleProof, Config}; use avail_rust::avail::runtime_types::bounded_collections::bounded_vec::BoundedVec; use avail_rust::avail::vector::calls::types::send_message::Message; use avail_rust::{avail, AvailExtrinsicParamsBuilder, Keypair, SecretUri, WaitFor, SDK}; use reqwest::Url; use serde::{Deserialize, Serialize}; use std::fs; use std::str::FromStr; use std::time::Duration; #[tokio::main] async fn main() -> Result<()> { let content = fs::read_to_string("./config.toml").expect("Read config.toml"); let config = toml::from_str::(&content).expect("Parse config.toml"); println!("Using config:\n{:#?}", config); let sdk = SDK::new(config.avail_rpc_url.as_str()) .await .expect("Initializing SDK"); let secret_uri = SecretUri::from_str(config.avail_mnemonic.as_str()).expect("Valid secret URI"); let account = Keypair::from_uri(&secret_uri).expect("Valid secret URI"); } ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/availproject/docs/blob/main/content/docs/da/build/rollups/zkevm/guide/index.mdx Clone the validium-contracts repository and install necessary npm packages. This is the initial setup step for deploying the contracts. ```bash git clone git@github.com:availproject/validium-contracts.git cd validium-contracts npm i ``` -------------------------------- ### Get Block Header using avail-rust Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/chain-get-block/index.mdx This example shows how to fetch block headers with the avail-rust SDK. It covers getting both the latest block header and a header for a specific block hash. ```APIDOC ## Get Block Header (avail-rust) ### Description Fetches the latest block header or a header for a specific block hash using the avail-rust SDK. ### Method `rpc::chain::get_header(client: &Client, block_hash: Option) -> Result` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use avail_rust::prelude::*; pub async fn get_block_header() -> Result<(), ClientError> { let sdk = SDK::new("wss://turing-rpc.avail.so/ws").await?; // Get the latest block header let latest_block_header = rpc::chain::get_header(&sdk.client, None).await?; println!("Latest Block Header: {:?}", latest_block_header); // Get the block header for a specific block let block_hash = new_h256_from_hex("0x75a6c54bb5ea904e47fa151956992d7cf543bc7c936d78488e311db8e10397c1")?; let block_header = rpc::chain::get_header(&sdk.client, Some(block_hash)).await?; println!("Block Header: {:?}", block_header); Ok(()) } #[tokio::main] async fn main() -> Result<(), ClientError> { get_block_header().await?; Ok(()) } ``` ### Response #### Success Response (200) Returns the block header object. #### Response Example ```json { "hash": "0x...", "parentHash": "0x...", "number": 12345, "stateRoot": "0x...", "extrinsicsRoot": "0x..." } ``` ``` -------------------------------- ### Minimal Go Example for Creating an Application Key Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/da-create-application-key/index.mdx This Go code snippet demonstrates the minimal steps required to create an application key. It covers account creation from a seed, SDK initialization, generating the transaction, executing it, and handling the response events. ```go package main import ( "fmt" "log" "os" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/types" "github.com/availproject/avail-sdk-go/SDK" daPallet "github.com/availproject/avail-sdk-go/SDK/pallet/data_availability" ) func main() { // Load environment variables (e.g., from .env file) // For simplicity, this example assumes SEED is set in the environment. // In a real application, you would use a library like "github.com/joho/godotenv" to load .env files. // Make sure the SEED environment variable is set seed := os.Getenv("SEED") if seed == "" { log.Fatal("SEED environment variable is not set") } // Create an account from the SEED environment variable acc, err := SDK.Account.NewKeyPair(seed) if err != nil { log.Fatalf("Failed to create account: %v", err) } fmt.Println("Your account Address: " + acc.SS58Address(42)) // Initialize an SDK instance sdk, err := SDK.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } // Generate an application key // Please note that the transaction will fail if // an AppID with the same key already exists key := "My new application key" tx := sdk.Tx.DataAvailability.CreateApplicationKey([]byte(key)) // Execute the transaction res, err := tx.ExecuteAndWatchInclusion(acc, SDK.NewTransactionOptions()) if err != nil { log.Fatalf("Transaction failed: %v", err) } // Check if the transaction was successful if !res.IsSuccessful().UnsafeUnwrap() { log.Fatal("Transaction was not successful") } fmt.Println("Application Key Created Successfully") // Printing out all the values of the event ApplicationKeyCreated events := res.Events.UnsafeUnwrap() eventMyb := SDK.EventFindFirst(events, daPallet.EventApplicationKeyCreated{}) event := eventMyb.UnsafeUnwrap().UnsafeUnwrap() appId := event.Id fmt.Println(fmt.Sprintf(`Owner: %v, Key: %v, AppId: %v`, event.Owner.ToHuman(), string(event.Key), appId)) fmt.Println(fmt.Sprintf(`Block Hash: %v, Block Index: %v, Tx Hash: %v, Tx Index: %v`, res.BlockHash.ToHexWith0x(), res.BlockNumber, res.TxHash.ToHexWith0x(), res.TxIndex)) fmt.Println("Application Key Created") } ``` -------------------------------- ### Get Avail Head Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-bridge-api/avail-head/index.mdx Fetches the current block range (start and end) being tracked by the Avail bridge. ```APIDOC ## GET /avl/head ### Description Retrieves the current Avail block range tracked by the bridge. ### Method GET ### Endpoint /avl/head ### Response #### Success Response (200) - **data** (object) - Contains the start and end block numbers. - **start** (integer) - The starting block number of the tracked range. - **end** (integer) - The ending block number of the tracked range. ### Response Example ```json { "data":{ "end":512738, "start":488581 } } ``` ``` -------------------------------- ### Go SDK Example Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/nomination-pools-create-with-pool-id/index.mdx This Go code snippet illustrates how to initialize the Avail Go SDK, create an account from a seed, define pool parameters including addresses, and execute the `CreateWithPoolId` transaction. ```APIDOC ## CreateWithPoolId ### Description Initiates the creation of a new nomination pool with a specified pool ID, bond amount, and designated roles using the Avail Go SDK. ### Method `sdk.Tx.NominationPools.CreateWithPoolId(amount, root, nominator, bouncer, poolId)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **amount** (*metadata.Balance) - Required - The initial amount to bond for the pool. - **root** (*primitives.MultiAddress) - Required - The account address designated as the pool's root. - **nominator** (*primitives.MultiAddress) - Required - The account address designated as the pool's nominator. - **bouncer** (*primitives.MultiAddress) - Required - The account address designated as the pool's bouncer. - **poolId** (uint32) - Required - The unique identifier for the new nomination pool. ### Request Example ```go amount, err := metadata.NewBalanceFromString("1000000000000000000000000") poolId := uint32(1) rootAddress, _ := primitives.NewAccountIdFromAddress("5DqMavSQikX9eMzwHKiC8xS6VWB2yCd5gGQuQq7KheM2Mgc7") nominatorAddress, _ := primitives.NewAccountIdFromAddress("5FphMk7DhSdq7jXsQCVQthw7XTiCWxdA9ZS6V43rKeJzvya9") bouncerAddress, _ := primitives.NewAccountIdFromAddress("5G9fM7DhSdq7jXsQCVQthw7XTiCWxdA9ZS6V43rKeJzvya9") root := rootAddress.ToMultiAddress() nominator := nominatorAddress.ToMultiAddress() bouncer := bouncerAddress.ToMultiAddress() tx := sdk.Tx.NominationPools.CreateWithPoolId(amount, root, nominator, bouncer, poolId) ``` ### Response #### Success Response (200) Indicates successful execution of the `CreateWithPoolId` transaction, typically returning a confirmation of inclusion in a block. #### Response Example ```go // Upon successful execution, the function returns a result object. // The success can be checked via res.IsSuccessful().UnsafeUnwrap() fmt.Println("CreateWithPoolId transaction successful") ``` ``` -------------------------------- ### Run avail-js transferKeepAlive example Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/balances-transfer-keep-alive/index.mdx Execute the TypeScript script to perform the AVAIL transfer. Ensure you have `ts-node` installed. ```bash ts-node your-file-name.ts ``` -------------------------------- ### Set Up Validator with avail-go Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/staking-validate/index.mdx This Go snippet demonstrates how to initialize the SDK, create an account from a seed, and set validator preferences including commission. Ensure the SEED environment variable is set. ```go package main import ( "fmt" "log" "os" "github.com/availproject/avail-go-sdk/metadata" SDK "github.com/availproject/avail-go-sdk/sdk" "github.com/joho/godotenv" ) func main() { // Load environment variables from .env file err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file") } // Make sure the SEED environment variable is set seed := os.Getenv("SEED") if seed == "" { log.Fatal("SEED environment variable is not set") } // Create an account from the SEED environment variable acc, err := SDK.Account.NewKeyPair(seed) if err != nil { log.Fatalf("Failed to create account: %v", err) } fmt.Println("Your account Address: " + acc.SS58Address(42)) // Initialize an SDK instance sdk, err := SDK.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } // Set validator preferences prefs := metadata.ValidatorPrefs{ Commission: metadata.NewPerbillFromU8(5), // 5% commission ``` -------------------------------- ### Avail Node Startup Output Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-full-node/full-node/index.mdx Example output displayed in the terminal after successfully running the Avail node binary. ```bash 2024-04-29 07:48:22 Avail Node 2024-04-29 07:48:22 โœŒ๏ธ version 2.1.1-8608dc47f00 2024-04-29 07:48:22 โค๏ธ by Avail Project , 2017-2024 2024-04-29 07:48:22 ๐Ÿ“‹ Chain specification: Avail Turing Network 2024-04-29 07:48:22 ๐Ÿท Node name: possible-point-3102 2024-04-29 07:48:22 ๐Ÿ‘ค Role: FULL 2024-04-29 07:48:22 ๐Ÿ’พ Database: ParityDb at ./output/chains/avail_turing_network/paritydb/full ``` -------------------------------- ### Initialize SDK and Fetch Block Hash using avail-go Source: https://github.com/availproject/docs/blob/main/content/docs/da/build/interact/read-write-on-avail/index.mdx This snippet demonstrates the initial steps for interacting with the Avail network using the avail-go SDK. It covers initializing the SDK with a network endpoint and creating a BlockHash object from a hexadecimal string. ```go package main import ( "fmt" "log" "github.com/availproject/avail-go-sdk/primitives" SDK "github.com/availproject/avail-go-sdk/sdk" ) func main() { // Initialize an SDK instance ssdk, err := SDK.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } blockHash, err := primitives.NewBlockHashFromHexString("0x75a6c54bb5ea904e47fa151956992d7cf543bc7c936d78488e311db8e10397c1") if err != nil { log.Fatalf("Failed to create block hash: %v", err) } ``` -------------------------------- ### Fetch App Key Info using avail-go Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/da-app-keys/index.mdx This Go program initializes the Avail SDK and fetches the latest block hash to prepare for querying storage. It sets up the necessary components to interact with the Avail network's data availability storage. ```go package main import ( "fmt" "log" daPallet "github.com/availproject/avail-go-sdk/metadata/pallets/data_availability" prim "github.com/availproject/avail-go-sdk/primitives" SDK "github.com/availproject/avail-go-sdk/sdk" ) func main() { sdk, err := SDK.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } // Get the latest block hash latestBlockHash, err := sdk.Client.BestBlockHash() if err != nil { log.Fatalf("Failed to get latest block hash: %v", err) } // Initialize the block storage blockStorage, err := sdk.Client.StorageAt(prim.Some(latestBlockHash)) ``` -------------------------------- ### Fetch Submission Information Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-turbo-da-api/get-submission-info/index.mdx This example shows how to retrieve submission details using the `GET /v1/get_submission_info` endpoint. You need to provide your API key and the submission ID. ```APIDOC ## GET /v1/get_submission_info ### Description Retrieves metadata and status information about a previous data submission to Turbo DA. ### Method GET ### Endpoint `/v1/get_submission_info` ### Parameters #### Query Parameters - **submission_id** (string) - Required - The unique identifier received when data was submitted. #### Headers - **x-api-key** (string) - Required - Your API authentication key. ### Request Example ```bash curl -X GET 'https://staging.turbo-api.availproject.org/v1/get_submission_info?submission_id=YOUR_SUBMISSION_ID' \ -H 'x-api-key: YOUR_API_KEY' ``` ### Response #### Success Response (200) - **data** (object) - Metadata about the submission including status, transaction details, and timestamps. - **amount_data** (string) - The amount of data submitted. - **block_hash** (string) - The hash of the block where the transaction was included. - **block_number** (integer) - The block number where the transaction was included. - **created_at** (string) - The timestamp when the submission was created. - **data_billed** (string) - The amount of data billed for the submission. - **data_hash** (string) - The hash of the submitted data. - **fees** (string) - The transaction fees associated with the submission. - **tx_hash** (string) - The hash of the transaction. - **tx_index** (integer) - The index of the transaction within the block. - **user_id** (string) - The identifier of the user who made the submission. - **error** (null) - Indicates no error occurred. - **id** (string) - The unique identifier of the submission. - **state** (string) - The current state of the submission (e.g., "Finalized"). #### Response Example ```json { "data": { "amount_data": "20.00 B", "block_hash": "0x087c21csd7cdc3d08y007eb940b0883175a20a22965e61819d533efa8d601aec1", "block_number": 1465348, "created_at": "2023-06-15T10:30:45Z", "data_billed": "1024", "data_hash": "0xc30f0eadacfc1579a2a6cee3b3154bf5df8f41ac824d555e74363b6fc55df8f8", "fees": "124443109311818076", "tx_hash": "0xff57e96bee175118f8c3779241469170b692a3d91697182af92774e594963969", "tx_index": 1, "user_id": "user@example.com" }, "error": null, "id": "7b8f9e2a-c531-4d45-8c7a-1b2d3e4f5g6h", "state": "Finalized" } ``` ### Error Handling If the submission ID is invalid or not found, you'll receive an appropriate HTTP error code with an error message. ``` -------------------------------- ### Minimal Go Example for Nomination Pools Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/nomination-pools-create-with-pool-id/index.mdx This Go code snippet demonstrates the minimal setup for interacting with nomination pools, printing details of a block and transaction. ```go fmt.Printf("Block Hash: %v, Block Number: %v, Tx Hash: %v, Tx Index: %v\n", res.BlockHash.ToHexWith0x(), res.BlockNumber, res.TxHash.ToHexWith0x(), res.TxIndex) } ``` -------------------------------- ### Avail Light Client Sample Output Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-light-client/light-client/index.mdx This is an example of the expected output when the Avail light client is running successfully. ```shell 2024-03-20T10:50:25.528628Z INFO avail_light::light_client: Processing finalized block block_number=562690 block_delay=20 2024-03-20T10:50:25.528706Z INFO avail_light::light_client: Random cells generated: 10 block_number=562690 cells_requested=10 2024-03-20T10:50:26.069497Z INFO avail_light::network: Cells fetched from DHT block_number=562690 cells_total=10 cells_fetched=0 cells_verified=0 fetch_elapsed=540.755792ms proof_verification_elapsed=2.208ยตs 2024-03-20T10:50:28.322706Z INFO avail_light::network: Cells fetched from RPC block_number=562690 cells_total=10 cells_fetched=10 cells_verified=10 fetch_elapsed=2.232714917s proof_verification_elapsed=20.404208ms 2024-03-20T10:50:28.322987Z INFO avail_light::light_client: Confidence factor: 99.90234375 block_number=562690 confidence=99.90234375 2024-03-20T10:50:28.323134Z INFO avail_light::light_client: Sleeping for 14.61143875s seconds 2024-03-20T10:50:28.323154Z INFO avail_light::api::v2: Message published to clients topic=ConfidenceAchieved published=0 failed=0 2024-03-20T10:50:28.859369Z INFO avail_light::network::p2p::event_loop: Cell upload success rate for block 562690: 0/10. Duration: 0 2024-03-20T10:50:41.535425Z INFO avail_light::network::rpc::subscriptions: New justification at block no.: 562692, hash: 0x3b602253298ce9bec9b5b8f0c8767f14502ccaa17a003dfba77f9d90edeaf5da 2024-03-20T10:50:41.709011Z INFO avail_light::network::rpc::subscriptions: Header no.: 562692 2024-03-20T10:50:41.709557Z INFO avail_light::network::rpc::subscriptions: Number of matching signatures: 5/7 for block 562692, set_id 223 2024-03-20T10:50:41.709574Z INFO avail_light::network::rpc::subscriptions: Storing finality checkpoint at block 562692 2024-03-20T10:50:41.709908Z INFO avail_light::network::rpc::subscriptions: Sending finalized block 562692 2024-03-20T10:50:41.709966Z INFO avail_light::api::v2: Message published to clients topic=HeaderVerified published=0 failed=0 2024-03-20T10:50:42.936699Z INFO avail_light::light_client: Processing finalized block block_number=562691 block_delay=20 2024-03-20T10:50:42.936761Z INFO avail_light::light_client: Random cells generated: 10 block_number=562691 cells_requested=10 2024-03-20T10:50:43.472932Z INFO avail_light::network: Cells fetched from DHT block_number=562691 cells_total=10 cells_fetched=0 cells_verified=0 fetch_elapsed=536.136083ms proof_verification_elapsed=3.042ยตs 2024-03-20T10:50:46.513570Z INFO avail_light::network: Cells fetched from RPC block_number=562691 cells_total=10 cells_fetched=10 cells_verified=10 fetch_elapsed=3.022786041s proof_verification_elapsed=17.810542ms 2024-03-20T10:50:46.513706Z INFO avail_light::light_client: Confidence factor: 99.90234375 block_number=562691 confidence=99.90234375 2024-03-20T10:50:46.513785Z INFO avail_light::light_client: Sleeping for 15.195224667s seconds 2024-03-20T10:50:46.513795Z INFO avail_light::api::v2: Message published to clients topic=ConfidenceAchieved published=0 failed=0 2024-03-20T10:50:47.056255Z INFO avail_light::network::p2p::event_loop: Cell upload success rate for block 562691: 0/10. Duration: 0 ``` -------------------------------- ### Transfer AVAIL with avail-rust Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/balances-transfer-allow-death/index.mdx Use this snippet to transfer AVAIL tokens using the avail-rust SDK. This example requires Rust and Cargo to be installed, and your .env file must contain your SEED. ```rust use dotenvy::dotenv; use std::env; use avail_rust::prelude::*; use core::str::FromStr; pub async fn transfer_allow_death() -> Result<(), ClientError> { // Create a new SDK instance let sdk = SDK::new("wss://turing-rpc.avail.so/ws").await?; // Loading seed phrase and creating an account derived from the seed dotenv().ok(); let seed = env::var("SEED").expect("SEED environment variable is not set"); let account = account::from_secret_uri(&seed)?; println!("Account Address: {}", account.public_key().to_account_id()); // Executing the transaction let dest = AccountId::from_str("5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw").unwrap(); let amount = 12_345_000_000_000_000_000u128; // 12.345 AVAIL being transferred to the destination account let tx = sdk.tx.balances.transfer_allow_death(dest, amount); let res = tx.execute_and_watch_inclusion(&account, Options::default()).await?; println!( "Block Hash: {:?}, Block Number: {}, Tx Hash: {:?}, Tx Index: {}", res.block_hash, res.block_number, res.tx_hash, res.tx_index ); println!("Transfer completed successfully"); Ok(()) } // Add a main function to call transfer_allow_death #[tokio::main] async fn main() { if let Err(e) = transfer_allow_death().await { eprintln!("Error: {:?}", e); } } ``` -------------------------------- ### Avail Bridge Project Setup and Configuration Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-bridge-api/vector-send-tokens/index.mdx This snippet shows the necessary imports and setup for the Avail Bridge project, including configuration loading, keypair generation, and establishing connections to Ethereum and Avail networks. ```rust use alloy::primitives::{Address, U256}; use alloy_network::EthereumWallet; use alloy_provider::ProviderBuilder; use alloy_sol_types::sol; use anyhow::{anyhow, Result}; use avail_bridge_tools::{address_to_h256, convert_addressed_message, eth_seed_to_address, Config}; use avail_rust::avail::runtime_types::bounded_collections::bounded_vec::BoundedVec; use avail_rust::avail_core::data_proof::AddressedMessage; use avail_rust::{avail, AvailExtrinsicParamsBuilder, WaitFor, SDK}; use avail_rust::{subxt_signer::SecretUri, Keypair}; use reqwest::Url; use serde::{Deserialize, Deserializer}; use sp_core::H256; use std::{fs, str::FromStr, time::Duration}; sol!( #[sol(rpc)] AvailBridgeContract, "src/availbridge.json" ); #[tokio::main] async fn main() -> Result<()> { let content = fs::read_to_string("./config.toml").expect("Read config.toml"); let config = toml::from_str::(&content).unwrap(); let secret_uri = SecretUri::from_str(config.avail_mnemonic.as_str()).expect("Valid secret URI"); let account = Keypair::from_uri(&secret_uri).expect("Valid secret URI"); let recipient = account.public_key().0; let amount: u128 = 100000; let ethereum_signer = config .ethereum_mnemonic .parse::()?; let sender = eth_seed_to_address(config.ethereum_mnemonic.as_str()); let provider = ProviderBuilder::new() .with_recommended_fillers() .wallet(EthereumWallet::from(ethereum_signer)) .on_http(Url::parse(config.ethereum_url.as_str())?); let contract_addr: Address = config.contract_address.parse()?; let contract = AvailBridgeContract::new(contract_addr, &provider); ``` -------------------------------- ### Install and Run Avail Light Client with availup Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-light-client/light-client/index.mdx Execute this command to download and run the Avail light client on the Turing testnet using availup. ```shell curl -sL1 avail.sh | bash ``` -------------------------------- ### Fast Transfer Component Usage Example Source: https://github.com/availproject/docs/blob/main/content/docs/nexus/nexus-ui-elements/components/transfer.mdx Integrate the FastTransfer component into your application. Prefill token and chainId for a streamlined user experience. Implement callbacks for completion, errors, and start events. ```tsx ``` -------------------------------- ### Get Block Header using avail-go Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/chain-get-block/index.mdx This code example demonstrates how to retrieve block headers using the avail-go SDK, including fetching the latest header and a header for a specific block hash. ```APIDOC ## Get Block Header (avail-go) ### Description Retrieves the latest block header or a specific block header by its hash using the avail-go SDK. ### Method `sdk.Client.Rpc.Chain.GetHeader(blockHash prim.Option[prim.H256])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "fmt" "log" prim "github.com/availproject/avail-go-sdk/primitives" SDK "github.com/availproject/avail-go-sdk/sdk" ) func main() { sdk, err := SDK.NewSDK("https://turing-rpc.avail.so/rpc") if err != nil { log.Fatalf("Failed to initialize SDK: %v", err) } // Get the latest block hash by not passing any parameters latestBlockHeader, err := sdk.Client.Rpc.Chain.GetHeader(prim.None[prim.H256]()) if err != nil { log.Fatalf("Failed to get the latest block header: %v", err) } fmt.Println("Latest Block Header: ", latestBlockHeader) // Get a specific block header by passing the block hash blockHash, err := prim.NewH256FromHexString("0x75a6c54bb5ea904e47fa151956992d7cf543bc7c936d78488e311db8e10397c1") if err != nil { log.Fatalf("Failed to create H256 from hex: %v", err) } specificBlockHeader, err := sdk.Client.Rpc.Chain.GetHeader(prim.Some[prim.H256](blockHash)) if err != nil { log.Fatalf("Failed to get the specific block header: %v", err) } fmt.Println("Specific Block Header: ", specificBlockHeader) } ``` ### Response #### Success Response (200) Returns the block header object. #### Response Example ```json { "hash": "0x...", "parentHash": "0x...", "number": 12345, "stateRoot": "0x...", "extrinsicsRoot": "0x..." } ``` ``` -------------------------------- ### avail-go Transfer All Example Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-node-api/balances-transfer-all/index.mdx This snippet demonstrates how to transfer all AVAIL balances using the avail-go SDK. It includes loading environment variables, initializing the SDK, and preparing for transaction execution. ```APIDOC ## avail-go Transfer All ### Description This example shows the initial setup for transferring all AVAIL balances using the `avail-go-sdk`. It covers loading environment variables, including the seed phrase, and initializing the SDK. The full transaction execution logic would follow this setup. ### Method (Not explicitly defined in the provided snippet, but would involve a method similar to `sdk.tx.balances.transferAll`) ### Parameters (Not explicitly defined in the provided snippet, but would typically include destination address and a `keepAlive` flag) ### Request Example ```go package main import ( "fmt" "log" "os" "github.com/availproject/avail-go-sdk/primitives" SDK "github.com/availproject/avail-go-sdk/sdk" "github.com/joho/godotenv" ) func main() { err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file") } seed := os.Getenv("SEED") if seed == "" log.Fatal("SEED environment variable is not set") // Further SDK initialization and transaction logic would follow here. // Example placeholder for SDK initialization: // sdk, err := SDK.New("wss://turing-rpc.avail.so/ws") // if err != nil { // log.Fatalf("Failed to initialize SDK: %v", err) // } fmt.Println("Environment loaded and seed is available.") } ``` ### Response (Response details are not available in the provided snippet.) ``` -------------------------------- ### Run Pre-built Binary (Linux ARM64) Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-light-client/light-client/index.mdx Execute the pre-built Avail light client binary for Linux systems with ARM64 architecture. This requires downloading the appropriate binary release. ```sh ./avail-light-linux-arm64 --app-id 18 --network mainnet --identity identity.toml ``` -------------------------------- ### Check cURL Installation Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-lc-api/index.mdx Verify if cURL is installed on your system. If not, follow the provided link to install it. ```bash curl --version ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/availproject/docs/blob/main/content/docs/nexus/nexus-sdk/quickstart/index.mdx Copy the example environment file and add your WalletConnect Project ID to enable wallet connections. ```bash cd my-nexus-app cp .env.local.example .env.local ``` ```bash NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id_here ``` -------------------------------- ### Install WSL on Windows Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-light-client/light-client/index.mdx Installs the Windows Subsystem for Linux without a default distribution. Requires a system restart after installation. ```powershell wsl --install --no-distribution ``` -------------------------------- ### Check Rust and Cargo Installation Source: https://github.com/availproject/docs/blob/main/content/docs/da/api-reference/avail-lc-api/index.mdx Confirm that Rust and Cargo are installed. Instructions for installation are available via the provided link. ```bash rustc --version && cargo --version ``` -------------------------------- ### Avail Nexus SDK Quickstart Source: https://github.com/availproject/docs/blob/main/content/docs/nexus/get-started/index.mdx Initialize the Nexus SDK, check balances for bridging and swapping, and perform bridge or swap operations. ```typescript // 1. Initialize const sdk = new NexusSDK({ network: 'mainnet' }); // 2. See balances across all chains const bridgeBalances = await sdk.getBalancesForBridge(); // โ†’ Returns tokens available for bridging across chains const swapBalances = await sdk.getBalancesForSwap(); // โ†’ Returns tokens available for cross-chain swaps // 3. Bridge to any chain โ€” Nexus finds the best route await sdk.bridge({ token: 'USDC', amount: 100, toChain: 'arbitrum' }); // 4. Or swap any token โ†’ any token, cross-chain await sdk.swap({ from: 'USDC', to: 'ETH', amount: 50, toChain: 'base' }); ``` -------------------------------- ### Sample Avail Light Client Output Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/run-a-light-client/light-client/index.mdx This is an example of the expected output when the Avail light client is running successfully. ```shell 2024-03-20T10:22:23.821042Z INFO avail_light::api::v2: Message published to clients topic=HeaderVerified published=0 failed=0 2024-03-20T10:22:23.854448Z INFO avail_light::network: Cells fetched from RPC block_number=562606 cells_total=10 cells_fetched=10 cells_verified=10 fetch_elapsed=466.901875ms proof_verification_elapsed=10.431583ms ``` -------------------------------- ### Install Grafana Source: https://github.com/availproject/docs/blob/main/content/docs/da/operate/become-a-validator/monitor-your-validator/index.mdx Installs Grafana on your system by adding the Grafana repository and then installing the Grafana package. Grafana will be used to visualize the metrics collected by Prometheus. ```bash wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/deb stable main" > grafana.list sudo mv grafana.list /etc/apt/sources.list.d/grafana.list sudo apt-get update && sudo apt-get install -y grafana ```