### Serialize Example Transaction (Casper Network) Source: https://docs.casper.network/concepts/serialization/transaction-serialization-example This code snippet demonstrates the binary representation of an example TransactionV1 in the Casper Network. It starts with the version byte '0x01' followed by the binary data of the transaction. ```plaintext 0x030000000000000000000100200000000200150100007b010000de78f579a9 afb234cb6ee3ab989a44f44a1544caa991a470dfa0eccde29373370600000000 000000000001003600000002003e00000003004600000004004d00000005006a 000000c9000000020000000000000000000100010000002200000000011a3818 79f8a8dc97361d012e3b472207cc7313ed1a81c918eebfa872b93414d98366de 079801000000dd6d000000000003000000616263030000000000000000000100 0001000000020002000000030000000103020400000000001600000000010000 000100000061070000000300000078797a0a01000f0000000100000000000000 0000010000000002000f00000001000000000000000000010000000303000f00 000001000000000000000000010000000001000000011a381879f8a8dc97361d01 2e3b472207cc7313ed1a81c918eebfa872b93414d901bcc0ee36a4bb5d8d7b89 34bbd2e09270456eb201db15f6288490879c9a8e44d5a40514600952e6a541e9 bf8f0bcc7f9dcec55533c0faec0b8674c979c8c86000 ``` -------------------------------- ### Casper CLI: Sample Get Account Info Command and Output Source: https://docs.casper.network/concepts/accounts-and-keys A practical example of using the `get-account-info` subcommand with a specific node address and public key, followed by the JSON output detailing the account's information, including its hash, main purse, and associated keys. ```bash casper-client get-account-info --node-address http://65.21.75.254:7777 --public-key 0202ceafc0aa35f5a7bdda22f65c046b9b30b858459e18d3670f035839ad887fe5db ``` ```json { "jsonrpc": "2.0", "id": -4442861421270275102, "result": { "api_version": "2.0.0", "account": { "account_hash": "account-hash-0ea7998b2822afe5b62b08a21d54c941ad791279b089f3f7ede0d72b477eca34", "named_keys": [], "main_purse": "uref-974019c976b5f26412ce486158d2431967af35d91387dae8cbcd43c20fce6452-007", "associated_keys": [ { "account_hash": "account-hash-0ea7998b2822afe5b62b08a21d54c941ad791279b089f3f7ede0d72b477eca34", "weight": 1 } ], "action_thresholds": { "deployment": 1, "key_management": 1 } }, "merkle_proof": "[32920 hex chars]" } } ``` -------------------------------- ### Casper CLI: Get Help for Account Info Source: https://docs.casper.network/concepts/accounts-and-keys This command displays the help message for the `get-account-info` subcommand in the Casper CLI client, providing more details on its usage and options. ```bash casper-client get-account-info --help ``` -------------------------------- ### Writing Entries to a Dictionary Source: https://docs.casper.network/concepts/dictionaries This section details how to add or update entries within a dictionary. It covers the use of `storage::dictionary_put` and provides an example of updating a ledger record. ```APIDOC ## POST /dictionary/write ### Description Adds or updates an entry in a Casper Network dictionary. If the key already exists, the value is overwritten. This operation incurs the cost of writing the entire structure, regardless of the size of the change. ### Method POST ### Endpoint `/dictionary/write` (Conceptual - specific implementation depends on context) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **dictionary_uref** (URef) - Required - The seed URef of the dictionary. - **dictionary_item_key** (String) - Required - The unique identifier for the dictionary item. - **value** (Any) - Required - The data to be stored or updated for the dictionary item. ### Request Example ```json { "dictionary_uref": "uref-example-seed", "dictionary_item_key": "donation_count_alice", "value": 10 } ``` ### Response #### Success Response (200) Indicates the operation was successful. The exact response format may vary. #### Response Example ```json { "success": true } ``` ## Update Ledger Record (Rust Example) ### Description An example function demonstrating how to update a ledger record within a dictionary. It first acquires the `ledger` seed URef, then attempts to get the existing entry. If the entry exists, it increments the count; otherwise, it creates the entry with a value of 1. ### Method Internal Rust Function ### Endpoint N/A (Internal Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **dictionary_item_key** (String) - Required - The key of the ledger item to update. ### Request Example (See Rust code in original documentation) ### Response #### Success Response (200) Indicates the operation was successful. The exact response format may vary. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Read Dictionary Item via Seed URef (Casper Client) Source: https://docs.casper.network/concepts/dictionaries This command-line example illustrates reading a Casper dictionary item directly using its seed URef with the Casper client. It requires the node address, state root hash, the dictionary item key, and the seed URef of the dictionary. This method is more direct than using Contract Named Keys as it bypasses the need for contract hash and dictionary name. ```bash casper-client get-dictionary-item \ --node-address http://localhost:11101 \ --state-root-hash 50c34ccbe1315d58ce22bf7518071164d16acd20a1becb0b423293418297416d \ --dictionary-item-key \ --seed-uref uref-90b4a8d936b881d3b45b73a102adb2b652181d75c76b7547ae9d1bb213f8db6b-007 ``` -------------------------------- ### Casper CLI: Get Account Info Command Source: https://docs.casper.network/concepts/accounts-and-keys This command retrieves account information from the Casper network using the `casper-client`. It requires the node address and the public key of the account. The public key can be provided directly or as a path to a file. ```bash casper-client get-account-info \ --node-address \ --public-key ``` -------------------------------- ### Read Dictionary Item via Contract Named Key (Casper Client) Source: https://docs.casper.network/concepts/dictionaries This command-line example shows how to read a specific item from a Casper dictionary using the Casper client. It requires the node address, state root hash, contract hash, dictionary name, and the specific dictionary item key. This method is used when the dictionary is referenced by a contract's named keys. ```bash casper-client get-dictionary-item \ --node-address http://localhost:11101 \ --state-root-hash 50c34ccbe1315d58ce22bf7518071164d16acd20a1becb0b423293418297416d \ --contract-hash hash-09c8fa7c1441ae7c1cbe27ae3a722fd4ffc5290315f8546454454c1b9f85c842 \ --dictionary-name \ --dictionary-item-key ``` -------------------------------- ### Initialize Contract with Dictionary in Rust Source: https://docs.casper.network/concepts/dictionaries This Rust code snippet shows how to create a dictionary named 'ledger' during a contract's initialization. It also creates a 'fundraising_purse' and stores it. Dictionaries intended for contract use should typically be set up within the initializing entry point. Error handling is managed using `unwrap_or_revert`. ```rust #[no_mangle] pub extern "C" fn init() { let fundraising_purse = system::create_purse(); runtime::put_key("fundraising_purse", fundraising_purse.into()); // Create a dictionary to track the mapping of account hashes to number of donations made. storage::new_dictionary("ledger").unwrap_or_revert(); } ``` -------------------------------- ### Display Secp256k1 Public Key Hex Source: https://docs.casper.network/concepts/accounts-and-keys This command displays the hexadecimal representation of the Secp256k1 public key. The output starts with '02' and is 68 characters long. ```bash cat secp256k1-keys/public_key_hex ``` -------------------------------- ### Chainspec Settings for Reward Calculation Source: https://docs.casper.network/concepts/design/rewards Demonstrates sample values for chainspec settings used in calculating rewards on the Casper Network. These include parameters for distributing rewards between block producers and signers, defining lookback intervals for rewards, and setting the annual inflation rate through the round seigniorage rate. ```toml # The split in finality signature rewards between block producer and participating signers. finders_fee = [1, 5] # The proportion of baseline rewards going to reward finality signatures specifically. finality_signature_proportion = [1, 2] # Lookback interval indicating which past block we are looking at to reward. signature_rewards_max_delay = 3 ... # Round seigniorage rate represented as a fraction of the total supply. # # Annual issuance: 8% # Minimum block time: 2^14 milliseconds # Ticks per year: 31536000000 # # (1+0.08)^((2^14)/31536000000)-1 is expressed as a fractional number below # Python: # from fractions import Fraction # Fraction((1 + 0.08)**((2**14)/31536000000) - 1).limit_denominator(1000000000) round_seigniorage_rate = [7, 175070816] ``` -------------------------------- ### Display Ed25519 Public Key Hex Source: https://docs.casper.network/concepts/accounts-and-keys This command displays the hexadecimal representation of the Ed25519 public key generated by the Casper client. The output starts with '01' and is 66 characters long. ```bash cat ed25519-keys/public_key_hex ``` -------------------------------- ### Uniform Data Structure Serialization with calltable Scheme Source: https://docs.casper.network/concepts/serialization/calltable-serialization Demonstrates serializing non-polymorphic data structures using the calltable scheme. Fields are assigned unique serialization indices starting from 0. This scheme assumes the structure of the data is known beforehand. ```rust struct A { a: u16, b: String, c: Vec } ``` -------------------------------- ### Create a New Dictionary in Rust Source: https://docs.casper.network/concepts/dictionaries This snippet demonstrates the fundamental function for creating a new dictionary within the Casper smart contract environment. It utilizes the `new_dictionary` function from the `casper_contract::contract_api::storage` module. Ensure the `casper_contract` crate is included in your project dependencies. ```rust casper_contract::contract_api::storage::new_dictionary(dict_name) ``` -------------------------------- ### GET /account/info Source: https://docs.casper.network/concepts/accounts-and-keys Retrieves information about a specific account on the Casper network using the CLI client. This includes details like the account hash, named keys, main purse, associated keys, and action thresholds. ```APIDOC ## GET /account/info (CLI) ### Description Retrieves detailed information for a given Casper account using the `casper-client`. This command allows users to inspect account properties such as their main purse, associated keys, and security thresholds. ### Method CLI Command ### Endpoint `casper-client get-account-info` ### Parameters #### Command-Line Arguments - **`--node-address`** (string) - Required - The network address of a node (e.g., `http://:`). Defaults to port 7777 for JSON-RPC. - **`--public-key`** (string or path) - Required - The formatted public key of the account or the path to a file containing the public key (`public_key_hex` or `public_key.pem`). ### Request Example ```bash casper-client get-account-info --node-address http://65.21.75.254:7777 --public-key 0202ceafc0aa35f5a7bdda22f65c046b9b30b858459e18d3670f035839ad887fe5db ``` ### Response #### Success Response (200) - **`jsonrpc`** (string) - The JSON-RPC protocol version. - **`id`** (integer) - The ID of the request. - **`result`** (object) - Contains the account information. - **`api_version`** (string) - The API version used. - **`account`** (object) - Details of the account. - **`account_hash`** (string) - The unique hash of the account. - **`named_keys`** (array) - A list of named keys associated with the account. - **`main_purse`** (string) - The URef of the account's main purse. - **`associated_keys`** (array) - List of keys associated with the account and their weights. - **`action_thresholds`** (object) - Thresholds for different actions (deployment, key management). - **`merkle_proof`** (string) - The Merkle proof associated with the account data. #### Response Example ```json { "jsonrpc": "2.0", "id": -4442861421270275102, "result": { "api_version": "2.0.0", "account": { "account_hash": "account-hash-0ea7998b2822afe5b62b08a21d54c941ad791279b089f3f7ede0d72b477eca34", "named_keys": [], "main_purse": "uref-974019c976b5f26412ce486158d2431967af35d91387dae8cbcd43c20fce6452-007", "associated_keys": [ { "account_hash": "account-hash-0ea7998b2822afe5b62b08a21d54c941ad791279b089f3f7ede0d72b477eca34", "weight": 1 } ], "action_thresholds": { "deployment": 1, "key_management": 1 } }, "merkle_proof": "[32920 hex chars]" } } ``` ### Help Command For more details, run: ```bash casper-client get-account-info --help ``` ``` -------------------------------- ### Mint Contract Interface Source: https://docs.casper.network/concepts/design/casper-design The mint system contract exposes several methods for managing tokens and purses. ```APIDOC ## Mint Contract Methods ### `transfer(source: URef, target: URef, amount: Motes) -> TransferResult` #### Description Transfers a specified amount of motes from a source purse to a target purse. #### Method N/A (Contract Method) #### Parameters * **source** (URef) - Required - The purse to transfer motes from. Must have at least `Write` access rights. * **target** (URef) - Required - The purse to transfer motes to. Must have at least `Add` access rights. * **amount** (Motes) - Required - The amount of motes to transfer. #### Response * **TransferResult** - The result of the transfer, which can be a success acknowledgment or an error if the source or target is invalid, or if the source purse has insufficient balance. ### `mint(amount: Motes) -> MintResult` #### Description Mints a specified amount of new motes. Only the system account can call this method. #### Method N/A (Contract Method) #### Parameters * **amount** (Motes) - Required - The amount of motes to mint. #### Response * **MintResult** - Either provides the created `URef` with full access rights and the specified balance, or an error if minting is not allowed. ### `create() -> URef` #### Description A convenience function that creates an empty purse. It is equivalent to calling `mint(0)` and cannot fail. #### Method N/A (Contract Method) #### Response * **URef** - A newly created `URef` representing an empty purse. ### `balance(purse: URef) -> Option` #### Description Retrieves the balance of a given purse. #### Method N/A (Contract Method) #### Parameters * **purse** (URef) - Required - The purse to check the balance of. Must have at least `Read` access rights. #### Response * **Option** - Returns the number of motes held by the purse, or `None` if the `URef` is invalid. ``` -------------------------------- ### Tagged-Union Serialization with calltable Scheme Source: https://docs.casper.network/concepts/serialization/calltable-serialization Explains how to serialize polymorphic, yet limited, tagged-union data structures. Serialization index 0 is reserved for a 1-byte variant discriminator. Subsequent indices serialize variant fields. Examples are shown for Rust enums and Python notation. ```rust enum X { A, B {a: u16, b: u32}, C (u16, u32, u64) } ``` ```python # Serializing variant X::A I = [0] B = [(0).to_bytes(1, byteorder = 'little')] # Serializing variant X::B {a: 155, b: 9500} I = [0, 1, 2] B = [(1).to_bytes(1, byteorder = 'little'), (155).to_bytes(2, byteorder = 'little'), (9500).to_bytes(4, byteorder = 'little')] # Serializing variant X::C(5, 10, 15) I = [0, 1, 2, 3] B = [(2).to_bytes(1, byteorder = 'little'), (5).to_bytes(2, byteorder = 'little'), (10).to_bytes(4, byteorder = 'little'), (15).to_bytes(8, byteorder = 'little')] ```