Rust SDK - Examples
For sample code which explains the core concepts of how to use the SDK, see:
Below are additional resources which may be more suited for your individual use case.
Code Snippets
Section titled “Code Snippets”The examples folder
in the SDK repo has many code snippets you can customize to your needs.
| Example | Description |
|---|---|
transfer.rs | Basic APT transfer between accounts |
view_function.rs | Read-only view function calls |
simulation.rs | Simulate transactions before submission |
sponsored_transaction.rs | Fee payer (sponsored) transactions |
multi_agent.rs | Multi-signer transactions |
account_management.rs | Account creation, mnemonics, and key types |
indexer_queries.rs | Query the Aptos indexer via GraphQL |
fungible_asset_transfer.rs | Transfer a fungible asset |
orderless_transaction.rs | Orderless (nonce-based) transactions |
How to run examples
Section titled “How to run examples”To run one of the example scripts:
-
Clone the repository.
Terminal window git clone https://github.com/aptos-labs/aptos-rust-sdk.gitcd aptos-rust-sdk -
Run an example with the features it needs.
Terminal window cargo run -p aptos-sdk --example transfer --features "ed25519,faucet"
Helpful Reference Code
Section titled “Helpful Reference Code”- SDK source code - This has in-line comments explaining what each function does.
- API reference - Generated rustdoc for the crate.
- Migration guide - Mapping from the legacy
aptos-coreSDK.