### Install Simplicity CLI with Cargo Source: https://docs.simplicity-lang.org/getting-started/cli Installs the Simplicity development toolkit using Cargo, the Rust package manager. This command fetches the latest version directly from the GitHub repository. ```bash cargo install --git https://github.com/starkware-bitcoin/simply simply ``` -------------------------------- ### Simplicity Common Commands Reference Source: https://docs.simplicity-lang.org/getting-started/cli A reference guide for commonly used `simply` commands, including building, running, testing, depositing, and withdrawing contracts. ```bash simply build --entrypoint simply run --entrypoint --logging simply test simply deposit --entrypoint simply withdraw --entrypoint --txid --destination
``` -------------------------------- ### Start Elements Testnet Node Source: https://docs.simplicity-lang.org/getting-started/cli Initiates an Elements blockchain node configured for the liquidtestnet. The `-daemon` flag runs the node in the background. ```bash elementsd -chain=liquidtestnet -daemon ``` -------------------------------- ### Verify Simplicity and Elements CLI Installation Source: https://docs.simplicity-lang.org/getting-started/cli Checks if the `simply` and `elements-cli` tools are installed correctly by displaying their respective version numbers. This is a crucial step after installation to ensure the tools are ready for use. ```bash simply --version elements-cli --version ``` -------------------------------- ### Troubleshoot: Install Simplicity CLI Source: https://docs.simplicity-lang.org/getting-started/cli Provides commands to check if the 'simply' CLI tool is installed and how to reinstall it from source if necessary. This is useful for resolving 'command not found' errors. ```bash # Check if installed which simply # Reinstall if needed cargo install --git https://github.com/starkware-bitcoin/simply simply --force ``` -------------------------------- ### Create Contract File (Simplicity) Source: https://docs.simplicity-lang.org/getting-started/cli Creates a Simplicity contract file named 'my_contract.simf' with a basic 'main' function that always succeeds. This is the starting point for contract development. ```bash cat > my_contract.simf << 'EOF' fn main() { // Always succeeds } EOF ``` -------------------------------- ### Simplicity Combinators Example Source: https://docs.simplicity-lang.org/documentation/simplicity-for-evm-developers Illustrates the basic combinators used to construct Simplicity expressions. These include composition, pairing, witness data input, identity, unit, injection, taking, dropping, and case analysis. ```Simplicity comp pair witness iden unit injl injr take drop case ``` -------------------------------- ### Create a Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Defines a basic Simplicity smart contract named `hellosimply`. This contract is designed to always succeed and serves as a starting point for development. ```simplicity fn main() { // Contract that always succeeds } ``` -------------------------------- ### Liquid Testnet Genesis Hash Source: https://docs.simplicity-lang.org/getting-started/cli Displays the genesis hash for the Liquid Testnet, which uniquely identifies the start of the blockchain. ```plaintext a771da8e52ee6ad581ed1e9a99825e5b3b7992225534eaa2ae23244fe26ab1c1 ``` -------------------------------- ### Witness File Format Example Source: https://docs.simplicity-lang.org/getting-started/simplicityhl Demonstrates the expected JSON format for witness data used with SimplicityHL contracts. This includes the value of the data and its type, such as 'Signature'. ```json { "signature": { "value": "0x...", "type": "Signature" } } ``` -------------------------------- ### Accessing Witness Data in SimplicityHL Source: https://docs.simplicity-lang.org/getting-started/simplicityhl Example of how to access witness data within a SimplicityHL contract. Witness data is provided when spending and can be accessed for validation purposes. The example shows retrieving a signature from witness data. ```rust fn main() { let sig: Signature = witness::signature; // Use sig in validation } ``` -------------------------------- ### Liquid Testnet API Common Commands Reference Source: https://docs.simplicity-lang.org/getting-started/cli Common `curl` commands for interacting with the Liquid Testnet API, including funding addresses, checking UTXOs, getting transactions, broadcasting, and checking status. ```bash # Fund address curl "https://liquidtestnet.com/faucet?address=
&action=lbtc" # Check UTXOs curl "https://blockstream.info/liquidtestnet/api/address/
/utxo" # Get transaction curl "https://blockstream.info/liquidtestnet/api/tx/" # Broadcast transaction curl -X POST "https://blockstream.info/liquidtestnet/api/tx" -d "" # Check status curl "https://blockstream.info/liquidtestnet/api/tx//status" ``` -------------------------------- ### Get Balance with Elements CLI Source: https://docs.simplicity-lang.org/getting-started/cli Retrieves the current balance of the specified wallet ('mywallet') on the Liquid Testnet using `elements-cli`. This command shows the total amount of cryptocurrency available. ```bash elements-cli -chain=liquidtestnet -rpcwallet=mywallet getbalance ``` -------------------------------- ### Get Deposit Address for Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Obtains a deposit address for a Simplicity contract using the `simply deposit` command. This address can be used to fund the contract. ```bash simply deposit --entrypoint my_contract.simf ``` -------------------------------- ### Type Conversion: Left Pad Low (uA -> uB) Source: https://docs.simplicity-lang.org/documentation/jets-overview Zero-pads a smaller unsigned integer type to a larger unsigned integer type. Example converts u16 to u32. ```Simplicity jet::left_pad_low_16_32(x) ``` -------------------------------- ### Get Transaction Details via Blockstream API Source: https://docs.simplicity-lang.org/getting-started/cli Retrieves detailed information about a specific transaction on the Liquid Testnet using its transaction ID (txid) via the Blockstream API. ```bash curl "https://blockstream.info/liquidtestnet/api/tx/abc123..." ``` -------------------------------- ### SimplicityHL Struct Example (Not Supported) Source: https://docs.simplicity-lang.org/simplicityhl-reference/type_alias This code snippet demonstrates a Rust-like struct definition for organizing user data. SimplicityHL does not currently support this syntax, requiring developers to use tuples instead. ```rust struct User { active: bool, id: u256, sign_in_count: u64, } ``` -------------------------------- ### Liquid Testnet Faucet Source: https://docs.simplicity-lang.org/getting-started/cli Obtain test L-BTC for development and testing purposes. ```APIDOC ## Liquid Testnet Faucet ### Fund Address Requests test L-BTC from the faucet to a specified address. #### Method `GET` #### URL `https://liquidtestnet.com/faucet?address=
&action=lbtc` #### Parameters - **address** (string) - Required - The Liquid address to receive funds. - **action** (string) - Required - Set to `lbtc` to request L-BTC. ``` -------------------------------- ### Create Wallet with Elements CLI Source: https://docs.simplicity-lang.org/getting-started/cli Creates a new wallet using the `elements-cli` tool for managing cryptocurrency on the Liquid Testnet. The wallet is named 'mywallet'. ```bash elements-cli -chain=liquidtestnet createwallet mywallet ``` -------------------------------- ### Troubleshooting Source: https://docs.simplicity-lang.org/getting-started/cli Common issues and solutions for Simplicity development and Liquid network interaction. ```APIDOC ## Troubleshooting Common Issues ### `simply` Command Not Found 1. **Check Installation:** ```bash which simply ``` 2. **Reinstall if Necessary:** ```bash cargo install --git https://github.com/starkware-bitcoin/simply simply --force ``` ### Connection Errors to Blockstream API 1. **Test API Connectivity:** ```bash curl "https://blockstream.info/liquidtestnet/api" ``` *Expected Output:* API documentation or a similar response indicating the API is reachable. ### Transaction Building Fails 1. **Verify UTXO Existence:** Ensure the transaction output you are trying to spend (UTXO) is valid and exists on the network. ```bash curl "https://blockstream.info/liquidtestnet/api/tx//hex" ``` 2. **Check if UTXO is Already Spent:** Confirm that the specific output of the transaction has not already been spent. ```bash curl "https://blockstream.info/liquidtestnet/api/tx//outspend/" ``` ``` -------------------------------- ### Compile a Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Compiles a Simplicity contract file (`.simf`) into a binary format using the `simply build` command. It specifies the entry point of the contract and outputs compilation details like CMR and cost. ```bash simply build --entrypoint hellosimply.simf ``` -------------------------------- ### Simplicity Contract Execution Source: https://docs.simplicity-lang.org/getting-started/cli Commands for compiling, running, testing, and deploying Simplicity contracts. ```APIDOC ## Simply Commands ### Build Contract Compiles a Simplicity contract. #### Method `simply build` #### Parameters - **--entrypoint** (string) - Required - The main contract file. - **--stats** (boolean) - Optional - Show build statistics. ### Run Contract Locally Executes a Simplicity contract in a local environment with debug logging. #### Method `simply run` #### Parameters - **--entrypoint** (string) - Required - The main contract file. - **--logging** (string) - Optional - Logging level (e.g., `debug`). ### Test Contract Suite Discovers and executes all `test_*` functions within Simplicity files. #### Method `simply test` ### Get Deposit Address Retrieves the deposit address for a Simplicity contract. #### Method `simply deposit` #### Parameters - **--entrypoint** (string) - Required - The main contract file. ### Withdraw Funds Spends funds from a Simplicity contract. #### Method `simply withdraw` #### Parameters - **--entrypoint** (string) - Required - The main contract file. - **--txid** (string) - Required - The transaction ID of the funds to spend. - **--destination** (string) - Required - The recipient address. ``` -------------------------------- ### SimplicityHL Type Inference Example Source: https://docs.simplicity-lang.org/simplicityhl-reference/type_casting Illustrates SimplicityHL's type inference mechanism. The meaning of a literal value like '1' is determined by the explicitly declared type of the variable it is assigned to (e.g., u32). ```SimplicityHL let x: u32 = 1; ``` -------------------------------- ### Spend Funds with Simplicity Source: https://docs.simplicity-lang.org/getting-started/cli Demonstrates how to spend funds using the `simply withdraw` command. It requires the entrypoint of the contract, transaction ID, destination address, and a witness file. ```bash simply withdraw --entrypoint p2pk.simf --txid abc123... --destination tex1qdest... --witness witness.wit ``` -------------------------------- ### Network Parameters Source: https://docs.simplicity-lang.org/getting-started/cli Key network parameters for Liquid Testnet. ```APIDOC ## Liquid Testnet Network Parameters ### Genesis Hash `a771da8e52ee6ad581ed1e9a99825e5b3b7992225534eaa2ae23244fe26ab1c1` ### L-BTC Asset ID `144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49` ### Explorer API Base URL `https://blockstream.info/liquidtestnet/api` ``` -------------------------------- ### Compile Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Compiles a Simplicity contract file using the `simply build` command. The `--entrypoint` flag specifies the contract file to compile. ```bash simply build --entrypoint my_contract.simf ``` -------------------------------- ### Simplicity: Product Constructor and Type Checking Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Illustrates the product constructor in Simplicity. If 'b' has type 'B' and 'c' has type 'C' in context 'Γ', then '(b, c)' has the type 'B × C'. ```simplicity If Γ ⊩ `b`: B If Γ ⊩ `c`: C Then Γ ⊩ `(b, c)`: B × C ``` -------------------------------- ### Build Simplicity Contract with Statistics Source: https://docs.simplicity-lang.org/getting-started/cli Compiles a Simplicity contract and generates performance statistics, including cost bounds, memory usage, and program size, using the `simply build --stats` command. ```bash simply build --entrypoint contract.simf --stats ``` -------------------------------- ### Simplicity Web IDE Compilation Process Source: https://docs.simplicity-lang.org/getting-started/web-ide The steps involved in compiling SimplicityHL source code within the Web IDE. This includes parsing, compiling to Simplicity bytecode, computing the Commitment Root (CMR), and generating a P2TR address. ```rust src/compile.rs ``` -------------------------------- ### Get Transaction Hex via Blockstream API Source: https://docs.simplicity-lang.org/getting-started/cli Fetches the raw hexadecimal representation of a transaction on the Liquid Testnet using its transaction ID (txid) from the Blockstream API. This hex can be used for broadcasting or further analysis. ```bash curl "https://blockstream.info/liquidtestnet/api/tx/abc123.../hex" ``` -------------------------------- ### SimplicityHL Type Alias Definition Source: https://docs.simplicity-lang.org/simplicityhl-reference/type_alias This example illustrates the definition of a custom type alias in SimplicityHL. Aliases provide a new name for an existing type, improving code readability without creating new types like structs. ```simplicityhl type User = (bool, u256, u64); ``` -------------------------------- ### Liquid Testnet API (Blockstream) Source: https://docs.simplicity-lang.org/getting-started/cli Interact with the Liquid Testnet blockchain using the Blockstream API. ```APIDOC ## Liquid Testnet API Endpoints **Base URL:** `https://blockstream.info/liquidtestnet/api` ### Check Address Balance (UTXOs) Retrieves unspent transaction outputs (UTXOs) for a given address. #### Method `GET` #### Endpoint `/address/
/utxo` ### Get Transaction Details Fetches detailed information about a specific transaction. #### Method `GET` #### Endpoint `/tx/` ### Get Transaction Hex Retrieves the raw hexadecimal representation of a transaction. #### Method `GET` #### Endpoint `/tx//hex` ### Broadcast Transaction Submits a raw transaction hex to the Liquid network for inclusion in a block. #### Method `POST` #### Endpoint `/tx` #### Request Body - **transaction_hex** (string) - Required - The hexadecimal string of the transaction to broadcast. ### Check Transaction Confirmation Status Verifies if a transaction has been confirmed and provides block information. #### Method `GET` #### Endpoint `/tx//status` #### Response Example (Success) ```json { "confirmed": true, "block_height": 2137590, "block_hash": "abc..." } ``` ``` -------------------------------- ### Simplicity: Pattern Context Creation Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Shows how pattern contexts are created in Simplicity. PCtx(A, 'v') creates a context mapping 'v' to type 'A'. PCtx(A, '_') creates an empty context. ```simplicity Type A and pattern `p` create a context denoted by PCtx(A, `p`) PCtx(A, `v`) := [`v` ↦ A] PCtx(A, `_`) := [] ``` -------------------------------- ### Addition Jets (uN) Source: https://docs.simplicity-lang.org/documentation/jets-overview Performs addition for unsigned integers of various bit widths, returning a carry flag and the sum. Available for bit widths: 1, 8, 16, 32, 64, 128, 256. Example shown for 32-bit. ```Simplicity let (carry, sum) = jet::add_32(x, y); ``` -------------------------------- ### Troubleshoot: Test API Connectivity Source: https://docs.simplicity-lang.org/getting-started/cli Checks connectivity to the Blockstream API for Liquid Testnet by making a simple request. A successful response should return API documentation. ```bash # Test API connectivity curl "https://blockstream.info/liquidtestnet/api" # Should return API documentation ``` -------------------------------- ### SimplicityHL Hash Time-Locked Contract Example Source: https://docs.simplicity-lang.org/index This snippet implements a Hash Time-Locked Contract (HTLC) in SimplicityHL. It includes functions for SHA-2 hashing, signature verification, and conditional spending based on a preimage or a timeout. The contract allows a recipient to claim funds with a secret, or a sender to reclaim them after a block height. ```SimplicityHL /* * The recipient can spend the coins by providing the secret preimage of a hash. * The sender can cancel the transfer after a fixed block height. * * HTLCs enable two-way payment channels and multi-hop payments, * such as on the Lightning network. */ fn sha2(string: u256) -> u256 { let hasher: Ctx8 = jet::sha_256_ctx_8_init(); let hasher: Ctx8 = jet::sha_256_ctx_8_add_32(hasher, string); jet::sha_256_ctx_8_finalize(hasher) } fn checksig(pk: Pubkey, sig: Signature) { let msg: u256 = jet::sig_all_hash(); jet::bip_0340_verify((pk, msg), sig); } fn complete_spend(preimage: u256, recipient_sig: Signature) { let hash: u256 = sha2(preimage); let expected_hash: u256 = 0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925; sha2([0x00; 32]) assert!(jet::eq_256(hash, expected_hash)); let recipient_pk: Pubkey = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798; 1 * G checksig(recipient_pk, recipient_sig); } fn cancel_spend(sender_sig: Signature) { let timeout: Height = 1000; jet::check_lock_height(timeout); let sender_pk: Pubkey = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5; 2 * G checksig(sender_pk, sender_sig) } fn main() { match witness::COMPLETE_OR_CANCEL { Left(preimage_sig: (u256, Signature)) => { let (preimage, recipient_sig): (u256, Signature) = preimage_sig; complete_spend(preimage, recipient_sig); }, Right(sender_sig: Signature) => cancel_spend(sender_sig), } } ``` -------------------------------- ### Elements CLI Common Commands Reference (Testnet) Source: https://docs.simplicity-lang.org/getting-started/cli A reference for common `elements-cli` commands used for Testnet operations, such as checking blockchain info, creating addresses, sending transactions, and retrieving transaction details. ```bash # Testnet operations elements-cli -chain=liquidtestnet getblockchaininfo elements-cli -chain=liquidtestnet getnewaddress elements-cli -chain=liquidtestnet sendtoaddress
elements-cli -chain=liquidtestnet sendrawtransaction elements-cli -chain=liquidtestnet gettransaction ``` -------------------------------- ### Simplicity Web IDE Transaction Building Steps Source: https://docs.simplicity-lang.org/getting-started/web-ide The internal process the Simplicity Web IDE follows to construct a transaction. This involves creating the transaction structure, building the sighash, satisfying the Simplicity program with witness data, encoding, and serializing the transaction. ```plaintext 1. Create transaction structure 2. Build sighash from transaction data + genesis hash 3. Satisfy Simplicity program with witness 4. Encode program and witness to bytes 5. Build complete witness stack 6. Serialize transaction to hex ``` -------------------------------- ### Test Simplicity Contract Locally Source: https://docs.simplicity-lang.org/getting-started/cli Runs a Simplicity contract locally for testing purposes using the `simply run` command. The `--logging debug` option provides detailed execution trace, jet calls, and debug output. ```bash simply run --entrypoint contract.simf --logging debug ``` -------------------------------- ### Build and Broadcast Spending Transaction Source: https://docs.simplicity-lang.org/getting-started/cli Constructs and broadcasts a transaction to spend funds from a UTXO to a specified destination address using `simply withdraw`. This command automatically handles fetching UTXO, building the transaction, encoding the Simplicity program and witness, and broadcasting to the Liquid testnet. ```bash simply withdraw --entrypoint always_true.simf --txid c2f44551601034af3cc0d004b5b486d558c867bd9bc4f97123e48e4ddd3b8d42 --destination tex1qrecipient7r2qf9h8xvua5jk3n4l6p8r9t2s4v6w8x ``` -------------------------------- ### SimplicityHL Main Function Entry Point Source: https://docs.simplicity-lang.org/simplicityhl-reference/function Defines the 'main' function, which serves as the mandatory entry point for all SimplicityHL programs. Execution of a SimplicityHL program begins by running its 'main' function, from which other functions are typically called. ```simplicityhl fn main() { // ... } ``` -------------------------------- ### Request L-BTC from Liquid Testnet Faucet Source: https://docs.simplicity-lang.org/getting-started/cli Uses `curl` to request Liquid Bitcoin (L-BTC) from the testnet faucet. The request includes the P2TR address generated in the previous step. ```bash curl "https://liquidtestnet.com/faucet?address=tex1p5m8j7r2qf9h8xvua5jk3n4l6p8r9t2s4v6w8x&action=lbtc" ``` -------------------------------- ### SHA-256 Initialization Jet Source: https://docs.simplicity-lang.org/documentation/jets-overview Initializes a SHA-256 context for hashing. Uses an 8-byte context. ```Simplicity let ctx = sha_256_ctx_8_init(); ``` -------------------------------- ### Create a P2PK Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Defines a Simplicity contract for a Pay-to-Public-Key (P2PK) scenario. It includes logic for verifying a signature against a public key and a message derived from the transaction sighash. ```simplicity fn main() { let pk: Pubkey = 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798; let msg: u256 = jet::sig_all_hash(); let sig: Signature = witness::signature; jet::bip_0340_verify(pk, msg, sig) } ``` -------------------------------- ### Elements Node Operations Source: https://docs.simplicity-lang.org/getting-started/cli Commands for managing and interacting with an Elements node for Liquid Testnet. ```APIDOC ## Elements Node Commands ### Start Liquid Testnet Node Initializes and starts a Liquid Testnet node. #### Command `elementsd -chain=liquidtestnet -daemon` ### Create Wallet Creates a new wallet for the Elements node. #### Command `elements-cli -chain=liquidtestnet createwallet ` ### Generate New Address Generates a new P2PKH address within a specified wallet. #### Command `elements-cli -chain=liquidtestnet -rpcwallet= getnewaddress` ### Get Wallet Balance Retrieves the current balance of the specified wallet. #### Command `elements-cli -chain=liquidtestnet -rpcwallet= getbalance` ### Send Raw Transaction Broadcasts a pre-signed raw transaction to the Liquid network. #### Command `elements-cli -chain=liquidtestnet sendrawtransaction ` ``` -------------------------------- ### Run Simplicity Test Suite Source: https://docs.simplicity-lang.org/getting-started/cli Executes all test functions within Simplicity contract files. Tests are identified by functions prefixed with `test_`. ```bash simply test ``` -------------------------------- ### Create Witness File (Simplicity) Source: https://docs.simplicity-lang.org/getting-started/cli Defines the structure for a witness file in JSON format, required for certain Simplicity operations. This includes the signature value and type. ```json { "signature": { "value": "0x", "type": "Signature" } } ``` -------------------------------- ### Generate New Address with Elements CLI Source: https://docs.simplicity-lang.org/getting-started/cli Generates a new receiving address using the specified wallet ('mywallet') on the Liquid Testnet via `elements-cli`. This address can be used to receive funds. ```bash elements-cli -chain=liquidtestnet -rpcwallet=mywallet getnewaddress ``` -------------------------------- ### Internal Sighash Computation in Simplicity Source: https://docs.simplicity-lang.org/getting-started/cli Illustrates how `simply` internally computes the sighash for transaction signing. The `ElementsEnv` struct is used to construct the transaction environment, and the `sighash_all()` method calculates the sighash, which is then accessible within the contract via `jet::sig_all_hash()`. ```rust // simply builds the transaction environment let tx_env = ElementsEnv::new( transaction, vec![utxo], input_index, cmr, control_block, None, genesis_hash // Liquid testnet: a771da8e... ); // Computes sighash automatically let sighash = tx_env.c_tx_env().sighash_all(); ``` -------------------------------- ### Simplicity Product Environment Definition Source: https://docs.simplicity-lang.org/simplicityhl-reference/environment Defines the product of two Simplicity environments, ΞA and ΞB, from types A and B respectively, resulting in an environment from type A × B. It details how shared and unique variable bindings are handled, including the use of 'take' and 'drop' combinators. ```simplicity Product(ΞA, ΞB) maps `v` to take a: A × B → C if ΞA maps `v` to Simplicity expression a: A → C Product(ΞA, ΞB) maps `v` to drop b: A × B → C if ΞB maps `v` to Simplicity expression b: B → C and ΞA doesn't map `v` ``` -------------------------------- ### Wait and Check UTXO after Funding Source: https://docs.simplicity-lang.org/getting-started/cli Pauses execution for 60 seconds using `sleep` and then checks for UTXOs at a given address using `curl` and `jq`. This is typically done after funding an address. ```bash sleep 60 curl "https://blockstream.info/liquidtestnet/api/address/tex1p5m8j7r2qf9h8xvua5jk3n4l6p8r9t2s4v6w8x/utxo" | jq '.[0]' ``` -------------------------------- ### Broadcast Transaction via Blockstream API Source: https://docs.simplicity-lang.org/getting-started/cli Submits a raw transaction (in hexadecimal format) to the Liquid Testnet network for confirmation using the Blockstream API. Requires a POST request with the transaction data. ```bash curl -X POST "https://blockstream.info/liquidtestnet/api/tx" -d "020000..." ``` -------------------------------- ### Send Raw Transaction with Elements CLI Source: https://docs.simplicity-lang.org/getting-started/cli Broadcasts a pre-signed raw transaction to the Liquid Testnet network using `elements-cli`. The transaction is provided in hexadecimal format. ```bash elements-cli -chain=liquidtestnet sendrawtransaction 020000... ``` -------------------------------- ### Check Address UTXO Balance on Liquid Testnet Source: https://docs.simplicity-lang.org/getting-started/cli Queries the Liquid testnet block explorer via `curl` to retrieve Unspent Transaction Outputs (UTXOs) for a given address. This is used to verify if the faucet funding was successful. ```bash curl "https://blockstream.info/liquidtestnet/api/address/tex1p5m8j7r2qf9h8xvua5jk3n4l6p8r9t2s4v6w8x/utxo" ``` -------------------------------- ### Check Address Balance via Blockstream API Source: https://docs.simplicity-lang.org/getting-started/cli Queries the Blockstream API for unspent transaction outputs (UTXOs) associated with a given Liquid Testnet address. This is used to check the available balance. ```bash curl "https://blockstream.info/liquidtestnet/api/address/tex1q.../utxo" ``` -------------------------------- ### Verify Transaction on Liquid Testnet Source: https://docs.simplicity-lang.org/getting-started/cli Uses `curl` to query the Liquid testnet block explorer for transaction details and confirmation status. This allows verification that the previously broadcasted transaction has been included in a block. ```bash curl "https://blockstream.info/liquidtestnet/api/tx/xyz789abc..." curl "https://blockstream.info/liquidtestnet/api/tx/xyz789abc.../status" ``` -------------------------------- ### Simplicity: Jet Application and Type Checking Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Explains how jets are applied in Simplicity. If 'j' is a jet of type 'B → C' and 'b' has type 'B' in context 'Γ', then 'jet::j b' has type 'C'. ```simplicity If `j` is the name of a jet of type B → C If Γ ⊩ `b`: B Then Γ ⊩ `jet::j b`: C ``` -------------------------------- ### Simplicity: Right Constructor and Type Checking Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Explains the Right constructor in Simplicity. If 'c' has type 'C' in context 'Γ', then 'Right(c)' has the type 'B + C' for any type 'B'. ```simplicity If Γ ⊩ `c`: c Then Γ ⊩ `Right(c)`: B + C For any B ``` -------------------------------- ### Simplicity: Pattern Context for Product Types Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Illustrates context creation for product types in Simplicity patterns. If 'p1' and 'p2' map disjoint variable sets, PCtx(A × B, '(p1, p2)') is the disjoint union of PCtx(A, 'p1') and PCtx(B, 'p2'). ```simplicity If `p1` and `p2` map disjoint sets of variables Then PCtx(A × B, `(p1, p2)`) := PCtx(A, `p1`) ⊎ PCtx(B, `p2`) ``` -------------------------------- ### Calling a SimplicityHL Jet Function Source: https://docs.simplicity-lang.org/simplicityhl-reference/function Demonstrates the invocation of a predefined and optimized function, known as a 'jet'. Jets are accessed through their namespace, prefixed with 'jet::', and provide efficient implementations for common operations. ```simplicityhl jet::add_32(40, 2) ``` -------------------------------- ### Liquid Testnet L-BTC Asset ID Source: https://docs.simplicity-lang.org/getting-started/cli Provides the asset identifier for L-BTC (Liquid Bitcoin) on the Liquid Testnet. ```plaintext 144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49 ``` -------------------------------- ### Simplicity Pattern Environment Generation Source: https://docs.simplicity-lang.org/simplicityhl-reference/environment Generates an environment for SimplicityHL patterns. It handles simple variable bindings and product patterns, creating corresponding Simplicity expressions using 'take' and 'drop' combinators as needed. The pattern '_' is ignored. ```simplicity PEnv'(t: A → B, `v`) := [`v` ↦ t] PEnv'(t: A → B, `_`) := [] If `p1` and `p2` contain disjoint sets of variables Then PEnv'(t: A → B × C, `(p1, p2)`) := PEnv'(take t: A → B, p1) ⊎ PEnv'(drop t: A → C, p2) PEnv(A, `p`) := PEnv'(iden: A → A, `p`) ``` -------------------------------- ### Simplicity Environment Definition Source: https://docs.simplicity-lang.org/simplicityhl-reference/environment Defines an environment mapping variable names to Simplicity expressions. It specifies the source type for all expressions within the environment. Variables like 'foo', 'bar', and 'baz' are shown with their respective type mappings. ```simplicity Ξ = [ foo ↦ unit: (𝟚^32? × 2^32) → 𝟙 , bar ↦ take iden: (𝟚^32? × 𝟚^32) → 𝟚^32? , baz ↦ drop iden: (𝟚^32? × 𝟚^32) → 𝟚^32 ] ``` -------------------------------- ### Define and Call a Simplicity Function Source: https://docs.simplicity-lang.org/simplicityhl-reference/function Demonstrates defining a function 'add' with parameters and a return type, including overflow checking, and subsequently calling this function with specific arguments. The function body executes sequentially, returning the final expression's value. ```simplicityhl fn add(x: u32, y: u32) -> u32 { let (carry, sum): (bool, u32) = jet::add_32(x, y); match carry { true => panic!(), // overflow false => {}, // ok }; sum } let z: u32 = add(40, 2); ``` -------------------------------- ### Troubleshoot: Verify UTXO Exists Source: https://docs.simplicity-lang.org/getting-started/cli Verifies if a specific transaction output (UTXO) exists and is unspent. This involves fetching the transaction's hex and checking the specific output index. ```bash # Verify UTXO exists curl "https://blockstream.info/liquidtestnet/api/tx//hex" # Check if already spent curl "https://blockstream.info/liquidtestnet/api/tx//outspend/" ``` -------------------------------- ### Spend Funds from Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Executes the spending logic of a Simplicity contract using the `simply withdraw` command. Requires the contract entrypoint, transaction ID of the funds to spend, and the destination address. ```bash simply withdraw --entrypoint my_contract.simf --txid c2f44551601034af3cc0d004b5b486d558c867bd9bc4f97123e48e4ddd3b8d42 --destination tex1qrecipient7address ``` -------------------------------- ### SHA-256 Context Update Jet Source: https://docs.simplicity-lang.org/documentation/jets-overview Adds a 4-byte word (u32) to an existing SHA-256 context. Returns the updated context. ```Simplicity ctx = sha_256_ctx_8_add_4(ctx, data_word); ``` -------------------------------- ### BIP-340 Signature Verification (Panic) Source: https://docs.simplicity-lang.org/documentation/jets-overview Verifies a BIP-340 Schnorr signature. Panics if the signature is invalid. Takes a tuple of public key and message hash, and the signature. ```Simplicity bip_0340_verify((pubkey, message_hash), signature); ``` -------------------------------- ### Basic SimplicityHL Contract Source: https://docs.simplicity-lang.org/getting-started/simplicityhl A simple SimplicityHL contract that always succeeds. Every contract must have a `main()` function. If `main()` does not abort, it is considered to have succeeded. There are no side effects other than aborts and read-only access to witness data and the transaction environment. ```rust fn main() { // This contract always succeeds } ``` -------------------------------- ### Simplicity: Define and Assign Variable with Let Source: https://docs.simplicity-lang.org/simplicityhl-reference/let_statement Demonstrates how to define a variable 'x' of type u32 and assign it an initial value or the result of a function call. ```simplicity let x: u32 = 1; ``` ```simplicity let x: u32 = f(1337); ``` -------------------------------- ### Simplicity Program Internal Key Source: https://docs.simplicity-lang.org/getting-started/web-ide The internal public key used for generating P2TR addresses within the SimplicityHL Web IDE. This key is derived from the Simplicity program's commitment. ```hex 0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0 ``` -------------------------------- ### Verify Transaction Status Source: https://docs.simplicity-lang.org/getting-started/cli Checks the confirmation status of a newly created transaction on the Liquid Testnet using its transaction ID (txid) via the Blockstream API and `jq` for parsing. ```bash curl "https://blockstream.info/liquidtestnet/api/tx//status" | jq . ``` -------------------------------- ### Define Witness Data for Simplicity Contract Source: https://docs.simplicity-lang.org/getting-started/cli Specifies the witness data required for a Simplicity contract, including signature details. For contracts like `always_true`, no witness data is needed. ```json { "signature": { "value": "0x<64_byte_hex>", "type": "Signature" } } ``` -------------------------------- ### SIGHASH_ALL Hash Computation Jet Source: https://docs.simplicity-lang.org/documentation/jets-overview Computes the SIGHASH_ALL signature hash. This is a Bitcoin-specific operation. ```Simplicity let sighash_all = sig_all_hash(); ``` -------------------------------- ### Simplicity: Left Constructor and Type Checking Source: https://docs.simplicity-lang.org/simplicityhl-reference/context Shows the Left constructor in Simplicity. If 'b' has type 'B' in context 'Γ', then 'Left(b)' has the type 'B + C' for any type 'C'. ```simplicity If Γ ⊩ `b`: B Then Γ ⊩ `Left(b)`: B + C For any C ```