$ show FuelLabs/fuels-rs
The FuelLabs/fuels-rs repository is a Rust SDK for the Fuel blockchain, providing tools for compiling, deploying, and testing Sway contracts. It enables developers to interact with the Fuel blockchain through a provider abstraction, manage wallets and accounts, generate type-safe Rust bindings from Sway contracts via the `abigen!` macro, and build and send transactions using a fluent transaction builder pattern. The SDK follows a modular workspace structure with separate crates for accounts, core types, code generation, macros, and high-level program interactions. Key features include configurable constants, blob-based contract deployment for large contracts, and a testing macro (`setup_program_test!`) that reduces boilerplate in end-to-end tests. The architecture is modular, with clear separation of concerns: `fuels-accounts` for wallet management, `fuels-core` for core types and transaction building, `fuels-code-gen` for ABI binding generation, `fuels-macros` for procedural macros, and `fuels-programs` for high-level contract interaction APIs. The SDK relies on external dependencies such as the Fuel blockchain node (fuel-core) and the Sway compiler (forc) for contract compilation. Primary data flows involve generating bindings from ABI JSON, constructing transactions with customizable policies and inputs/outputs, deploying contracts (regular or via blob loader for large contracts), and interacting with deployed contracts through generated bindings. The SDK emphasizes type safety and developer experience, leveraging Rust's procedural macros and trait system to reduce boilerplate and prevent common errors.
The LLM identified 3 files worth highlighting for reuse:
The fuels-code-gen crate provides a library and procedural macros (abigen!) to generate type-safe Rust bindings from Sway contract ABI JSON. It handles complex type resolution (enums, structs, arrays, tuples, generics) and is isolated enough to be adapted for other ABI formats.
This file provides a fluent interface for constructing Fuel transactions (script, create, upload, upgrade) with customizable policies (maturity, expiration, fee, etc.), inputs, outputs, and signers. The pattern is isolated and demonstrates skill in designing a safe and flexible transaction builder.
The setup_program_test! macro reduces boilerplate in tests by setting up wallets, a provider, and deploying contracts. It demonstrates skill in managing asynchronous resources and could be adapted for other blockchain testing frameworks.