### Install cargo-generate Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Installs the `cargo-generate` tool, which is used to scaffold new projects from templates. This is a prerequisite for generating Rust integration tests for Sway projects. ```shell cargo install cargo-generate ``` -------------------------------- ### FuelConnector Install Metadata Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/wallets/connectors.md.md Provides an example of the required 'install' object within FuelConnector metadata, detailing the action, link, and description for installation. ```typescript install: { action: 'Install', description: 'Install the My Wallet Connector', link: 'https://example.com/install', } ``` -------------------------------- ### FuelConnector Install Metadata Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/wallets/connectors.md.md Provides an example of the required 'install' object within FuelConnector metadata, detailing the action, link, and description for installation. ```typescript install: { action: 'Install', description: 'Install the My Wallet Connector', link: 'https://example.com/install', } ``` -------------------------------- ### Install cargo-generate Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Installs the `cargo-generate` tool, which is used to scaffold new projects from templates. This is a prerequisite for generating Rust integration tests for Sway projects. ```shell cargo install cargo-generate ``` -------------------------------- ### Project Setup Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/cookbook/wallet-sdk-and-react-hooks.md.md Commands to create a new Next.js application using npm, pnpm, or bun. ```sh npm create next-app my-fuel-app ``` ```sh pnpm create next-app my-fuel-app ``` ```sh bun create next-app my-fuel-app ``` -------------------------------- ### Project Setup Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/cookbook/wallet-sdk-and-react-hooks.md.md Commands to create a new Next.js application using npm, pnpm, or bun. ```sh npm create next-app my-fuel-app ``` ```sh pnpm create next-app my-fuel-app ``` ```sh bun create next-app my-fuel-app ``` -------------------------------- ### Create New Sway Project Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Commands to create a new Sway project using `forc`. You can either create a new project with a specified name or initialize a project in an existing directory. ```shell forc new ``` ```shell forc init ``` -------------------------------- ### Project Initialization Confirmation Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/creating-a-fuel-dapp/index.md.md Example output shown after successfully creating a Fuel dApp project, including instructions to navigate the project and start development servers. ```md ◇ What is the name of your project? │ my-fuel-project └ ⚡️ Success! Created a fullstack Fuel dapp at my-fuel-project To get started: - cd into the project directory: cd my-fuel-project - Start a local Fuel dev server: pnpm fuels:dev - Run the frontend: pnpm dev -> TS SDK docs: https://docs.fuel.network/docs/fuels-ts/ -> Sway docs: https://docs.fuel.network/docs/sway/ -> If you have any questions, check the Fuel forum: https://forum.fuel.network/ ``` -------------------------------- ### Create New Sway Project Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Commands to create a new Sway project using `forc`. You can either create a new project with a specified name or initialize a project in an existing directory. ```shell forc new ``` ```shell forc init ``` -------------------------------- ### Import Fuel Rust SDK Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Demonstrates how to import the Fuel Rust SDK into your Rust project. This line makes all necessary components from the SDK available for use. ```rust use fuels::prelude::* ``` -------------------------------- ### Project Initialization Confirmation Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/creating-a-fuel-dapp/index.md.md Example output shown after successfully creating a Fuel dApp project, including instructions to navigate the project and start development servers. ```md ◇ What is the name of your project? │ my-fuel-project └ ⚡️ Success! Created a fullstack Fuel dapp at my-fuel-project To get started: - cd into the project directory: cd my-fuel-project - Start a local Fuel dev server: pnpm fuels:dev - Run the frontend: pnpm dev -> TS SDK docs: https://docs.fuel.network/docs/fuels-ts/ -> Sway docs: https://docs.fuel.network/docs/sway/ -> If you have any questions, check the Fuel forum: https://forum.fuel.network/ ``` -------------------------------- ### Import Fuel Rust SDK Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Demonstrates how to import the Fuel Rust SDK into your Rust project. This line makes all necessary components from the SDK available for use. ```rust use fuels::prelude::* ``` -------------------------------- ### Install Dependencies Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/cookbook/wallet-sdk-and-react-hooks.md.md Commands to install the Fuel Wallet React SDK, Fuel TypeScript SDK, and React Query using npm, pnpm, or bun. ```sh npm install fuels @fuels/connectors @fuels/react @tanstack/react-query ``` ```sh pnpm add fuels @fuels/connectors @fuels/react @tanstack/react-query ``` ```sh bun add fuels @fuels/connectors @fuels/react @tanstack/react-query ``` -------------------------------- ### Add Sway Library Dependency Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway-libs/docs/book/src/getting_started/index.md Demonstrates how to add a Sway library as a dependency in the `Forc.toml` file and using the `forc add` command to include a specific library version. ```sway [dependencies] example = "0.0.0" ``` ```bash forc add ownership@0.26.0 ``` -------------------------------- ### Install Dependencies Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/cookbook/wallet-sdk-and-react-hooks.md.md Commands to install the Fuel Wallet React SDK, Fuel TypeScript SDK, and React Query using npm, pnpm, or bun. ```sh npm install fuels @fuels/connectors @fuels/react @tanstack/react-query ``` ```sh pnpm add fuels @fuels/connectors @fuels/react @tanstack/react-query ``` ```sh bun add fuels @fuels/connectors @fuels/react @tanstack/react-query ``` -------------------------------- ### Build and Run All Fuel Integration Tests Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Commands to build and run all integration tests for the Fuel Rust SDK. This involves building all Sway test projects within the `e2e` directory and then executing the tests using `cargo test`. Options for running all targets/features and capturing output are also provided. ```shell forc build --release --path e2e ``` ```shell cargo test ``` ```shell cargo test --all-targets --all-features ``` ```shell cargo test -- --nocapture ``` -------------------------------- ### Install Fuel Toolchain Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/node-operator/docs/src/fuel-ignition/mainnet-node.md Installs the Fuel toolchain, including `forc`, `forc-client`, `forc-fmt`, `forc-lsp`, `forc-wallet`, and `fuel-core`. The installation script downloads and executes the necessary setup for your environment. ```sh curl https://install.fuel.network | sh ``` -------------------------------- ### Build and Run All Fuel Integration Tests Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Commands to build and run all integration tests for the Fuel Rust SDK. This involves building all Sway test projects within the `e2e` directory and then executing the tests using `cargo test`. Options for running all targets/features and capturing output are also provided. ```shell forc build --release --path e2e ``` ```shell cargo test ``` ```shell cargo test --all-targets --all-features ``` ```shell cargo test -- --nocapture ``` -------------------------------- ### Add Sway Library Dependency Source: https://github.com/fuellabs/markdown/blob/main/docs/sway-libs/docs/book/src/getting_started/index.md Demonstrates how to add a Sway library as a dependency in the `Forc.toml` file and using the `forc add` command to include a specific library version. ```sway [dependencies] example = "0.0.0" ``` ```bash forc add ownership@0.26.0 ``` -------------------------------- ### Install Fuel Toolchain Source: https://github.com/fuellabs/markdown/blob/main/docs/node-operator/docs/src/fuel-ignition/mainnet-node.md Installs the Fuel toolchain, including `forc`, `forc-client`, `forc-fmt`, `forc-lsp`, `forc-wallet`, and `fuel-core`. The installation script downloads and executes the necessary setup for your environment. ```sh curl https://install.fuel.network | sh ``` -------------------------------- ### Deploy Multiple Contracts and Call Between Them Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Illustrates deploying multiple contracts, including a library contract and caller contracts, on the same provider. It shows how different instances of the same contract get unique IDs due to salt and how they can interact. ```rust setup_program_test!( Wallets("wallet"), Abigen( Contract( name = "LibContract", project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", project = "e2e/sway/contracts/lib_contract_caller" ), ), Deploy( name = "lib_contract_instance", contract = "LibContract", wallet = "wallet", random_salt = false, ), Deploy( name = "contract_caller_instance", contract = "LibContractCaller", wallet = "wallet", ), Deploy( name = "contract_caller_instance2", contract = "LibContractCaller", wallet = "wallet", ), ); let lib_contract_id = lib_contract_instance.contract_id(); let contract_caller_id = contract_caller_instance.contract_id(); let contract_caller_id2 = contract_caller_instance2.contract_id(); // Because we deploy with salt, we can deploy the same contract multiple times assert_ne!(contract_caller_id, contract_caller_id2); // The first contract can be called because they were deployed on the same provider let response = contract_caller_instance .methods() .increment_from_contract(lib_contract_id, 42) .with_contracts(&[&lib_contract_instance]) .call() .await?; assert_eq!(43, response.value); let response = contract_caller_instance2 .methods() .increment_from_contract(lib_contract_id, 42) .with_contracts(&[&lib_contract_instance]) .call() .await?; assert_eq!(43, response.value); ``` -------------------------------- ### Deploy Multiple Contracts and Call Between Them Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Illustrates deploying multiple contracts, including a library contract and caller contracts, on the same provider. It shows how different instances of the same contract get unique IDs due to salt and how they can interact. ```rust setup_program_test!( Wallets("wallet"), Abigen( Contract( name = "LibContract", project = "e2e/sway/contracts/lib_contract" ), Contract( name = "LibContractCaller", project = "e2e/sway/contracts/lib_contract_caller" ), ), Deploy( name = "lib_contract_instance", contract = "LibContract", wallet = "wallet", random_salt = false, ), Deploy( name = "contract_caller_instance", contract = "LibContractCaller", wallet = "wallet", ), Deploy( name = "contract_caller_instance2", contract = "LibContractCaller", wallet = "wallet", ), ); let lib_contract_id = lib_contract_instance.contract_id(); let contract_caller_id = contract_caller_instance.contract_id(); let contract_caller_id2 = contract_caller_instance2.contract_id(); // Because we deploy with salt, we can deploy the same contract multiple times assert_ne!(contract_caller_id, contract_caller_id2); // The first contract can be called because they were deployed on the same provider let response = contract_caller_instance .methods() .increment_from_contract(lib_contract_id, 42) .with_contracts(&[&lib_contract_instance]) .call() .await?; assert_eq!(43, response.value); let response = contract_caller_instance2 .methods() .increment_from_contract(lib_contract_id, 42) .with_contracts(&[&lib_contract_instance]) .call() .await?; assert_eq!(43, response.value); ``` -------------------------------- ### Build and Run Sway Project Tests Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Commands to build a Sway project and run its tests. `forc build` compiles the Sway code, and `cargo test` executes the Rust integration tests. The `-- --nocapture` flag can be used to see test output. ```shell forc build ``` ```shell cargo test ``` ```shell cargo test -- --nocapture ``` -------------------------------- ### Launch Provider and Get Wallet with Single Method Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/connecting/short-lived.md Illustrates the use of `launch_provider_and_get_wallet` which simplifies the setup of a provider and wallet creation into a single method call. ```rust let wallet = launch_provider_and_get_wallet().await?; ``` -------------------------------- ### Add Fuel Rust SDK Dependency Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Specifies how to add the Fuel Rust SDK as a dependency in your project's `Cargo.toml` file. It also shows the necessary `use` statement for importing the SDK in your Rust code. ```toml fuels = "0.66.0" ``` -------------------------------- ### Forc Migrate Check Output Example Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/migrations-and-disclosures/docs/src/migrations/sway.md An example output from `forc migrate check` showing a warning about unused manifest keys and a detailed explanation of a breaking change related to storage domains, including guidance on backward compatibility. ```APIDOC Compiling mira_amm_contract (/mira-v1-core/contracts/mira_amm_contract) warning: unused manifest key: build-profile.?.release.experimental Migrating Breaking change feature storage_domains Checked [storage_domains] Review explicitly defined slot keys in storage declarations (`in` keywords) Review [storage_domains] Explicitly define storage slot keys if they need to be backward compatible info: [storage_domains] Explicitly define storage slot keys if they need to be backward compatible --> /mira-v1-core/contracts/mira_amm_contract/src/main.sw:65:1 | 63 | 64 | 65 | / storage { 66 | | /// Pools storage ... | 79 | | hook: Option = None, 80 | | } | |_ | = help: If the contract owning this storage is behind a proxy, or for any other reason needs = help: to use previous storage slot keys, those keys must be explicitly assigned to the = help: storage fields by using the `in` keyword. = help: = help: E.g.: = help: storage { = help: field in : u64 = 0, = help: } = help: = help: The previous formula for calculating storage keys was: `sha256("storage.")`. = help: The new formula is: `sha256((0u8, "storage."))`. = help: = help: This migration step will interactively modify the code, based on your input. = help: = help: For a detailed migration guide see: https://github.com/FuelLabs/sway/issues/6701 ____ The following storage fields will have slot keys calculated by using the new formula: - storage.pools - storage.total_pools - storage.total_reserves - storage.lp_total_supply - storage.lp_name - storage.protocol_fees - storage.hook Do you want these fields to have backward compatible storage slot keys, calculated by using the previous formula? If yes, this migration step will insert `in` keywords to all of the above fields, and calculate the storage slot keys by using the previous formula. 1. Yes, assign the backward compatible storage slot keys. 2. No, this contract does not require backwards compatibility. Enter your choice [1..2]: 1 Changing [storage_domains] Explicitly define storage slot keys if they need to be backward compatible Source code successfully changed (7 changes). Finished Project is compatible with the next breaking change version of Sway ``` -------------------------------- ### Launch Provider and Get Wallet with Single Method Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/connecting/short-lived.md Illustrates the use of `launch_provider_and_get_wallet` which simplifies the setup of a provider and wallet creation into a single method call. ```rust let wallet = launch_provider_and_get_wallet().await?; ``` -------------------------------- ### Build and Run Sway Project Tests Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Commands to build a Sway project and run its tests. `forc build` compiles the Sway code, and `cargo test` executes the Rust integration tests. The `-- --nocapture` flag can be used to see test output. ```shell forc build ``` ```shell cargo test ``` ```shell cargo test -- --nocapture ``` -------------------------------- ### Deploy Single Contract Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Demonstrates deploying a single contract instance using a specified wallet and calling its methods. It includes setup for wallets, contract abigen, and deployment. ```rust setup_program_test!( Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", contract = "TestContract", wallet = "wallet" ), ); let response = contract_instance .methods() .initialize_counter(42) .call() .await?; assert_eq!(42, response.value); ``` -------------------------------- ### Add Fuel Rust SDK Dependency Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Specifies how to add the Fuel Rust SDK as a dependency in your project's `Cargo.toml` file. It also shows the necessary `use` statement for importing the SDK in your Rust code. ```toml fuels = "0.66.0" ``` -------------------------------- ### Import Sway Library Function Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway-libs/docs/book/src/getting_started/index.md Shows how to import a specific function from a Sway library into your Sway Smart Contract using the `use` statement. ```sway use ownership::only_owner; ``` -------------------------------- ### Deploy Single Contract Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Demonstrates deploying a single contract instance using a specified wallet and calling its methods. It includes setup for wallets, contract abigen, and deployment. ```rust setup_program_test!( Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", contract = "TestContract", wallet = "wallet" ), ); let response = contract_instance .methods() .initialize_counter(42) .call() .await?; assert_eq!(42, response.value); ``` -------------------------------- ### Forc Migrate Check Output Example Source: https://github.com/fuellabs/markdown/blob/main/docs/migrations-and-disclosures/docs/src/migrations/sway.md An example output from `forc migrate check` showing a warning about unused manifest keys and a detailed explanation of a breaking change related to storage domains, including guidance on backward compatibility. ```APIDOC Compiling mira_amm_contract (/mira-v1-core/contracts/mira_amm_contract) warning: unused manifest key: build-profile.?.release.experimental Migrating Breaking change feature storage_domains Checked [storage_domains] Review explicitly defined slot keys in storage declarations (`in` keywords) Review [storage_domains] Explicitly define storage slot keys if they need to be backward compatible info: [storage_domains] Explicitly define storage slot keys if they need to be backward compatible --> /mira-v1-core/contracts/mira_amm_contract/src/main.sw:65:1 | 63 | 64 | 65 | / storage { 66 | | /// Pools storage ... | 79 | | hook: Option = None, 80 | | } | |_ | = help: If the contract owning this storage is behind a proxy, or for any other reason needs = help: to use previous storage slot keys, those keys must be explicitly assigned to the = help: storage fields by using the `in` keyword. = help: = help: E.g.: = help: storage { = help: field in : u64 = 0, = help: } = help: = help: The previous formula for calculating storage keys was: `sha256("storage.")`. = help: The new formula is: `sha256((0u8, "storage."))`. = help: = help: This migration step will interactively modify the code, based on your input. = help: = help: For a detailed migration guide see: https://github.com/FuelLabs/sway/issues/6701 ____ The following storage fields will have slot keys calculated by using the new formula: - storage.pools - storage.total_pools - storage.total_reserves - storage.lp_total_supply - storage.lp_name - storage.protocol_fees - storage.hook Do you want these fields to have backward compatible storage slot keys, calculated by using the previous formula? If yes, this migration step will insert `in` keywords to all of the above fields, and calculate the storage slot keys by using the previous formula. 1. Yes, assign the backward compatible storage slot keys. 2. No, this contract does not require backwards compatibility. Enter your choice [1..2]: 1 Changing [storage_domains] Explicitly define storage slot keys if they need to be backward compatible Source code successfully changed (7 changes). Finished Project is compatible with the next breaking change version of Sway ``` -------------------------------- ### Vue Script Setup for Testing Guide Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/testing/index.md.md This snippet demonstrates the setup for a Vue.js component that guides users through testing Sway applications. It imports data, extracts a specific variable, and defines a URL for related documentation. ```html ``` -------------------------------- ### Import Sway Library Function Source: https://github.com/fuellabs/markdown/blob/main/docs/sway-libs/docs/book/src/getting_started/index.md Shows how to import a specific function from a Sway library into your Sway Smart Contract using the `use` statement. ```sway use ownership::only_owner; ``` -------------------------------- ### Install Cosmovisor Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/node-operator/docs/src/fuel-sequencer/mainnet-node.md Installs the latest version of Cosmovisor using Go's install command. ```bash go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest ``` -------------------------------- ### Vue Script Setup for Testing Guide Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/testing/index.md.md This snippet demonstrates the setup for a Vue.js component that guides users through testing Sway applications. It imports data, extracts a specific variable, and defines a URL for related documentation. ```html ``` -------------------------------- ### Install and Use forc-install Plugin Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway/docs/book/src/forc/plugins/index.md Demonstrates how to clone the forc-install repository, install it using Cargo, and verify its installation. It also shows how to use the plugin to install a Sway library from GitHub. ```sh git clone https://github.com/darthbenro008/forc-install cd forc-install cargo install --path . ``` ```console $ forc plugins Installed Plugins: forc-install ``` ```console forc install https://github.com/user/sway-library ``` -------------------------------- ### Importing only_owner from Ownership Library (Sway) Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway-libs/docs/book/src/getting_started/index.md Demonstrates a concrete example of how to import a specific function, `only_owner`, from the `ownership` module within the `sway-libs` dependency using the `use` keyword. This import statement is typically placed at the top of a Sway file to make the function accessible. ```sway use sway_libs::ownership::only_owner; ``` -------------------------------- ### Deploy Contract with Custom Wallet Configuration Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Shows how to manually create wallet instances and providers, then use them within the `setup_program_test!` macro for contract deployment. This allows for more control over wallet creation and provider setup. ```rust let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT)); let mut wallets = launch_custom_provider_and_get_wallets(config, None, None).await?; let wallet = wallets.pop().unwrap(); let wallet_2 = wallets.pop().unwrap(); setup_program_test!( Abigen(Contract( name = "TestContract", project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", contract = "TestContract", wallet = "wallet", random_salt = false, ), ); ``` -------------------------------- ### VSCode Sway Plugin Installation Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway/docs/book/src/lsp/installation.md Instructions for installing the Sway language support extension for Visual Studio Code from the marketplace. ```bash Install the Sway extension from the VSCode marketplace. ``` -------------------------------- ### Hexlified B256 Address Example Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/utilities/address-conversion.md.md Shows an example of a hexlified B256 address, another common format. ```typescript const b256Address = '0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6'; ``` -------------------------------- ### Hexlified B256 Address Example Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/utilities/address-conversion.md.md Shows an example of a hexlified B256 address, another common format. ```typescript const b256Address = '0xbebd3baab326f895289ecbd4210cf886ce41952316441ae4cac35f00f0e882a6'; ``` -------------------------------- ### Create a random wallet (two-step) Source: https://github.com/fuellabs/markdown/blob/main/docs/migrations-and-disclosures/docs/src/migrations/rust-sdk.md Demonstrates the two-step process for creating a random wallet, useful when the node is not yet started but an address is needed. ```rust // Create a random private key signer let signer = PrivateKeySigner::random(&mut rng); let coins = setup_single_asset_coins(signer.address(), asset_id, 1, DEFAULT_COIN_AMOUNT); let provider = setup_test_provider(coins.clone(), vec![], None, None).await?; let wallet = Wallet::new(signer, provider); ``` -------------------------------- ### Create a random wallet (two-step) Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/migrations-and-disclosures/docs/src/migrations/rust-sdk.md Demonstrates the two-step process for creating a random wallet, useful when the node is not yet started but an address is needed. ```rust // Create a random private key signer let signer = PrivateKeySigner::random(&mut rng); let coins = setup_single_asset_coins(signer.address(), asset_id, 1, DEFAULT_COIN_AMOUNT); let provider = setup_test_provider(coins.clone(), vec![], None, None).await?; let wallet = Wallet::new(signer, provider); ``` -------------------------------- ### Importing specific function from Sway Libs Ownership (Sway) Source: https://github.com/fuellabs/markdown/blob/main/docs/sway-libs/docs/book/src/getting_started/index.md Provides a concrete example of how to import the `only_owner` function from the `ownership` library within `sway_libs` into a Sway file. This statement makes the `only_owner` function available for use in the current scope. Requires the `ownership` library to be part of `sway_libs` and `sway_libs` to be a dependency. ```Sway use sway_libs::ownership::only_owner; ``` -------------------------------- ### Running Fuel Rust SDK e2e Tests (Shell) Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/getting-started.md Execute the Rust end-to-end tests within the Fuel Rust SDK source code using `cargo test`. Options include running with all targets/features (`--all-targets --all-features`) or capturing test output (`-- --nocapture`). ```Shell cargo test ``` ```Shell cargo test --all-targets --all-features ``` ```Shell cargo test -- --nocapture ``` -------------------------------- ### SDK Interaction: Wallet and Predicate Setup Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/predicates/send-spend-predicate.md This Rust code demonstrates setting up wallets with private keys, initializing a test provider, and creating a predicate instance. It includes steps for transferring assets to the predicate and verifying its balance. ```rust let wallet_signer = PrivateKeySigner::new( "0x862512a2363db2b3a375c0d4bbbd27172180d89f23f2e259bac850ab02619301".parse()?, ); let wallet2_signer = PrivateKeySigner::new( "0x37fa81c84ccd547c30c176b118d5cb892bdb113e8e80141f266519422ef9eefd".parse()?, ); let wallet3_signer = PrivateKeySigner::new( "0x976e5c3fa620092c718d852ca703b6da9e3075b9f2ecb8ed42d9f746bf26aafb".parse()?, ); let receiver_signer = PrivateKeySigner::random(&mut thread_rng()); ``` ```rust let asset_id = AssetId::zeroed(); let num_coins = 32; let amount = 64; let initial_balance = amount * num_coins; let all_coins = [ &wallet_signer, &wallet2_signer, &wallet3_signer, &receiver_signer, ] .iter() .flat_map(|signer| setup_single_asset_coins(signer.address(), asset_id, num_coins, amount)) .collect::>(); let provider = setup_test_provider(all_coins, vec![], None, None).await?; let wallet = Wallet::new(wallet_signer, provider.clone()); let wallet2 = Wallet::new(wallet2_signer, provider.clone()); let wallet3 = Wallet::new(wallet3_signer, provider.clone()); let receiver = Wallet::new(receiver_signer, provider.clone()); ``` ```rust abigen!(Predicate( name = "MyPredicate", abi = "e2e/sway/predicates/signatures/out/release/signatures-abi.json" )); let predicate_data = MyPredicateEncoder::default().encode_data(signatures)?; let code_path = "../../e2e/sway/predicates/signatures/out/release/signatures.bin"; let predicate: Predicate = Predicate::load_from(code_path)? .with_provider(provider) .with_data(predicate_data); ``` ```rust let amount_to_predicate = 500; wallet .transfer( predicate.address(), amount_to_predicate, asset_id, TxPolicies::default(), ) .await?; let predicate_balance = predicate.get_asset_balance(&asset_id).await?; assert_eq!(predicate_balance, amount_to_predicate as u128); ``` ```rust let amount_to_receiver = 300; predicate .transfer( receiver.address(), ``` -------------------------------- ### Converting Bytes32 to &str in Rust Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/types/conversion.md This snippet shows how to get a string slice (`&str`) representation of a `Bytes32`. It uses the `to_string()` method to get a `String` and then `as_str()` to get the slice. Requires a `Bytes32` variable. ```rust let _str_from_bytes32: &str = b256.to_string().as_str(); ``` -------------------------------- ### Deploy Contract with Custom Wallet Configuration Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/testing/the-setup-program-test-macro.md Shows how to manually create wallet instances and providers, then use them within the `setup_program_test!` macro for contract deployment. This allows for more control over wallet creation and provider setup. ```rust let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT)); let mut wallets = launch_custom_provider_and_get_wallets(config, None, None).await?; let wallet = wallets.pop().unwrap(); let wallet_2 = wallets.pop().unwrap(); setup_program_test!( Abigen(Contract( name = "TestContract", project = "e2e/sway/contracts/contract_test" )), Deploy( name = "contract_instance", contract = "TestContract", wallet = "wallet", random_salt = false, ), ); ``` -------------------------------- ### Install Fuel Toolchain Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/node-operator/docs/src/fuel-ignition/testnet-node.md Installs the Fuel toolchain including `forc`, `forc-client`, `forc-fmt`, `forc-lsp`, `forc-wallet`, and `fuel-core`. The installation script downloads and sets up the necessary binaries in `~/.fuelup/bin`. ```sh curl https://install.fuel.network | sh ``` -------------------------------- ### Converting AssetId to &str in Rust Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/types/conversion.md This snippet shows how to get a string slice (`&str`) representation of an `AssetId`. It uses the `to_string()` method to get a `String` and then `as_str()` to get the slice. Requires an `AssetId` variable. ```rust let _str_from_asset_id: &str = asset_id.to_string().as_str(); ``` -------------------------------- ### Converting Address to &str in Rust Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/types/conversion.md This snippet shows how to get a string slice (`&str`) representation of an `Address`. It uses the `to_string()` method to get a `String` and then `as_str()` to get the slice. Requires an `Address` variable. ```rust let _str_from_address: &str = address.to_string().as_str(); ``` -------------------------------- ### Converting ContractId to &str in Rust Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-rs/docs/src/types/conversion.md This snippet shows how to get a string slice (`&str`) representation of a `ContractId`. It uses the `to_string()` method to get a `String` and then `as_str()` to get the slice. Requires a `ContractId` variable. ```rust let _str_from_contract_id: &str = contract_id.to_string().as_str(); ``` -------------------------------- ### Install Cosmovisor Source: https://github.com/fuellabs/markdown/blob/main/docs/node-operator/docs/src/fuel-sequencer/mainnet-node.md Installs the latest version of Cosmovisor using Go's install command. ```bash go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest ``` -------------------------------- ### Counter Contract Example Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/nightly/fuels-ts/apps/docs/src/guide/contracts/proxy-contracts.md.md An example Sway contract demonstrating a simple counter with increment, decrement, and get count functionalities. It utilizes storage slots for state management. ```sway contract; abi Counter { #[storage(read)] fn get_count() -> u64; #[storage(write, read)] fn increment_count(amount: u64) -> u64; #[storage(write, read)] fn decrement_count(amount: u64) -> u64; } storage { counter: u64 = 0, } impl Counter for Contract { #[storage(read)] fn get_count() -> u64 { storage.counter.try_read().unwrap_or(0) } #[storage(write, read)] fn increment_count(amount: u64) -> u64 { let current = storage.counter.try_read().unwrap_or(0); storage.counter.write(current + amount); storage.counter.read() } #[storage(write, read)] fn decrement_count(amount: u64) -> u64 { let current = storage.counter.try_read().unwrap_or(0); storage.counter.write(current - amount); storage.counter.read() } } ``` -------------------------------- ### Implement Pausable Library ABI Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway-libs/docs/book/src/getting_started/index.md Illustrates how to implement the `Pausable` ABI from the Pausable library in a Sway Smart Contract, including the `pause`, `unpause`, and `is_paused` functions. ```sway use pausable::{_is_paused, _pause, _unpause, Pausable}; // Implement the Pausable ABI for our contract impl Pausable for Contract { #[storage(write)] fn pause() { _pause(); // Call the provided pause function. } #[storage(write)] fn unpause() { _unpause(); // Call the provided unpause function. } #[storage(read)] fn is_paused() -> bool { _is_paused() // Call the provided is paused function. } } ``` -------------------------------- ### Counter Contract Example Source: https://github.com/fuellabs/markdown/blob/main/docs/fuels-ts/fuels-ts/apps/docs/src/guide/contracts/proxy-contracts.md.md An example Sway contract demonstrating a simple counter with increment, decrement, and get count functionalities. It utilizes storage slots for state management. ```sway contract; abi Counter { #[storage(read)] fn get_count() -> u64; #[storage(write, read)] fn increment_count(amount: u64) -> u64; #[storage(write, read)] fn decrement_count(amount: u64) -> u64; } storage { counter: u64 = 0, } impl Counter for Contract { #[storage(read)] fn get_count() -> u64 { storage.counter.try_read().unwrap_or(0) } #[storage(write, read)] fn increment_count(amount: u64) -> u64 { let current = storage.counter.try_read().unwrap_or(0); storage.counter.write(current + amount); storage.counter.read() } #[storage(write, read)] fn decrement_count(amount: u64) -> u64 { let current = storage.counter.try_read().unwrap_or(0); storage.counter.write(current - amount); storage.counter.read() } } ``` -------------------------------- ### Initialize Regular Contract Source: https://github.com/fuellabs/markdown/blob/main/docs/migrations-and-disclosures/docs/src/migrations/rust-sdk.md Demonstrates initializing a regular contract from raw binary or a file, with an option to set configurables. ```rust let contract = Contract::regular(contract_binary, Salt::zeroed(), vec![]); ``` ```rust let contract = Contract::load_from( "sway/contracts/storage/release/storage.bin", LoadConfiguration::default(), )?; ``` ```rust let contract = Contract::regular(binary, Salt::zeroed(), vec![]).with_configurables(configurables); ``` -------------------------------- ### Code OSS Sway Plugin Installation Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/sway/docs/book/src/lsp/installation.md Steps to install the Sway language support extension for Code OSS (VSCode on Linux) using the code-marketplace helper. ```bash Install code-marketplace Install the Sway extension from the VSCode marketplace. ``` -------------------------------- ### Run Guide Tests Source: https://github.com/fuellabs/markdown/blob/main/docs/contributing/guides.md This command executes the guide tests using pnpm. It's used to verify the functionality described in the guides. ```sh pnpm test:guides ``` -------------------------------- ### Generate Sway Rust Test Harness Source: https://github.com/fuellabs/markdown/blob/main/docs/nightly/fuels-rs/docs/src/getting-started.md Generates a Rust integration test harness for a Sway project using `cargo generate`. The `--init` flag specifies the template repository, and `--name` sets the project name. The `--force` flag preserves the casing of the project name. ```shell cargo generate --init fuellabs/sway templates/sway-test-rs --name --force ```