### Install Oyl SDK and Dependencies Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Clones the Oyl SDK repository from GitHub, navigates into the project directory, and installs all required dependencies using Yarn. ```sh $ git clone https://github.com/oyl-wallet/oyl-sdk.git $ cd oyl-sdk $ yarn install ``` -------------------------------- ### Install OYL SDK CLI Globally Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Illustrates how to install the OYL SDK's command-line interface (CLI) tool globally using either NPM or Yarn. A global installation allows the `oyl` or `oyl-cli` commands to be executed directly from any directory. ```bash npm install -g @oyl/sdk ``` ```bash yarn global add @oyl/sdk ``` -------------------------------- ### Clone and Install Oyl SDK Dependencies Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Instructions to clone the Oyl SDK repository, install its dependencies using Yarn, build the project, and optionally link it for local development. ```Bash git clone https://github.com/oyl-wallet/oyl-sdk.git cd oyl-sdk ``` ```Bash yarn install ``` ```Bash yarn build ``` ```Bash yarn link ``` -------------------------------- ### Configure Oyl SDK Environment Variables Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Example .env file configuration for the Oyl SDK, specifying network, API URL, project ID, and optional fee rate. ```Shell # Network configuration NETWORK=mainnet # Options: mainnet, testnet, regtest API_URL=https://api.example.com PROJECT_ID=your-project-id # Optional configurations FEE_RATE=5 # Default fee rate in sat/vB ``` -------------------------------- ### Install OYL SDK Package Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Provides commands to install the OYL SDK as a local project dependency using either NPM or Yarn. This is the standard method for integrating the SDK into a JavaScript/TypeScript project. ```bash npm install @oyl/sdk ``` ```bash yarn add @oyl/sdk ``` -------------------------------- ### Install Oyl CLI Globally Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Installs the 'oyl' command-line interface tool globally on your system, allowing you to invoke it directly without the 'yarn' prefix. ```sh $ yarn global add oyl ``` -------------------------------- ### Programmatic Usage: Initializing Provider and Sending Bitcoin Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/projectbrief.md Demonstrates how to initialize the Oyl SDK provider, create an account from a mnemonic, and send Bitcoin programmatically using TypeScript. This example showcases the Provider, Account, and btc modules for core SDK operations. ```TypeScript import { Account, Provider, btc } from '@oyl/sdk'; // Initialize provider const provider = new Provider({ url: 'https://api.example.com', projectId: 'your-project-id', network: bitcoin.networks.bitcoin, networkType: 'mainnet' }); // Create account from mnemonic const account = Account.fromMnemonic({ mnemonic: 'your mnemonic phrase here', network: bitcoin.networks.bitcoin }); // Send Bitcoin const result = await btc.createPsbt({ utxos: accountUtxos, toAddress: 'recipient-address', amount: 10000, // in satoshis feeRate: 5, account, provider }); ``` -------------------------------- ### Publish Oyl SDK to NPM Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Publishes the Oyl SDK package to the npm registry, making it publicly available for others to install and use. ```sh $ npm publish --access public ``` -------------------------------- ### Singleton Pattern: Provider Class Instance Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md An example illustrating the Singleton Pattern as applied to the Provider class in the Oyl SDK. This pattern ensures that there is only a single instance of network connection resources throughout the application, maintaining consistent network settings. ```TypeScript export class Provider { public sandshrew: SandshrewBitcoinClient public esplora: EsploraRpc public ord: OrdRpc public api: any public alkanes: AlkanesRpc // ... } ``` -------------------------------- ### Factory Pattern: Account Creation from Mnemonic Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md An example demonstrating the Factory Pattern in the Oyl SDK, specifically for creating an Account object from a mnemonic. This pattern ensures consistent initialization of complex objects. ```TypeScript export const mnemonicToAccount = ({ mnemonic = generateMnemonic(), opts, }: { mnemonic?: string opts?: MnemonicToAccountOptions }): Account => { // Implementation that creates and returns an Account object } ``` -------------------------------- ### Oyl SDK Project File Structure Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/projectbrief.md An overview of the Oyl SDK's directory layout, illustrating the organization of source code, compiled output, binaries, and configuration files within the project. ```Text oyl-sdk/ ├── bin/ # Binary executables ├── lib/ # Compiled JavaScript output ├── src/ # TypeScript source code │ ├── account/ # Account management │ ├── alkanes/ # Alkanes smart contract functionality │ ├── brc20/ # BRC-20 token support │ ├── btc/ # Core Bitcoin operations │ ├── cli/ # Command-line interface │ ├── collectible/ # NFT-like asset handling │ ├── errors/ # Error definitions │ ├── network/ # Network configurations │ ├── provider/ # Provider abstraction │ ├── rpclient/ # RPC client implementations │ ├── rune/ # Runes protocol support │ ├── shared/ # Shared utilities │ ├── signer/ # Transaction signing │ ├── utxo/ # UTXO management │ └── index.ts # Main entry point ├── package.json # Package configuration ├── tsconfig.json # TypeScript configuration ├── jest.config.ts # Jest testing configuration └── README.md # Project documentation ``` -------------------------------- ### Oyl SDK Development Workflow Commands Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Common commands for building, testing, running in development mode, and formatting code within the Oyl SDK project. ```Bash yarn build ``` ```Bash yarn dev ``` ```Bash yarn test ``` ```Bash yarn oyl ``` ```Bash make reset ``` ```Bash yarn prettier ``` -------------------------------- ### CLI Usage: Account Management and Bitcoin Transactions Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/projectbrief.md Illustrates common command-line operations with the Oyl SDK CLI, including generating a new mnemonic, deriving account information from an existing mnemonic, and initiating Bitcoin transactions. ```Bash # Generate a new mnemonic oyl account generateMnemonic # Get account information from mnemonic oyl account mnemonicToAccount -m "your mnemonic phrase" # Send Bitcoin oyl btc send -a "recipient-address" -v 10000 -f 5 ``` -------------------------------- ### Oyl SDK Module Organization Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md This snippet illustrates the directory structure and module organization of the Oyl SDK, showcasing how different functionalities are grouped into distinct domains for better maintainability and separation of concerns. ```Plaintext src/ ├── account/ # Account management and wallet operations ├── alkanes/ # Alkanes smart contract functionality ├── amm/ # Automated Market Maker functionality ├── brc20/ # BRC-20 token operations ├── btc/ # Core Bitcoin operations ├── cli/ # Command-line interface ├── collectible/ # NFT-like asset handling ├── errors/ # Error definitions and handling ├── network/ # Network configurations ├── provider/ # Provider abstraction for network interaction ├── psbt/ # PSBT (Partially Signed Bitcoin Transaction) handling ├── rpclient/ # RPC client implementations ├── rune/ # Runes protocol support ├── shared/ # Shared utilities and interfaces ├── signer/ # Transaction signing └── utxo/ # UTXO management ``` -------------------------------- ### Constructing Bitcoin PSBTs with Builder Pattern in TypeScript Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md The PSBT Builder facilitates incremental construction of Partially Signed Bitcoin Transactions. It allows adding inputs, outputs, and other metadata step by step, ensuring a flexible and robust transaction building process. ```typescript export const psbtBuilder = async ({ inputs, outputs, feeRate, // ...other parameters }) => { const psbt = new bitcoin.Psbt({ network }) // Add inputs for (const input of inputs) { psbt.addInput(/* ... */) } // Add outputs for (const output of outputs) { psbt.addOutput(/* ... */) } // Additional configuration return psbt } ``` -------------------------------- ### Run Oyl SDK Test Suite Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Executes the automated test suite for the Oyl SDK to ensure all functionalities are working as expected. ```sh $ yarn test ``` -------------------------------- ### Link Oyl CLI for Local Development Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Links the Oyl SDK package locally, enabling real-time updates to the CLI as you make changes to the source code. ```sh $ yarn link ``` -------------------------------- ### Oyl SDK Internal Module Integration Points Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md Internal modules within the Oyl SDK integrate through well-defined interfaces and shared types. Key integration points include Account with Signer, UTXO with BTC, BTC with Provider, and Protocol Modules with Core Modules, ensuring cohesive operation. ```APIDOC 1. Account → Signer: Account module provides key material to Signer module 2. UTXO → BTC: UTXO module provides input selection to BTC module 3. BTC → Provider: BTC module uses Provider for network operations 4. Protocol Modules → Core Modules: Protocol-specific modules use core modules for common operations ``` -------------------------------- ### Compile OYL SDK with TypeScript Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Provides the command-line instruction to compile the OYL SDK's TypeScript source files into JavaScript and type definitions. This step is fundamental to preparing the SDK for distribution and use. ```bash tsc ``` -------------------------------- ### Implementing RPC Client Adapters for Consistent Bitcoin API Access in TypeScript Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md RPC Client Adapters normalize disparate Bitcoin RPC interfaces, such as Esplora and Ord, into a consistent internal interface. This pattern ensures that different external APIs can work together seamlessly within the Oyl SDK. ```typescript // Each RPC client adapts a specific API to a consistent interface export class EsploraRpc { // Methods that adapt Esplora API to our internal interface } export class OrdRpc { // Methods that adapt Ord API to our internal interface } ``` -------------------------------- ### Development Dependencies for OYL SDK Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Outlines the packages necessary for developing and testing the OYL SDK, such as TypeScript, Jest, and various type definitions. These are not included in the final production build but are crucial for the development workflow. ```json { "@types/jest": "29.5.14", "@types/node": "20.17.12", "@types/tiny-async-pool": "2.0.3", "@types/yargs": "17.0.33", "cross-env": "^7.0.3", "jest": "29.7.0", "npm-run-all": "^4.1.5", "ts-jest": "29.2.5", "typescript": "4.9.5", "yarn-audit-fix": "10.1.1" } ``` -------------------------------- ### Oyl SDK Module Dependency Hierarchy Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md This diagram illustrates the hierarchical dependencies between core modules, protocol modules, account/signer modules, and the provider module within the Oyl SDK. It shows how higher-level components rely on lower-level ones for fundamental operations. ```APIDOC CLI/API Interface │ ├── Protocol Modules (BRC20, Rune, Alkanes, AMM) │ │ │ ├── Core Modules (BTC, UTXO) │ │ │ └── Account/Signer Modules │ └── Provider Module │ └── RPC Clients ``` -------------------------------- ### Core Dependencies for OYL SDK Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Lists the essential third-party libraries and their pinned versions required for the OYL SDK's core functionality. These dependencies include cryptographic libraries, protocol-specific tools, and utility packages. ```json { "@bitcoinerlab/secp256k1": "1.0.2", "@magiceden-oss/runestone-lib": "1.0.2", "@sadoprotocol/ordit-sdk": "3.0.0", "@scure/btc-signer": "1.5.0", "alkanes": "git+https://github.com/kungfuflex/alkanes.git", "bignumber.js": "9.1.2", "bip32": "4.0.0", "bip322-js": "2.0.0", "bip39": "3.1.0", "bitcoin-address-validation": "2.2.3", "bitcoinjs-lib": "6.1.7", "cbor-x": "1.6.0", "change-case": "4.1.2", "commander": "12.1.0", "crypto": "1.0.1", "dotenv": "16.3.1", "ecpair": "2.1.0", "fs-extra": "11.2.0", "nice-repl": "0.1.2", "node-fetch": "2.7.0" } ``` -------------------------------- ### Rebuild Oyl SDK CLI Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Performs a fresh build of the 'lib' directory, which is essential for the CLI to use the latest compiled TypeScript files. ```sh $ make reset ``` -------------------------------- ### Oyl SDK Transaction Data Flow Process Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md The Oyl SDK follows a consistent seven-step data flow for transaction operations: Input Collection, Transaction Construction, Fee Calculation, Transaction Finalization, Signing, Broadcasting, and Confirmation. This pattern ensures predictability and consistency across various modules. ```APIDOC 1. Input Collection: Gather necessary inputs (UTXOs, account information, operation parameters) 2. Transaction Construction: Build a transaction template based on the operation 3. Fee Calculation: Calculate appropriate fees based on transaction size and network conditions 4. Transaction Finalization: Finalize the transaction with correct inputs, outputs, and fees 5. Signing: Sign the transaction with appropriate keys 6. Broadcasting: Broadcast the transaction to the network 7. Confirmation: Monitor the transaction for confirmation ``` -------------------------------- ### Oyl SDK External System Integration Points Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md The Oyl SDK integrates with various external Bitcoin-related systems, including Bitcoin nodes via Sandshrew RPC, block explorers via Esplora RPC, Ordinals via Ord RPC, and Alkanes via Alkanes RPC, providing comprehensive functionality. ```APIDOC 1. Bitcoin Node Integration - Via Sandshrew RPC client - Provides access to Bitcoin Core functionality 2. Block Explorer Integration - Via Esplora RPC client - Provides efficient access to blockchain data 3. Ordinals Integration - Via Ord RPC client - Enables interaction with Ordinals protocol 4. Alkanes Integration - Via Alkanes RPC client - Provides smart contract functionality on Bitcoin ``` -------------------------------- ### Defining Spend Strategy Interface for UTXO Selection in TypeScript Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md The `SpendStrategy` interface defines a contract for different UTXO selection and change address management approaches. It allows the SDK to dynamically select algorithms at runtime based on specific requirements, enhancing flexibility in transaction spending. ```typescript export interface SpendStrategy { addressOrder: AddressKey[] utxoSortGreatestToLeast: boolean changeAddress: AddressKey } ``` -------------------------------- ### Invoke Oyl CLI Locally Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/README.md Runs the Oyl CLI using the local script provided, ensuring the program is isolated to the current environment and uses the project's specific dependencies. ```sh $ yarn oyl --help ``` -------------------------------- ### TypeScript Configuration for OYL SDK Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/techContext.md Details the `tsconfig.json` settings used for compiling the OYL SDK, specifying target ECMAScript version, module system, output directory, and strictness rules. This configuration ensures proper compilation and type checking for the SDK. ```json { "compilerOptions": { "target": "es2020", "module": "commonjs", "declaration": true, "outDir": "./lib", "strict": true, "esModuleInterop": true, "resolveJsonModule": true }, "include": [ "src" ], "exclude": [ "node_modules", "**/__tests__/*" ] } ``` -------------------------------- ### TypeScript Custom Error Class for Oyl SDK Transactions Source: https://github.com/oyl-wallet/oyl-sdk/blob/main/memory-bank/systemPatterns.md This TypeScript code defines `OylTransactionError`, a custom error class extending `Error`. It's used within the Oyl SDK to provide specific context for transaction-related failures, capturing the original error message and stack trace for improved debugging and error categorization. ```TypeScript export class OylTransactionError extends Error { constructor(error: any) { super(error.message || 'Transaction Error') this.name = 'OylTransactionError' this.stack = error.stack } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.