How dedotdev/dedot works
Main components
• Core Client & API: The “packages/api” and “packages/dedot” modules serve as the central interface for interacting with blockchain networks. They handle JSON-RPC calls, state queries, runtime API calls, subscription events (block chain head, transactions) and provide the main client classes (e.g., DedotClient, Substrate client interfaces).
• Providers: Located in “packages/providers”, these modules implement the actual transport layers (such as WsProvider for WebSocket-based connections and the Smoldot provider for light client functionality). They abstract away connection details and error handling.
• Codecs & Types: “packages/codecs” and “packages/types” are responsible for decoding/encoding scale-codec data coming from a Substrate chain. They represent extrinsic, metadata, and other low-level binary formats in a type-safe way.
• Code Generation: “packages/codegen” (including the “typink” submodule) automatically produces strongly-typed definitions (like chain types, contract types, runtime API definitions) by processing on-chain metadata. This allows Dedot to provide precise types and API suggestions.
• Contracts: “packages/contracts” supplies a full-featured, type-safe framework for interacting with ink! smart contracts. It includes executors to dispatch contract calls and deployers to handle contract instantiation.
• Runtime Specs & Chaintypes: “packages/runtime-specs” and “packages/chaintypes” provide runtime-specific constants, errors, events, and API details that are unique to each blockchain network.
• CLI: “packages/cli” gives command-line interfaces for interacting with Dedot (for example, executing commands for contract metadata processing or chain type generation).
• Utilities: “packages/utils” offers shared helper functions (hashing, formatting, address manipulation, queueing, etc.) that support many of the above layers.
Component Interactions and Data Flows
• When a user calls an API method (e.g., querying an account balance, subscribing to new block events), the Dedot client forwards the request to the appropriate Provider, which handles the network communication.
• If the data involves runtime calls or contract execution, the Contracts and Runtime-Specs modules participate in constructing call parameters and interpreting responses.
• The Codegen package sits in the development tools layer. It reads on-chain metadata and writes out strongly typed definitions that are then consumed by the API and Contracts packages.
• The CLI is a separate external interface that primarily calls into Dedot’s libraries (or related functions) for various administrative and utility operations.
Architectural Patterns and Design Principles
• Modular/Monorepo Architecture: The separation into packages (API, CLI, Codecs, etc.) allows independent evolution of each module while maintaining a coherent overall system through Lerna (as indicated by lerna.json).
• Layered Abstraction: There is a clear separation between low-level functionalities (e.g., data encoding/decoding, direct JSON-RPC calls via Providers) and higher-level abstractions (e.g., DedotClient, typed Contract APIs). This keeps the system both flexible (allowing custom providers) and safe (with strong TypeScript types).
• Tree-Shakable & Lightweight: The emphasis on “small bundle size” and removing heavy dependencies is also depicted by separating concerns and only including what a project really needs.
Putting It All Together
• Around it, connect the “Providers” to represent connectivity mechanisms.
• “CLI”, “Code Generation”, “Storage”, and “Utilities” as peripheral components that support development, testing, and enhanced functionality.