### Docker Compose Setup for Development Source: https://github.com/buildonspark/btkn/blob/main/infrastructure/README.md Starts services for a development environment using docker-compose. Supports different configurations including single node, two nodes, three nodes, and a comprehensive end-to-end setup with Bitcoin and Electrs backends. Use --force-recreate if network issues arise. ```sh # Regular setup for development with one node docker compose --file ./infrastructure/dev/docker-compose.yaml --project-directory . up # Setup with two LRC20 nodes docker compose --file ./infrastructure/dev/docker-compose.yaml --project-directory . --profile two_nodes_setup up # Setup with three LRC20 nodes docker compose --file ./infrastructure/dev/docker-compose.yaml --project-directory . --profile three_nodes_setup up # Setup with three LRC20 nodes, two Bitcoin nodes and two Electrs backends docker compose --file ./infrastructure/dev/docker-compose.yaml --project-directory . --profile end_to_end up ``` -------------------------------- ### lrc20-cli Configuration Example Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Example TOML configuration file for lrc20-cli, specifying private key, storage path, Bitcoin provider details (RPC or Esplora), LRC20 RPC URL, and fee rate strategy. ```toml # config.toml private_key = "cMzCipjMyeNdnPmG6FzB1GAL7ziTBPQ2TJ4EPWZWPdeGgbLTCAEE" storage = "path/to/storage" [bitcoin_provider] type = "bitcoin_rpc" url = "http://127.0.0.1:18443" # bitcoin node RPC url network = "regtest" auth = { username = "admin1", password = "123" } # Start syncing the blockchain history from the certain timestamp start_time = 0 # Or if you want to use Esplora: # [bitcoint-provider] # type = "esplora" # url = "http://127.0.0.1:3000" # network = "regtest" # # stop gap - It is a setting that determines when to stop fetching transactions for a set of # # addresses by indicating a gap of unused addresses. For example, if set to 20, the syncing # # mechanism would stop if it encounters 20 consecutive unused addresses. # stop_gap = 20 [lrc20_rpc] url = "http://127.0.0.1:18333" # The fee rate strategy. Possible values: # - { type = "estimate", target_blocks: 2 } The fee rate is fetched from Bitcoin RPC. If an error # occurs, the tx building process is interrupted. # - { type = "manual", fee_rate = 1.0 } Default fee rate is used. # - { type = "try_estimate", fee_rate = 1.0, target_blocks: 2 } The fee rate is fetched # automatically from Bitcoin RPC. If an error occurs, the default fee rate is used. # NOTE: fee_rate is measured in sat/vb. # https://developer.bitcoin.org/reference/rpc/estimatesmartfee.html [fee_rate_strategy] type = "manual" fee_rate = 1.2 ``` -------------------------------- ### Install LRC20 SDK Bindings Source: https://github.com/buildonspark/btkn/blob/main/python-sdk/README.md Commands to build and install the LRC20 SDK Python bindings using maturin. This involves building the Rust crate and then installing the generated wheel file. ```sh maturin build -m ../crates/bindings-kit/Cargo.toml ``` ```sh pip3 install target/wheels/lrcdk-0.4.3-cp38-abi3-macosx_11_0_arm64.whl ``` -------------------------------- ### Install lrc20-cli Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Installs the lrc20-cli tool using cargo, with an optional 'bulletproof' feature. ```sh git clone git@github.com:lightsparkdev/lrc20.git cargo install --path ./apps/cli --features bulletproof ``` -------------------------------- ### e2e-test Configuration Example Source: https://github.com/buildonspark/btkn/blob/main/apps/e2e-test/README.md A TOML configuration file example for the e2e-test. It specifies parameters for test duration, node setup (LRC20, Bitcoin, Esplora), account generation and funding, transaction checking thresholds, mining intervals, and report file paths. ```toml duration = { secs = 500, nanos = 0 } [nodes] # List of LRC20 nodes that will be randomly distributed among the accounts. # *At least one required. lrc20 = ["http://127.0.0.1:18333"] # List of Bitcoin nodes that will be randomly distributed among the accounts. # *At least one required. bitcoin = [ { url = "http://127.0.0.1:18443", auth = { username = "admin1", password = "123" } }, ] # Esplora url. # If not specified, `accounts.threshold` must be set to 1.0. esplora = ["http://127.0.0.1:30000"] [accounts] # Number of account to generate. number = 5 # Percent of accounts connected to Bitcoin nodes. Other nodes are connected to Esplora. # Accepts values in range (0;1]. # NOTE: Esplora feature is experimental, setting threshold to 1.0 disables it, i.e. all the accounts will be connected to Bitcoin RPC. threshold = 1.0 # Defines how often should the faucet fund the account. funding_interval = 60 [checker] # Defines the threshold needed to initiate a tx check (number of accounts) # For example, if threshold is 20, the tx check will start when there are at least 20 transactions broadcasted. threshold = 20 # Experimental: will count the expected balances and compare it to the actual balances in the end of the test. # The balances often don't match because of the bad synchronization. check_balances_matching = false [miner] interval = { secs = 1, nanos = 0 } [report] result_path = ".result.dev.txt" error_log_file = ".logs.dev.log" ``` -------------------------------- ### Generated Key Pair Output Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Example output from the 'generate keypair' command, showing the generated private key and corresponding Bitcoin addresses. ```text Private key: cUK2ZdLQWWpKeFcrrD7BBjiUsEns9M3MFBTkmLTXyzs66TQN72eX P2TR address: bcrt1phynjv46lc4vsgdyu8qzna4rkx0m6d2s48cjmx8mtcqkey5r23t2swjhv5n P2WPKH address: bcrt1qplal8wyn20chw4jfdamkk5vnfkpwdm3vyd46ew ``` -------------------------------- ### lrc20-node Configuration Example 2 Source: https://github.com/buildonspark/btkn/blob/main/apps/node/README.md This TOML configuration file sets up a second LRC20 node. It differs from the first by specifying a different RPC port, an alternative storage path, and connecting to the first node as a bootnode. ```toml # config-2.toml # Network type used in p2p and other crates. # Accepting values: mainnet, bitcoin, testnet, regtest, sigtest, mutiny network = "regtest" [p2p] port = 8002 # if settuping locally, bumping port here max_inbound_connections = 16 # maximum number of inbound connections max_outbound_connections = 8 # maximum number of outbound connections bootnodes = ["127.0.0.1:8001"] # address of first node [rpc] address = "127.0.0.1:18334" # bumping port here also [storage] path = "./.lrc20d/node-2" # another path to directory with stored txs. [bnode] url = "127.0.0.1:18443" auth = { username = "admin1", password = "123" } ``` -------------------------------- ### lrc20-node Configuration Example 1 Source: https://github.com/buildonspark/btkn/blob/main/apps/node/README.md This TOML configuration file sets up the first LRC20 node. It specifies network settings, peer-to-peer connections, RPC API details, storage parameters, Bitcoin node connection, logging level, indexer behavior, and controller/graph builder settings. ```toml # config-1.toml # Network type used in p2p and other crates. # Accepting values: mainnet, bitcoin, testnet, regtest, sigtest, mutiny network = "regtest" [p2p] address = "0.0.0.0:8002" # address on which node will listen p2p connections max_inbound_connections = 16 # maximum number of inbound connections max_outbound_connections = 8 # maximum number of outbound connections bootnodes = [] # list of ip addresses of nodes to connect [rpc] address = "127.0.0.1:18337" # address on which RPC API will be served. max_items_per_request = 1 # items limitation in the list requests max_request_size_kb = 20480 # Optional: max size of request in kilobytes (default: 20480, which is 20 megabytes) [storage] create_if_missing = true # Create database if missing with all missing directories in path tx_per_page = 100 # Number of transactions per one page return by `getlistrawlrc20transactions` flush_period = 100 # responds for the saving data period (in sececonds) database_url = "postgresql://postgres:postgres@postgres1:5432/lrc20d" # postgresql database url [bnode] url = "http://127.0.0.1:18443" # url to bitcoin node auth = { username = "admin1", password = "123" } # bitcoin node auth [logger] level = "INFO" # level logging, accepting values: TRACE, DEBUG, INFO, WARN, ERROR [indexer] # blockhash from which the indexer indexes blocks starting_block = "000000000000000000027e245190ea0b27c4eb344618816fbdd8b5eec8e234d3" polling_period = { secs = 5, nanos = 0 } # interval between indexer runs # acceptable amount of time for the Bitcoin node to not return new blocks liveness_period = { secs = 3600, nanos = 0 } # max time after each transaction should be discarded from pool max_confirmation_time = { secs = 86400, nanos = 0 } blockloader = { workers_number = 10, # number of workers which load blocks buffer_size = 50, # Number of blocks that will be fetched by the block loader in each iteration worker_time_sleep = 3 # Sleep the worker for seconds when the worker exceeds the rate limit } [controller] max_inv_size = 100 # max number of txs in inv message inv_sharing_interval = 10 # interval between inv messages [graph_builder] cleanup_period = { secs = 3600, nanos = 0 } # time after which GraphBuilder will cleanup outdated transactions tx_outdated_duration = { secs = 86400, nanos = 0 } # max time after which a transaction is assumed as outdated ``` -------------------------------- ### Run Integration Tests Source: https://github.com/buildonspark/btkn/blob/main/tests/README.md Executes integration tests for the system using Cargo. Ensure you have Rust and Cargo installed. ```rust cargo test ``` -------------------------------- ### Build LRC20 Transfer Transaction Source: https://github.com/buildonspark/btkn/blob/main/crates/dev-kit/README.md Demonstrates how to build an LRC20 transfer transaction using the MemoryWallet from the dev-kit. It covers setting up Bitcoin and LRC20 node configurations, initializing a wallet, syncing it, and adding recipients with token and satoshi amounts. The example also shows how to set a manual fee rate and finish the transaction. ```rust use bdk::bitcoin::PrivateKey; use bdk::blockchain::{rpc::Auth, EsploraBlockchain, AnyBlockchain}; use bitcoin::secp256k1::PublicKey; use std::{str::FromStr, sync::Arc}; use lrcdk::{ types::FeeRateStrategy, bitcoin_provider::{BitcoinProviderConfig, BitcoinRpcConfig}, wallet::{MemoryWallet, WalletConfig}, }; use lrc20_receipts::TokenPubkey; async fn build_tx() { // Provide valid Bitcoin node credentials. let bitcoin_auth = Auth::UserPass { username: "admin1".to_string(), password: "123".to_string(), }; // Set up the Bitcoin provider. In this case, Rpc is used. let provider = BitcoinProviderConfig::BitcoinRpc(BitcoinRpcConfig { url: "http://127.0.0.1:18443".to_string(), // Provide a valid, accessible Bitcoin node URL. auth: bitcoin_auth, network: bitcoin::Network::Regtest, // Specify the desired network. start_time: 0, }); let private_key: PrivateKey = "cNMMXcLoM65N5GaULU7ct2vexmQnJ5i5j3Sjc6iNnEF18vY7gzn9" .parse() .expect("Should be valid key"); // Set up the wallet config. let wallet_config = WalletConfig { privkey: private_key, // Replace `private_key` with the actual private key. network: bitcoin::Network::Regtest, // Specify the desired network. bitcoin_provider: provider, // Provide a valid Bitcoin provider. Could be either `BitcoinRpcConfig` or `EsploraConfig`. lrc20_url: "http://127.0.0.1:18333".to_string(), // Provide a valid, accessible LRC20 node URL. }; // Build a wallet from the config. let mut wallet = MemoryWallet::from_config(wallet_config) .expect("Couldn't init the wallet"); // Don't forget to sync the wallet to fetch the UTXOs. wallet.sync(lrcdk::wallet::SyncOptions::default()).await.expect("Wallet should sync"); // Init the blockchain. In this case, Esplora is used. let blockchain: Arc = Arc::new( EsploraBlockchain::new("http://127.0.0.1:30000", 20) .try_into() .expect("Esplora blockchain should be inited"), ); // Build a LRC20 transaction. let tx = { let mut builder = wallet.build_transfer().expect("Tx should build"); // Recipient `PublicKey`. let pubkey = PublicKey::from_str( "03ab5575d69e46968a528cd6fa2a35dd7808fea24a12b41dc65c7502108c75f9a9", ) .unwrap(); // `TokenPubkey` that is to be transferred let token_pubkey = TokenPubkey::from_str("bcrt1p6gvky9eh0q6d3r0k4gs2l4m9qptm7yac09l37adhazqd7y3gcmtsmgpe0u") .unwrap(); // Add a recipient and specify valid `TokenPubkey`, receiver's `PublicKey`, LRC20 token amount and Satoshis amount. builder .add_recipient(token_pubkey, &pubkey, 5000, 1000) .set_fee_rate_strategy(FeeRateStrategy::Manual { fee_rate: 2.0 }); // Finish the transaction. builder .finish(&blockchain) .await .expect("Transaction should finish") }; } ``` -------------------------------- ### Sync Wallet Balance with Electrum Source: https://github.com/buildonspark/btkn/blob/main/crates/bdk/README.md Synchronizes the wallet's balance by connecting to an Electrum server. This example demonstrates setting up an Electrum blockchain client and a wallet, then performing the synchronization. It requires the `bdk` crate and an Electrum server endpoint. ```rust use bdk::Wallet; use bdk::database::MemoryDatabase; use bdk::blockchain::ElectrumBlockchain; use bdk::SyncOptions; use bdk::electrum_client::Client; use bdk::bitcoin::Network; fn main() -> Result<(), bdk::Error> { let blockchain = ElectrumBlockchain::from(Client::new("ssl://electrum.blockstream.info:60002")?); let wallet = Wallet::new( "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"), Network::Testnet, MemoryDatabase::default(), )?; wallet.sync(&blockchain, SyncOptions::default())?; println!("Descriptor balance: {} SAT", wallet.get_balance()?); Ok(()) } ``` -------------------------------- ### Run Integration Tests with Features Source: https://github.com/buildonspark/btkn/blob/main/crates/bdk/README.md Command to run integration tests, specifically enabling the 'test-electrum' feature. This command also outlines how to use other features like 'test-esplora', 'test-rpc', or 'test-rpc-legacy'. It explains the automatic download of binaries and the use of environment variables (`BITCOIND_EXE`, `ELECTRS_EXE`) with `--no-default-features` if binaries are already installed. ```bash cargo test --features test-electrum ``` -------------------------------- ### Decoded LRC20 Transaction Data Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Example of the structured JSON output after decoding LRC20 proofs, showing transaction type and detailed output proofs including receipts and inner keys. ```json { "type": "Issue", "data": { "output_proofs": { "1": { "type": "Sig", "data": { "receipt": { "token_amount": { "amount": 10000 }, "token_pubkey": "ab28d32fe218d3cb53d330e2dd21db5b32dafb9fc5296c42d17dcb1cd63beab2" }, "inner_key": "02bdd2c029e4836fabace9bac3ec9cc9ced9d547e3f3e3b59073e33c9b3508e919" } }, "2": { "type": "EmptyReceipt", "data": { "inner_key": "02ab28d32fe218d3cb53d330e2dd21db5b32dafb9fc5296c42d17dcb1cd63beab2" } } }, "announcement": { "token_pubkey": "ab28d32fe218d3cb53d330e2dd21db5b32dafb9fc5296c42d17dcb1cd63beab2", "amount": 10000 } } } ``` -------------------------------- ### EventBus Usage Example Source: https://github.com/buildonspark/btkn/blob/main/crates/event-bus/README.md Demonstrates how to create an EventBus, register a custom event type (MyEvent), send an event, and subscribe to receive it. It highlights the dynamic nature of event handling. ```rust use event_bus::{EventBus, BusEvent, Receiver, typeid}; use std::any::TypeId; use event_bus_macros::Event; #[derive(Clone, Event)] struct MyEvent { id: u32, } tokio_test::block_on(async { // Creating event bus. let mut full_event_bus = EventBus::default(); let mut full_event_bus = EventBus::default(); // Registering unbounded channel for MyEvent event. full_event_bus.register::(None); // Extracting channel for MyEvent event. You aren't obligated // to extract channels, so you can use ful_event_bus instead. let mut event_bus = full_event_bus.extract(&typeid![MyEvent], &typeid![MyEvent]).unwrap(); // Sending event to channel. event_bus.send(MyEvent { id: 1 }).await; // Subscribing to channel. let mut receiver: Receiver = event_bus.subscribe(); // Receiving event from subscribed channel. let event = receiver.recv().await.unwrap(); }); ``` -------------------------------- ### Run Fuzz Tests with cargo-afl Source: https://github.com/buildonspark/btkn/blob/main/fuzz/README.md This command initiates fuzz testing using `cargo-afl`. It specifies the input directory (`fuzz/in`), the output directory (`fuzz/out`), and the target binary for fuzzing (`target/debug/fuzz`). Ensure `cargo-afl` is installed. ```sh cargo afl fuzz -i fuzz/in -o fuzz/out target/debug/fuzz ``` -------------------------------- ### Initialize Wallet and Clients Source: https://github.com/buildonspark/btkn/blob/main/python-sdk/README.md Python code to initialize the Esplora client, LRC20 RPC client, and the Wallet. It includes setting up network parameters, fee rates, and database storage. ```python import asyncio import lrcdk from lrc20.esplora import EsploraClient from lrc20.lrc20_client import Lrc20Client from lrc20.wallet import Wallet from lrc20.lrc20_types import Payment from lrc20.db import dbm, in_memory from bitcoinlib.keys import Key ESPLORA_CLI = EsploraClient("http://127.0.0.1:3000") LRC20_CLI = Lrc20Client("http://127.0.0.1:18333", ESPLORA_CLI) NETWORK = 'regtest' # can provide any type, e.g. bitcoin, testnet, signet... FEE_RATE_VB = 2.0 DB_PATH = ".wallet_db.dev" # Needed only if using a persistent storage USD_PRIVKEY = "cVm5SC4zJYMbz8jHpZkTGQXxbwtyhX76dKb8HVKLnmxS6bbpxVjD" USD_PUBKEY = "02a1f1ad0fe384b05504f8233209bad9e396f3f86b591e877dc1f95394306d9b94" USD_XONLY_PUBKEY = USD_PUBKEY[2:] ALICE_PUBKEY = "02b2eb79ee60f4755819f893c747b370096fa04c3b3b1fe7fb7bcdb35551dc3caf" # Initialize storage (in-memory or persistent) # storage = in_memory.InMemoryLrc20Storage() storage = dbm.PersistentLrc20Storage(DB_PATH) wallet = Wallet(LRC20_CLI, Key.from_wif(USD_PRIVKEY), storage, NETWORK) ``` -------------------------------- ### Get TokenPubkey Information Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Retrieves information about an announced TokenPubkey. Requires the token public key. ```sh lrc20-cli --config ./alice.toml token-pubkey info --token-pubkey $USD ``` -------------------------------- ### Running the First lrc20-node Instance Source: https://github.com/buildonspark/btkn/blob/main/apps/node/README.md This shell command executes the lrc20-node application using the previously defined configuration file (config-1.toml). It assumes the `lrc20-node` binary is available in the current path. ```sh cargo run -p lrc20-node -- run --config ./config-1.toml ``` -------------------------------- ### Build lrc20d Docker Container Source: https://github.com/buildonspark/btkn/blob/main/infrastructure/README.md Builds a new version of the lrc20d Docker container without using the cache. This command should be run from the root of the repository. ```sh docker build --no-cache -f ./infrastructure/build/lrc20d-crosscompile.Dockerfile -t lightspark/lrc20d:local-build . ``` -------------------------------- ### ogaki CLI Help Source: https://github.com/buildonspark/btkn/blob/main/apps/ogaki/README.md Displays the main help message for the ogaki CLI, outlining its purpose and available commands. ```sh ogaki --help ``` -------------------------------- ### Regtest Bitcoin Mining Source: https://github.com/buildonspark/btkn/blob/main/infrastructure/README.md Mines a block to a specified address within a Bitcoin node container for regtest interactions. This is necessary to obtain Bitcoin for testing purposes. ```sh bitcoin-cli -regtest generatetoaddress 1
``` -------------------------------- ### Get Transaction Status Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md This command retrieves the status of a specific LRC20 transaction using its transaction ID. A successful retrieval will return the transaction in HEX format, indicating it has been accepted by the node. ```sh lrc20-cli --config ./usd.toml get --txid b51cbc492b1ee31897defc0349aac93b4b13f1fbfb77a07d47e01fcd54f6e607 ``` -------------------------------- ### Alice Key Pair and Configuration Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Details of Alice's key pair, including private key, P2TR address, and P2WPKH address, along with her TOML configuration file. ```toml # alice.toml private_key = "cQb7JarJTBoeu6eLvyDnHYNr6Hz4AuAnELutxcY478ySZy2i29FA" storage = ".users/alice" [bitcoin_provider] type = "bitcoin_rpc" url = "http://127.0.0.1:18443" auth = { username = "admin1", password = "123" } network = "regtest" start_time = 0 [lrc20_rpc] url = "http://127.0.0.1:18333" [fee_rate_strategy] type = "manual" fee_rate = 1.2 ``` -------------------------------- ### Get LRC20 Proofs Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Retrieves LRC20 proofs for a given transaction ID. This command is used to obtain the necessary data for decoding and verifying LRC20 token information within a Bitcoin transaction. ```sh lrc20-cli --config ./usd.toml get --txid b51cbc492b1ee31897defc0349aac93b4b13f1fbfb77a07d47e01fcd54f6e607 --proofs ``` -------------------------------- ### Running the Second lrc20-node Instance Source: https://github.com/buildonspark/btkn/blob/main/apps/node/README.md This shell command executes the lrc20-node application using the second configuration file (config-2.toml). This allows for setting up a multi-node environment. ```sh cargo run -p lrc20-node -- run --config ./config-2.toml ``` -------------------------------- ### Get List of LRC20 Transactions by IDs Source: https://github.com/buildonspark/btkn/blob/main/docs/RPC-API.md Retrieves a list of LRC20 transactions based on provided transaction IDs. If some transactions are missing from the LRC20 node, they will be skipped in the response. ```APIDOC getlistrawlrc20transactions "txids" Parameters: - txids: A list of transaction IDs. Returns: List of LRC20 transactions. Example: curl -X POST \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"getlistrawlrc20transactions","params":[[ "txid1", "txid2" ]]}' \ http://127.0.0.1:18333 # Response { "result": [ # serialized LRC20 transactions in JSON format. ], "error": null, "id": 1 } ``` ```shell # Request curl -X POST \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"getlistrawlrc20transactions","params":[[ "txid1", "txid2" ]]}' \ http://127.0.0.1:18333 # Response { "result": [ # serialized LRC20 transactions in JSON format. ], "error": null, "id": 1 } ``` -------------------------------- ### BitcoinBlockIndexer::init Method Source: https://github.com/buildonspark/btkn/blob/main/crates/indexers/README.md Describes the `init` method of BitcoinBlockIndexer, which is responsible for the initial rapid synchronization of missed history before the main polling loop starts. It internally utilizes the BlockLoader. ```rust // Placeholder for BitcoinBlockIndexer::init method documentation // This method handles the initial rapid block synchronization. // It starts BlockLoader internally to fetch missed history. // Dependencies: BlockLoader, Bitcoin Node JSON RPC API // Input: Range of block heights to synchronize // Output: Indexed blocks ``` -------------------------------- ### Transfer USD Tokens from Alice to Bob Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Initiates a transfer of 1000 USD tokens from Alice to Bob using the lrc20-cli. Requires a configuration file for Alice and the token's public key. ```sh lrc20-cli --config ./alice.toml transfer \ --token_pubkey $USD \ --amount 1000 \ --recipient $BOB ``` -------------------------------- ### Get LRC20 Transaction by ID Source: https://github.com/buildonspark/btkn/blob/main/docs/RPC-API.md Retrieves the current state of an LRC20 transaction using its unique transaction ID. It returns the status and, if attached, the serialized LRC20 transaction data. ```APIDOC getrawlrc20transaction "txid" Parameters: txid: transaction id. Returns: JSON object with the following fields: * `status` - status of the transaction. Possible values are: * `none` - transaction is not found; * `pending` - transaction is in the mempool, but it's in the queue to be checked; * `checked` - transaction is in the mempool and is checked, but not attached; * `attached` - transaction is attached and accepted by the LRC20 node. * `data` - a [LRC20 transaction] serialized in JSON format. Is presented only if `status` is `attached`. ``` ```shell # Request curl -X POST \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"getrawlrc20transaction","params":["9ea621f64b8d64ebe3430e2212caa9b77175825cd3fc0c800ab9e30f03736cec"]}' \ http://127.0.0.1:18333 # Response { "jsonrpc": "2.0", "result": { "status": "none" }, "id": 1 } ``` -------------------------------- ### Bob Key Pair and Configuration Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Details of Bob's key pair, including private key, P2TR address, and P2WPKH address, along with his TOML configuration file. ```toml # bob.toml private_key = "cUrMc62nnFeQuzXb26KPizCJQPp7449fsPsqn5NCHTwahSvqqRkV" storage = ".users/bob" [bitcoin_provider] type = "bitcoin_rpc" url = "http://127.0.0.1:18443" auth = { username = "admin1", password = "123" } network = "regtest" start_time = 0 [lrc20_rpc] url = "http://127.0.0.1:18333" [fee_rate_strategy] type = "manual" fee_rate = 1.2 ``` -------------------------------- ### Transaction Dependency Graph Example Source: https://github.com/buildonspark/btkn/blob/main/crates/tx-attach/README.md Visualizes the dependency graph of LRC20 transactions, showing relationships between attached and newly processed transactions. This diagram helps understand how the GraphBuilder identifies and links transactions based on their history. ```mermaid graph LR; id3(3) ===> id1(1); id3(3) ===> id(2); id4[4] -.-> id3(3); id5[5] -.-> id4[4]; id4[4] ===> id6(6); id4[4] -.-> id7[7]; ``` -------------------------------- ### EUR Issuer Configuration Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Configuration file for the EUR issuer, specifying private key, storage path, Bitcoin RPC details, and fee rate strategy. ```toml # eur.toml private_key = "cUK2ZdLQWWpKeFcrrD7BBjiUsEns9M3MFBTkmLTXyzs66TQN72eX" storage = ".users/eur" [bitcoin_provider] type = "bitcoin_rpc" url = "http://127.0.0.1:18443" auth = { username = "admin1", password = "123" } network = "regtest" start_time = 0 [lrc20_rpc] url = "http://127.0.0.1:18333" [fee_rate_strategy] type = "manual" fee_rate = 1.2 ``` -------------------------------- ### LRC20 Architecture Overview Source: https://github.com/buildonspark/btkn/blob/main/docs/README.md Visual representation of the LRC20 transaction processing flow, illustrating the interaction between P2P, Transaction Checker, Transaction Attacher, Storage, RPC API, and Indexer. ```mermaid flowchart TD P2P --> |1.Received new transaction| TC[Transaction checker] TC --> |2.Isolated check for transaction| TC TC --> |3.Received tx to attach to DAG| TA[Transaction attacher] TA --> |4.Attach transaction to token DAG| TA TA --> |5.Get transaction needed to build DAG| S[Storage] TA --> |6.Request missing locally transaction to build DAG| P2P TA --> |7.When DAG is built, save all txs| S RA[RPC API] --> |8.Request data about transactions for client| S I[Indexer] --> |9.Add data about freeze/unfreeze for UTXOs| S ``` -------------------------------- ### Transaction Dependency Graph After Transfer Processing Source: https://github.com/buildonspark/btkn/blob/main/crates/tx-attach/README.md Depicts the transaction dependency graph after processing a 'Transfer' transaction and its dependencies. This example demonstrates how transactions are added to the 'attached' set (V) when their parents are confirmed, updating the overall graph structure. ```mermaid graph LR; id3(3) ===> id1(1); id3 ===> id(2); id4(4) ==> id3; id5(5) ==> id4; id4 ===> id6(6); id4 ==> id7(7); ``` -------------------------------- ### Issue EUR Token and Check Balances Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Demonstrates issuing a EUR token to an address and then checking the balances. This involves specifying the configuration file, amount, and recipient for the issuance, followed by a balance query. ```sh lrc20-cli --config ./eur.toml issue --amount 10000 --recipient $ALICE bitcoin-cli generatetoaddress 6 $USDW lrc20-cli --config ./alice.toml balances ``` -------------------------------- ### USD Issuer Configuration Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Configuration file for the USD issuer, mirroring the structure of the EUR issuer configuration with its specific private key and storage path. ```toml # usd.toml private_key = "cNMMXcLoM65N5GaULU7ct2vexmQnJ5i5j3Sjc6iNnEF18vY7gzn9" storage = ".users/usd" [bitcoin_provider] type = "bitcoin_rpc" url = "http://127.0.0.1:18443" auth = { username = "admin1", password = "123" } network = "regtest" start_time = 0 [lrc20_rpc] url = "http://127.0.0.1:18333" [fee_rate_strategy] type = "manual" fee_rate = 1.2 ``` -------------------------------- ### Generate New Bitcoin Addresses Source: https://github.com/buildonspark/btkn/blob/main/crates/bdk/README.md Generates a sequence of new Bitcoin addresses from a wallet descriptor. This example shows how to create a wallet instance and then repeatedly call `get_address` to obtain new addresses. It requires the `bdk` crate and a wallet descriptor. ```rust use bdk::{Wallet, database::MemoryDatabase}; use bdk::wallet::AddressIndex::New; use bdk::bitcoin::Network; fn main() -> Result<(), bdk::Error> { let wallet = Wallet::new( "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"), Network::Testnet, MemoryDatabase::default(), )?; println!("Address #0: {}", wallet.get_address(New)?); println!("Address #1: {}", wallet.get_address(New)?); println!("Address #2: {}", wallet.get_address(New)?); Ok(()) } ``` -------------------------------- ### BitcoinBlockIndexer Initialization and Execution Flow Source: https://github.com/buildonspark/btkn/blob/main/crates/indexers/README.md Illustrates the overall data flow within the LRC20 Node, showing how the BitcoinNode interacts with the BitcoinBlockIndexer and its sub-indexers (ConfirmationIndexer, FreezesIndexer) to process blocks and confirmed transactions. ```mermaid flowchart LR btcd(BitcoinNode) -->|blocks| indx[BitcoinBlockIndexer] subgraph LRC20 Node subgraph BitcoinBlockIndexer indx -->|blocks| conf[[ConfirmationIndexer]] indx -->|blocks| freeze[[FreezesIndexer]] end conf -->|confirmed txs| cont[Controller] freeze -->|found freezes| cont end ``` -------------------------------- ### Funding Issuers with Bitcoin Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Commands to generate Bitcoin to the USD and EUR issuer addresses using `bitcoin-cli`. ```sh bitcoin-cli generatetoaddress 101 $USDW bitcoin-cli generatetoaddress 101 $EURW ``` -------------------------------- ### Build TokenPubkey Announcement Source: https://github.com/buildonspark/btkn/blob/main/python-sdk/README.md Python code to create a token_pubkey announcement. This includes details about the token such as its name, symbol, decimals, max supply, and whether its outputs can be frozen. ```python tx = await wallet.token_pubkey_announcement(USD_XONLY_PUBKEY, "Test", "TST", 10, 100000, False) ``` -------------------------------- ### ogaki CLI Commands Source: https://github.com/buildonspark/btkn/blob/main/apps/ogaki/README.md Lists the available commands for the ogaki CLI, including update, check-updates, and run-with-auto-update. ```sh Usage: ogaki Commands: update Check for lrc20d updates and install them check-updates Check for lrc20d updates run-with-auto-update Run lrc20d, automatically checking for updates and installing them help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### LRC20 Transaction Flow Sequence Diagram Source: https://github.com/buildonspark/btkn/blob/main/docs/README.md This diagram illustrates the step-by-step process of handling an LRC20 transaction, from its reception through various internal components until it is confirmed and attached to the token DAG. It shows interactions between External Sources, Controller, Tx Confirmator, Tx Checker, GraphBuilder, and Storage. ```mermaid sequenceDiagram participant External Sources participant Controller participant Tx Confirmator participant Tx Checker participant GraphBuilder participant Storage External Sources->>Controller: - Recieve new txs via P2P/RPC
- Recieve new announcements from the indexer Controller->>Storage: Add txs to the mempool with the "initialized" status Controller->>Tx Checker: Isolated check for the txs Tx Checker->>Controller: Notify about checked and invalid txs Controller->>Storage: Change the txs status in the mempool to "waiting-mined" Controller->>Tx Confirmator: Send the txs for confirmation Tx Confirmator->>Tx Confirmator: Wait for the first confirmation (1 block) Tx Confirmator->>Controller: Send mined txs to broadcast via P2P Controller->>Storage: Change the txs status in the mempool to "mined" Controller->>External Sources: Broadcast mined txs via P2P Tx Confirmator->>Tx Confirmator: Wait for the the full confirmation (6 blocks by default) Tx Confirmator->>Controller: Notify about confirmed txs Controller->>Tx Checker: Full check for txs Tx Checker->>Controller: Notify about checked and invalid txs Controller->>Storage: Change the txs status in the mempool to "attaching" Controller->>GraphBuilder: Send checked txs for attaching GraphBuilder->>GraphBuilder: Attach transactions to token DAG GraphBuilder->>Storage: Get txs needed to build the DAG GraphBuilder->>External Sources: Request locally missing txs from the P2P peers GraphBuilder->>Storage: When the DAG is built, save attached txs GraphBuilder->>Controller: Notify about attached txs Controller->>Storage: Remove attached and invalid txs from the mempool ``` -------------------------------- ### Fund Alice with Bitcoins Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Generates 101 blocks to fund the Alice address with Bitcoins. This is a prerequisite for performing transactions. ```sh bitcoin-cli generatetoaddress 101 $ALICEW ``` -------------------------------- ### LRC20 Protocol Overview Source: https://github.com/buildonspark/btkn/blob/main/docs/README.md Provides a high-level explanation of the LRC20 protocol, its purpose, and its relationship to the Bitcoin protocol. ```APIDOC LRC20 Protocol: Description: A protocol for creating tokenized assets on the Bitcoin protocol, analogous to ERC-20 tokens. Functions: Issuance, transfer, freezing, unfreezing, and burning of tokens. Base Layer: Utilizes Bitcoin as the base layer for moving digital assets. Node Software: LRC20d allows any Bitcoin node to become an LRC20 node. Transaction Processing: LRC20 nodes broadcast and process LRC20 transactions similar to Bitcoin nodes. Token Identification: Token type identified by the issuer's issuing key. Transferability: Users can transfer LRC20coin among themselves without issuer intervention. Open Nature: Anyone can start an LRC20 node by running the LRC20d software. Compliance Features: - Freezing: Issuers can freeze assets for regulatory, legal, or compliance reasons. - Unfreezing: Issuers can unfreeze assets. Network Interaction: Freeze instructions are broadcast to the Bitcoin network; LRC20 nodes block transactions involving specified assets. ``` -------------------------------- ### Run Unit Tests Source: https://github.com/buildonspark/btkn/blob/main/crates/bdk/README.md Command to execute all unit tests defined within the Rust project. ```bash cargo test ``` -------------------------------- ### TokenPubkey Announcement Source: https://github.com/buildonspark/btkn/blob/main/apps/cli/README.md Announces a new token to the network by creating a transaction with specific token information. Requires token name, symbol, and decimal places. Token public key is taken from config if not specified. ```sh lrc20-cli --config ./usd.toml token-pubkey announcement --name "Some name" --symbol SMN --decimal 2 ```