### Build Ergo Transaction (Python) Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/docs/examples.rst Constructs an unsigned Ergo transaction, including defining output candidates with specified values and scripts, selecting appropriate input boxes, and setting transaction fees. This example requires the ergo-lib-python library and assumes pre-existing boxes and addresses. ```python from ergo_lib_python.chain import ErgoBoxCandidate from ergo_lib_python.transaction import TxBuilder from ergo_lib_python.wallet import select_boxes_simple # Create a new output candidate with 1 billion nanoErgs (1 ERG) output_candidate = ErgoBoxCandidate( value=10 ** 9, script = Address("9egnPnrYskFS8k1gYiKZEXZ2bhP9fvX9GZvsG1V3BzH3n8sBXrf"), creation_height = 10000) boxes = [] # List of boxes belonging to signer, left empty here fee = 10**7 # Pay 0.01 ERG fee # Select boxes whose value sums up to amount sent to recipient (1 ERG) and miner fee (0.01 ERG) selection = select_boxes_simple(boxes, target_balance=output_candidate.value + fee, target_tokens=[]) tx = TxBuilder(box_selection=selection, output_candidates=[output_candidate], current_height=1000, fee_amount=fee, change_address=Address("....")).build() # UnsignedTransaction ``` -------------------------------- ### Python Bindings for Sigma-Rust Usage Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Provides access to sigma-rust functionalities from Python applications, facilitating blockchain integration. This example shows wallet creation from a mnemonic, address derivation, and transaction building. ```python from ergo_lib_python import * # Create wallet from mnemonic mnemonic = "legal winner thank year wave sausage worth useful legal winner thank yellow" seed = Mnemonic.to_seed(mnemonic, "") master_key = ExtSecretKey.derive_master(seed) # Derive address path = DerivationPath.from_string("m/44'/429'/0'/0/0") derived_key = master_key.derive(path) pub_key = derived_key.public_key() address = pub_key.to_address() print(f"Address: {address.to_base58(NetworkPrefix.Mainnet)}") # Build transaction recipient_box = ErgoBoxCandidate( BoxValue.from_i64(I64(1000000)), Contract.pay_to_address(recipient_address), current_height, [], # tokens {} # registers ) # Select inputs selector = SimpleBoxSelector() selection = selector.select(input_boxes, target_balance, target_tokens) # Create and sign transaction tx_builder = TxBuilder( selection, [recipient_box], current_height, BoxValue.SUGGESTED_TX_FEE(), change_address ) unsigned_tx = tx_builder.build() wallet = Wallet.from_secrets([secret_key]) signed_tx = wallet.sign_transaction(tx_context, state_context) ``` -------------------------------- ### Run Doctests for ergo-lib-python Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/README.md This snippet details the process for running doctests, which requires Sphinx. It involves installing documentation dependencies, navigating to the docs directory, and then executing the doctest task. ```bash pip install -r docs/requirements.txt cd docs make doctest ``` -------------------------------- ### Build and Develop ergo-lib-python Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/README.md This snippet shows the commands to set up a Python virtual environment, install the necessary build tool 'maturin', and then develop the ergo-lib-python library in place. It allows for immediate testing of changes. ```bash python -m venv .venv source .venv/bin/activate pip install maturin maturin develop ``` -------------------------------- ### Rust: Build and Sign Ergo Transactions Source: https://context7.com/ergoplatform/sigma-rust/llms.txt This example shows how to construct an unsigned Ergo transaction using `ergo_lib::wallet::tx_builder::TxBuilder`. It covers selecting boxes, defining outputs, managing fees, and optionally adding data inputs, context extensions, or token burning permissions. The subsequent steps illustrate signing the transaction using a `Wallet` instance, including preparation of the `TransactionContext` and `ErgoStateContext`. ```rust use ergo_lib::wallet::tx_builder::TxBuilder; use ergo_lib::wallet::Wallet; use ergo_lib::chain::transaction::{TransactionContext, Transaction}; use ergo_lib::chain::ergo_box::DataInput; use ergo_lib::ergo_state_context::ErgoStateContext; use ergo_lib::wallet::secret::SecretKey; // Box selection already performed let box_selection = selector.select(inputs, target_balance, &target_tokens)?; // Define output candidates let output_candidates = vec![ recipient_box_candidate, // additional outputs... ]; // Build transaction let mut tx_builder = TxBuilder::new( box_selection, output_candidates, current_height, TxBuilder::SUGGESTED_TX_FEE(), // 1,100,000 nanoERG change_address, ); // Optional: Add data inputs (read-only boxes) tx_builder.set_data_inputs(vec![ DataInput::new(oracle_box_id) ]); // Optional: Set context extensions for specific inputs tx_builder.set_context_extension( input_box_id, ContextExtension::new(context_vars) ); // Optional: Allow token burning tx_builder.set_token_burn_permit(vec![ Token { token_id: burn_token_id, amount: burn_amount } ]); // Build unsigned transaction let unsigned_tx = tx_builder.build()?; // Create wallet from mnemonic let wallet = Wallet::from_mnemonic( "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", "" )?; // Or create from existing secret keys let secret_key = SecretKey::dlog_from_bytes(&sk_bytes)?; let wallet = Wallet::from_secrets(vec![secret_key]); // Prepare transaction context let tx_context = TransactionContext::new( unsigned_tx, input_boxes.clone(), data_input_boxes.clone() )?; // Create state context (blockchain state) let state_context = ErgoStateContext::new( pre_header, block_headers ); // Sign transaction let signed_tx = wallet.sign_transaction( tx_context, &state_context, None // no transaction hints )?; // Verify transaction is valid assert!(signed_tx.inputs().len() > 0); println!("Signed transaction ID: {}", signed_tx.id()); ``` -------------------------------- ### Evaluate ErgoTree Scripts with Interpreter Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Executes and evaluates ErgoTree scripts using the ErgoTree interpreter and blockchain context for smart contract validation. This example shows how to prepare the context and evaluate a script. ```rust use ergotree_interpreter::{eval, sigma_protocol::prover::Prover}; use ergo_lib::chain::transaction::{Input, Transaction}; // Prepare evaluation context let ctx = ErgoTreeEvaluationContext { height: current_height, self_box: spending_box.clone(), tx_context: TxIoVec { inputs: tx.inputs.clone(), data_inputs: tx.data_inputs.clone(), outputs: tx.outputs.clone(), }, }; // Evaluate ErgoTree script let ergo_tree = spending_box.ergo_tree(); let proof_result = eval::evaluate_tree( ergo_tree, &ctx, &prover )?; // Check if proposition is satisfied match proof_result { EvaluationResult::True => println!("Script evaluation succeeded"), EvaluationResult::False => println!("Script evaluation failed"), } ``` -------------------------------- ### Mint Token in Ergo Transaction (Python) Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/docs/examples.rst Builds an Ergo transaction that mints a new token. This involves defining an `ErgoBoxCandidate` with token details, including token ID, name, description, and decimals, and ensuring sufficient input boxes are selected to cover the minting costs and fees. Requires the ergo-lib-python library. ```python from ergo_lib_python.chain import Token, TokenId, ErgoBoxCandidate, TxBuilder boxes = [] # list of boxes belonging to signer fee = 10**7 # Pay 0.01 ERG fee selection = select_boxes_simple(boxes, target_balance=10**9 + fee, []) # The identifier of the token must be the ID of the first input in the transaction mint_token = Token(TokenId(selection.boxes[0].box_id), amount=1) mint_candidate = ErgoBoxCandidate( value = 10**9, script = Address("...."), creation_height = 10000, mint_token = mint_token, mint_token_name = "NFT", mint_token_desc = "desc", mint_token_decimals = 0 ) tx = TxBuilder( box_selection=selection, output_candidates=[output_candidate], current_height=1000, fee_amount=fee, change_address=Address("....")).build() # UnsignedTransaction ``` -------------------------------- ### Build ergo-lib-c Crate with REST API Features Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-c/README.md Builds the ergo-lib-c crate with support for REST API features using Cargo. Ensure you have Rust and Cargo installed. This command enables specific functionalities for network interactions. ```bash cargo build -p ergo-lib-c --features rest ``` -------------------------------- ### WASM JavaScript/TypeScript Integration for Sigma-Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Enables the use of sigma-rust functionalities within JavaScript and TypeScript applications through WebAssembly bindings. This example demonstrates wallet address generation and transaction signing. ```typescript import { ExtSecretKey, Mnemonic, DerivationPath, NetworkAddress, NetworkPrefix, Wallet, SecretKeys, ErgoBoxes, UnsignedTransaction, ErgoStateContext, BlockHeaders, PreHeader, BoxSelection, SimpleBoxSelector, ErgoBoxCandidateBuilder, BoxValue, Contract, I64 } from 'ergo-lib-wasm-nodejs'; // Generate wallet address const mnemonic = "legal winner thank year wave sausage worth useful legal winner thank yellow"; const seed = Mnemonic.to_seed(mnemonic, ""); const rootSecret = ExtSecretKey.derive_master(seed); const changePath = DerivationPath.new(0, new Uint32Array([0])); const changeSecretKey = rootSecret.derive(changePath); const changePubKey = changeSecretKey.public_key(); const changeAddress = NetworkAddress.new( NetworkPrefix.Mainnet, changePubKey.to_address() ); // Build and sign transaction const recipientBox = new ErgoBoxCandidateBuilder( BoxValue.from_i64(I64.from_str("1000000")), Contract.pay_to_address(recipientAddress), currentHeight ).build(); const unsignedTx = new UnsignedTransaction( unsignedInputs, dataInputs, outputCandidates ); const secretKeys = new SecretKeys(); secretKeys.add(changeSecretKey); const wallet = Wallet.from_secrets(secretKeys); const blockHeaders = BlockHeaders.from_json(blockHeadersJson); const preHeader = PreHeader.from_block_header(blockHeaders.get(0)); const stateCtx = new ErgoStateContext(preHeader, blockHeaders); const signedTx = wallet.sign_transaction( stateCtx, unsignedTx, inputBoxes, dataInputBoxes ); console.log(signedTx.to_json()); ``` -------------------------------- ### Generate Mnemonic and Address from Secret Key (Python) Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/docs/examples.rst Generates a mnemonic phrase, derives an extended secret key, and then derives the public key and address for the Ergo blockchain. Requires the ergo-lib-python library. Outputs a string representation of the Ergo address. ```python from ergo_lib_python.wallet import MnemonicGenerator, ExtSecretKey, DerivationPath from ergo_lib_python.chain import NetworkPrefix mnemonic = MnemonicGenerator("english", 128).generate() # create Extended Secret Key and derive first secret key using default derivation path ext_secret_key = ExtSecretKey.from_mnemonic(mnemonic, password="").derive(DerivationPath()) address = ext_secret_key.public_key().address() address.to_str(NetworkPrefix.Mainnet) # 9eg... ``` -------------------------------- ### Generate ergo_lib.h C Header File using cbindgen Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-c/README.md Generates the C header file (ergo_lib.h) from the ergo-lib-c Rust crate using cbindgen. This command requires a nightly version of rustc to expand macros, though the crate itself can be compiled with a stable version. Ensure cbindgen is installed and configured. ```bash cbindgen --config cbindgen.toml --crate ergo-lib-c --output h/ergo_lib.h ``` -------------------------------- ### Generate Xcode Project for iOS Simulator Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Generates an Xcode project for the iOS simulator and prepares it for building. This involves generating the project file and then using xcodebuild to compile the project, specifying the correct configuration and SDK. ```shell cd bindings/ergo-lib-ios swift package generate-xcodeproj xcodebuild -project ./ErgoLib.xcodeproj -xcconfig ./Config/iPhoneSimulator_{arm|intel}.xcconfig -sdk iphonesimulator ``` -------------------------------- ### Build Swift Package for iOS Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Builds the Swift package for the ergo-lib-ios project. This command links the previously compiled ergo-lib static library into the Swift project. It's used for both regular builds and tests. ```shell cd ../ergo-lib-ios swift build -Xlinker -L../../target/release/ swift test -Xlinker -L../../target/release/ --skip RestNodeApiTests --skip RestNodeApiIntegrationTests ``` -------------------------------- ### Output Box Building with Registers and Tokens in Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Demonstrates the construction of an output ErgoBox candidate. It includes setting the recipient address, adding tokens with specific amounts, configuring custom register values (R4-R9), calculating the minimum required box value, and finally building the box candidate. ```rust use ergo_lib::chain::ergo_box::box_builder::ErgoBoxCandidateBuilder; use ergo_lib::chain::contract::Contract; use ergo_lib::chain::address::Address; use ergo_lib::ergotree_ir::value::{BoxValue, Constant}; use ergo_lib::chain::token::{Token, TokenId}; use ergo_lib::ergotree_ir::serialization::ConstantSerializer; use ergo_lib::ergotree_ir::ir::types::NonMandatoryRegisterId; use std::str::FromStr; // Assume recipient_address is a valid Address object // let recipient_address = Address::from_base58("9f...")?; let current_height = 1000000u32; // Create basic output box // let mut box_builder = ErgoBoxCandidateBuilder::new( // BoxValue::try_from(2000000u64)?, // Contract::pay_to_address(&recipient_address)?.ergo_tree(), // current_height // ); // Add token to box // box_builder.add_token(Token { // token_id: TokenId::from_str("abc123...")?, // amount: 50.try_into()?, // }); // Set custom register values (R4-R9) // box_builder.set_register_value( // NonMandatoryRegisterId::R4, // Constant::from(100i32) // ); // Calculate minimum box value based on contents // let min_value = box_builder.calc_min_box_value()?; // box_builder.set_value(min_value); // Build the box candidate // let output_box = box_builder.build()?; ``` -------------------------------- ### Build Xcode Project for iPhone (iOS) Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Builds the Xcode project for the actual iPhone device. This requires compiling the ergo-lib-c for the ARM64 target and then using xcodebuild with the appropriate configuration and SDK for iOS. ```shell rustup target add aarch64-apple-ios cargo build --release --target=aarch64-apple-ios -p ergo-lib-c cd bindings/ergo-lib-ios swift package generate-xcodeproj xcodebuild -project ./ErgoLib.xcodeproj -xcconfig ./Config/iPhoneOS.xcconfig -sdk iphoneos ``` -------------------------------- ### Address Creation and Encoding in Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Illustrates parsing an Ergo address from a base58 string, creating a P2PK address from public key bytes, encoding addresses for different networks (mainnet/testnet), converting addresses to ErgoTree, and recreating an address from an ErgoTree. ```rust use ergo_lib::chain::address::{Address, AddressEncoder, NetworkPrefix}; use ergo_lib::ergotree_ir::chain::address::AddressTypePrefix; // Parse address from base58 string let addr_str = "9fRusAarL1KkrWQVsNrWuzXRsQu8A8D8PKuW8NqCzzq23VKKpss"; let address = AddressEncoder::decode_address_as_string(addr_str)?; // Create P2PK address from public key bytes // let pk_bytes: [u8; 33] = /* public key bytes */; // let p2pk_address = Address::p2pk_from_pk_bytes(&pk_bytes)?; // Encode address for different networks // let mainnet_str = p2pk_address.to_base58(NetworkPrefix::Mainnet); // let testnet_str = p2pk_address.to_base58(NetworkPrefix::Testnet); // Convert address to ErgoTree let ergo_tree = address.to_ergo_tree()?; // Recreate address from ErgoTree let recreated = Address::recreate_from_ergo_tree(&ergo_tree)?; ``` -------------------------------- ### UTXO Box Selection for Transactions in Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Shows how to use the SimpleBoxSelector to select input boxes from a given set to satisfy a target balance and specific token requirements. It also demonstrates how to access the selected inputs and any generated change boxes. ```rust use ergo_lib::wallet::box_selector::{BoxSelector, SimpleBoxSelector}; use ergo_lib::chain::transaction::TxIoVec; use ergo_lib::ergotree_ir::value::BoxValue; use ergo_lib::chain::token::{Token, TokenId}; use std::str::FromStr; // Assume available_boxes is a populated Vec // let available_boxes = ...; // Create box selector let selector = SimpleBoxSelector::new(); // Define target balance and tokens let target_balance = BoxValue::try_from(1100000u64)?; let target_tokens = vec![ Token { token_id: TokenId::from_str("tokenId1")?, amount: 100.try_into()?, } ]; // Select boxes from available inputs // let selection = selector.select( // available_boxes, // target_balance, // &target_tokens // )?; // BoxSelection contains selected inputs and change boxes // println!("Selected {} inputs", selection.boxes.len()); // for change_box in &selection.change_boxes { // println!("Change: {} nanoERG", change_box.value); // } ``` -------------------------------- ### Run Python Unit Tests for ergo-lib-python Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-python/README.md This command executes the Python unit tests located within the 'tests/' directory. It's a standard way to verify the correctness of the library's individual components. ```bash python -m unittest tests/*.py ``` -------------------------------- ### Build ergo-lib-c for iOS Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Compiles the ergo-lib-c Rust library for iOS targets. This command builds the static library required for the Swift wrapper. It supports cross-compilation for different architectures and simulators. ```shell cargo build --release --features rest --features mnemonic_gen -p ergo-lib-c --target x86_64-apple-ios cargo build --release --features rest --features mnemonic_gen -p ergo-lib-c --target aarch64-apple-ios cargo build --release --features rest --features mnemonic_gen -p ergo-lib-c --target aarch64-apple-ios-sim ``` -------------------------------- ### HD Wallet and Key Management with Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Demonstrates how to generate a seed from a mnemonic phrase, derive a master key, and then derive a specific key using an EIP-3 derivation path. It concludes by converting the derived public key to an Ergo address. ```rust use ergo_lib::wallet::{Mnemonic, ext_secret_key::ExtSecretKey, derivation_path::DerivationPath}; use ergo_lib::chain::address::NetworkPrefix; // Generate seed from mnemonic phrase let mnemonic = "change me do not use me change me do not use me"; let password = ""; let seed = Mnemonic::to_seed(mnemonic, password)?; // Derive master key from seed let master_key = ExtSecretKey::derive_master(seed)?; // EIP-3 derivation path: m/44'/429'/0'/0/address_index let path = DerivationPath::from_string("m/44'/429'/0'/0/0")?; let derived_key = master_key.derive(path)?; let public_key = derived_key.public_key()?; // Convert to Ergo address let address = public_key.to_address(); println!("Address: {}", address.to_base58(NetworkPrefix::Mainnet)); ``` -------------------------------- ### Configure Xcode Linker Flags for iPhone Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Sets the 'Other Linker Flags' in Xcode for the iPhone build. This points to the location of the ARM64 ergo-lib static library, enabling the Swift project to link against it for deployment on physical iOS devices. ```shell Set Other Linker Flags to be -L/absolute/path/to/sigma-rust/aarch64-apple-ios/release. ``` -------------------------------- ### Rust: Mint New Token with EIP-4 Metadata Source: https://context7.com/ergoplatform/sigma-rust/llms.txt This snippet demonstrates how to create a new token on the Ergo blockchain using the EIP-4 standard. It utilizes `ergo_lib` to define token details such as ID, initial supply, name, description, and decimals, associating them with a minting box. ```rust use ergo_lib::chain::ergo_box::box_builder::ErgoBoxCandidateBuilder; use ergo_lib::chain::token::{Token, TokenId, TokenAmount}; // First input box ID becomes the new token ID let first_input_box = &input_boxes[0]; let new_token_id = TokenId::from(first_input_box.box_id()); // Create token with initial supply let token = Token { token_id: new_token_id, amount: TokenAmount::try_from(1000000u64)?, }; // Build minting box with token metadata let mut box_builder = ErgoBoxCandidateBuilder::new( BoxValue::SAFE_USER_MIN, owner_ergo_tree, current_height ); box_builder.mint_token( token, "MyToken".to_string(), "A sample token for testing".to_string(), 2 // number of decimals ); let minting_box = box_builder.build()?; // Note: First transaction input MUST be the box whose ID matches token_id ``` -------------------------------- ### Compile ErgoScript to ErgoTree Bytecode Source: https://context7.com/ergoplatform/sigma-rust/llms.txt Compiles ErgoScript source code into executable ErgoTree bytecode, which is used for smart contracts on the Ergo platform. It supports simple and complex scripts with context variables. ```rust use ergoscript_compiler::compiler; use ergoscript_compiler::script_env::ScriptEnv; use ergo_lib::chain::contract::Contract; // Simple height-based timelock contract let script = r#" { sigmaProp(HEIGHT > 100000 && OUTPUTS(0).value >= 1000000L) } "#; // Compile to ErgoTree let ergo_tree = compiler::compile(script, ScriptEnv::new())?; let contract = Contract::new(ergo_tree); // More complex contract with context variables let advanced_script = r#" { val myPubKey = CONTEXT.getVar[SigmaProp](0).get val deadline = CONTEXT.getVar[Int](1).get sigmaProp( (HEIGHT < deadline && myPubKey) || (HEIGHT >= deadline && OUTPUTS(0).propositionBytes == SELF.propositionBytes) ) } "#; let advanced_tree = compiler::compile(advanced_script, ScriptEnv::new())?; // Use in box builder let protected_box = ErgoBoxCandidateBuilder::new( value, advanced_tree, current_height ).build()?; ``` -------------------------------- ### Configure Xcode Linker Flags for Simulator Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Sets the 'Other Linker Flags' in Xcode to point to the correct directory of the ergo-lib static library for iOS simulators. This ensures that the Swift project can find and link against the compiled Rust library. ```shell Set Other Linker Flags to be -L/absolute/path/to/sigma-rust/target/release for x86_64 and -L/absolute/path/to/sigma-rust/target/aarch64-apple-ios-sim/release for simulator on Apple silicon macs. ``` -------------------------------- ### Generate C Headers with cbindgen Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-ios/README.md Generates C header files from Rust code using cbindgen. This step requires a nightly version of the Rust compiler to handle macros. The generated header file is essential for the Swift wrapper to interface with the C bindings. ```shell cd bindings/ergo-lib-c rustup override set nightly cbindgen --config cbindgen.toml --crate ergo-lib-c --output h/ergo_lib.h ustup override set stable ``` -------------------------------- ### Rust: Multi-Signature Ergo Transaction Signing Source: https://context7.com/ergoplatform/sigma-rust/llms.txt This code illustrates how to handle multi-signature transactions on Ergo. It demonstrates the process where multiple parties generate transaction commitments using their respective wallets and then aggregate these commitments. Finally, one party can sign the transaction using the combined hints, enabling collaborative transaction finalization. ```rust use ergo_lib::wallet::TransactionHintsBag; // Party 1: Generate commitments let wallet1 = Wallet::from_secrets(vec![secret_key1]); let hints1 = wallet1.generate_commitments( tx_context.clone(), &state_context )?; // Party 2: Generate commitments let wallet2 = Wallet::from_secrets(vec![secret_key2]); let hints2 = wallet2.generate_commitments( tx_context.clone(), &state_context )?; // Aggregate hints from all parties let mut combined_hints = TransactionHintsBag::empty(); for input_idx in 0..unsigned_tx.inputs().len() { combined_hints.add_hints_for_input( input_idx, hints1.all_hints_for_input(input_idx) ); combined_hints.add_hints_for_input( input_idx, hints2.all_hints_for_input(input_idx) ); } // Any party can now sign with combined hints let signed_tx = wallet1.sign_transaction( tx_context, &state_context, Some(&combined_hints) )?; ``` -------------------------------- ### Interact with Ergo Node via REST API using Rust Source: https://context7.com/ergoplatform/sigma-rust/llms.txt This snippet demonstrates how to use the ergo_rest library in Rust to interact with an Ergo node's REST API. It covers fetching node information, querying unspent boxes for an address, submitting signed transactions, checking transaction status, and retrieving blockchain parameters. Ensure you have a running Ergo node accessible at the specified address. ```rust use ergo_rest::{ErgoRestApi, NodeApi}; // Create REST API client let api = ErgoRestApi::new("http://127.0.0.1:9053"); // Get blockchain info let info = api.get_node_info().await?; println!("Node height: {}", info.full_height); // Get unspent boxes for address let boxes = api.get_box_by_address(&address, 0, 100).await?; println!("Found {} unspent boxes", boxes.items.len()); // Submit signed transaction let tx_id = api.submit_transaction(&signed_tx).await?; println!("Transaction submitted: {}", tx_id); // Check transaction status let tx_status = api.get_transaction_status(&tx_id).await?; println!("Confirmations: {}", tx_status.confirmations); // Get current blockchain parameters let parameters = api.get_parameters().await?; println!("Storage fee: {}", parameters.storage_fee_factor); ``` -------------------------------- ### Webpack Configuration for TextDecoder/TextEncoder in ergo-lib-wasm Source: https://github.com/ergoplatform/sigma-rust/blob/develop/bindings/ergo-lib-wasm/README.md This snippet shows how to configure Webpack to provide TextDecoder and TextEncoder polyfills, which are often required when using WebAssembly modules like ergo-lib-wasm in certain bundler environments. It ensures compatibility by aliasing the 'text-encoder' library's implementations. ```javascript new webpack.ProvidePlugin({ TextDecoder: ['text-encoder', 'TextDecoder'], TextEncoder: ['text-encoder', 'TextEncoder'] }) ``` -------------------------------- ### Update Snapshot Tests with UPDATE_EXPECT Source: https://github.com/ergoplatform/sigma-rust/blob/develop/docs/architecture.md This command updates snapshot test data by running cargo test with the UPDATE_EXPECT environment variable set to 1. It is used to refresh expected test outputs after changes to the compiler or interpreter. ```bash env UPDATE_EXPECT=1 cargo test ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.