This guide covers Rust-specific setup and development for the CDP SDK.
- Development Setup
- Updating the SDK to use a new version of the OpenAPI specification
- Testing
- Example Scripts
- Code Style
The CDP SDK uses Rust 1.93.1 or higher.
You can run the following to check your Rust version:
rustc --version
cargo --versionIf you don't have Rust installed, download it from rustup.rs.
Then, build the project and install dependencies by running:
cargo buildFronm the root of the repository, run make update-openapi to pull the latest version of the spec.
Then, run cd rust and make generate to regenerate api.rs.
Unlike other SDK implementations, the Rust SDK uses Progenitor to automatically generate type-safe client bindings from the OpenAPI specification at build time. This means:
- No manual API wrapping - All client methods are automatically generated with proper types
- No separate generation step - The OpenAPI client is generated during
cargo build - Type safety - Request/response types are automatically derived from the OpenAPI spec
The generated client is located in src/api.rs and provides:
- Strongly-typed request builders (e.g.,
client.create_evm_account().body(body).send()) - Automatic serialization/deserialization of all types
- Builder patterns for all endpoints
If you need to add new functionality, focus on:
- Authentication middleware (
src/auth.rs) - for new auth requirements - Error handling (
src/error.rs) - for custom error types - Examples (
examples/) - to demonstrate new features - Tests (
tests/) - to validate new functionality
Run make test to run all unit tests in the SDK.
Run make test-e2e to run the end-to-end tests. Make sure to set the required environment variables:
export CDP_API_KEY_ID="your-api-key-id"
export CDP_API_KEY_SECRET="your-api-key-secret"
export CDP_WALLET_SECRET="your-wallet-secret"You can also set E2E_LOGGING=true to enable detailed logging during e2e tests:
E2E_LOGGING=true make test-e2e- Unit tests - Located in
src/modules using#[cfg(test)] - Integration tests - Located in
tests/e2e.rsfor comprehensive API testing - Example validation - Examples serve as both documentation and integration tests
The CDP SDK includes several runnable examples in the examples/ directory:
evm_account_management- EVM account CRUD operationsevm_signing- EVM transaction and message signingsmart_account_management- Smart account operationssolana_account_management- Solana account CRUD operationssolana_signing- Solana transaction and message signingtoken_balances- Multi-chain token balance queries
Run any example with:
cargo run --example evm_account_managementWhen you make changes to the SDK code, your changes will automatically take effect when you run an example.
We use rustfmt and clippy for formatting and linting:
# Format code
make format
# Lint code
make lint
# Fix linting issues
make lint-fix
# Check code without building
make check- Follow the Rust API Guidelines
- Use
#[must_use]for functions where ignoring the return value is likely a bug - Prefer
impl Traitover generic type parameters where appropriate - Use
thiserrorfor error types andanyhowfor error handling in examples - Document all public APIs with
///comments including examples where helpful
- Generated code (
src/api.rs) - Do not modify directly, regenerated on build - Authentication (
src/auth.rs) - JWT generation and middleware - Error types (
src/error.rs) - Custom error handling - Library exports (
src/lib.rs) - Public API surface - Examples (
examples/) - Practical usage demonstrations - Tests (
tests/) - Integration and e2e testing