This is the official Rust SDK for the Dash Platform. Dash Platform is a Layer 2 cryptocurrency technology that builds upon the Dash layer 1 network. This SDK provides an abstraction layer to simplify usage of the Dash Platform along with data models based on the Dash Platform Protocol (DPP), a CRUD interface, and bindings for other technologies such as C.
See Rust documentation of this crate for more details.
To use this crate, define it as a dependency in your Cargo.toml:
[dependencies]
dash-sdk = { git="https://github.com/dashpay/platform" }In order to build application that uses Dash Platform SDK, you need to:
-
Implement a Wallet that will store, manage and use your keys to sign transactions and state transitions. An example implementation of wallet can be found in src/mock/wallet.rs.
-
Implement Dash SPV client that will sync your application with Dash Core state, including quorum public keys.
TODO: Add more details here.
For testing and development purposes, while you don't have your SPV client implementation ready, you can setup local Dash Core node and access it using RPC interface (see below).
-
Implement
ContextProvidergives Dash Platform SDK access to state of your application, like:- quorum public keys retrieved using SPV,
- data contracts configured and/or fetched from the server.
See GrpcContextProvider for an example implementation.
Dash Platform SDK supports mocking with mocks feature which provides a
convenient way to define mock expectations and use the SDK without actual
connection to Platform.
You can see examples of mocking in mock_fetch.rs and mock_fetch_many.rs.
You can find quick start example in examples/ folder. Examples must be configured by setting constants.
You can also inspect tests in tests/ folder for more detailed examples.
Also refer to Platform Explorer which uses the SDK to execute various state transitions.
This section provides instructions on how to test the RS-SDK for Dash Platform. The tests can be run in two modes: offline (without connectivity to the Dash Platform) and network (with connectivity to the Dash Platform). Offline mode is the default one.
If both network and offline testing is enabled, offline testing takes precedence.
Network testing requires connectivity to the Dash Platform and Dash Core.
Follow these steps to conduct network testing:
- Configure platform address and credentials in
packages/rs-sdk/tests/.env. Note that the.envfile might already be configured during project setup (yarn setup). - Run the test without default features, but with
network-testingfeature enabled.
cd packages/rs-sdk
cargo test -p dash-sdk --no-default-features --features network-testingOffline testing uses the vectors generated using packages/rs-sdk/scripts/generate_test_vectors.sh script.
This script will connect to node defined in packages/rs-sdk/tests/.env, execute all tests against it and
update test vectors in packages/rs-sdk/tests/vectors.
To generate test vectors against a testnet node (or other remote node), you can use helper script
packages/rs-sdk/scripts/connect_to_remote.sh which will generate .env file for you and tunnel connection to Dash
Core RPC on the remote host.
Refer to rich comments / help in the forementioned scripts for more details.
When starting the local devnet with SDK_TEST_DATA=true yarn start, the create_sdk_test_data cfg flag
activates creation of deterministic test data in genesis state. This data is defined in
packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/test/.
Current test data includes 3 identities, a data contract with 3 tokens, and address balances. Token configuration:
| Token | Config |
|---|---|
TOKEN_ID_0 |
base_supply=100000, frozen for IDENTITY_ID_2, no pricing, no pre-programmed distributions |
TOKEN_ID_1 |
base_supply=100000, paused, single price=25, no pre-programmed distributions |
TOKEN_ID_2 |
base_supply=100000, pricing schedule (10 levels), pre-programmed distributions at timestamps 1000, 5000, 10000 |
When adding a new query type, add corresponding test data to the files in create_genesis_state/test/
and reference it in packages/rs-sdk/tests/fetch/generated_data.rs.
To generate test vectors for offline testing, you need to have access to a Dash Platform instance, either by
specifying configuration manually in packages/rs-sdk/tests/.env or starting a local devnet.
The .env file is automatically generated during yarn setup or yarn reset, using platform/scripts/configure_dotenv.sh script. See Dash Platform documentation for more details about starting and using local devnet.
To generate test vectors:
- Start local dev environment of Dash Platform using
SDK_TEST_DATA=true yarn start. - Ensure platform address and credentials in
packages/rs-sdk/tests/.envare correct. - Run
packages/rs-sdk/scripts/generate_test_vectors.shscript. - (Optional) commit generated files with
git commit packages/rs-sdk/tests/vectors/.
Run the offline test using the following command:
cargo test -p dash-platform-sdkHow to implement Fetch and FetchMany trait on new object types (Object).
It's basically copy-paste and tweaking of existing implementation for another object type.
Definitions:
Request- gRPC request type, as generated inpackages/dapi-grpc/protos/platform/v0/platform.proto.Response- gRPC response type, as generated inpackages/dapi-grpc/protos/platform/v0/platform.proto.Object- object type that should be returned by rs-sdk, most likely defined indppcrate. In some cases, it can be defined inpackages/rs-drive-proof-verifier/src/types.rs.Key- some unique identifier of theObject, for exampleplatform_value::Identifier
Checklist:
-
Ensure protobuf messages are defined in
packages/dapi-grpc/protos/platform/v0/platform.protoand generated correctly inpackages/dapi-grpc/src/platform/client/org.dash.platform.dapi.v0.rs. -
In
packages/dapi-grpc/build.rs, addRequesttoVERSIONED_REQUESTSand responseResponsetoVERSIONED_RESPONSES. This should add derive ofVersionedGrpcMessage(and some more) inorg.dash.platform.dapi.v0.rs. -
Link request and response type to dapi-client by adding appropriate invocation of
impl_transport_request_grpc!macro inpackages/rs-dapi-client/src/transport/grpc.rs. -
If needed, implement new type in
packages/rs-drive-proof-verifier/src/types.rsto hide complexity of data structures used internally.If you intend to implement
FetchMany, you should define type returned byfetch_many()usingRetrievedObjectsthat will store collection of returned objects, indexed by some key. -
Implement
FromProoftrait for theObject(or type defined intypes.rs) inpackages/rs-drive-proof-verifier/src/proof.rs. -
Implement
Querytrait for theRequestandFetch(orFetchMany) trait for theObject. Create a dedicated module under the appropriate subdirectory (e.g.,packages/rs-sdk/src/platform/tokens/my_query.rs) and addQuery+Fetch/FetchManyimpls there. Deprecated: older code placed these in central files (query.rs,fetch.rs,fetch_many.rs) — do not follow that pattern for new queries. -
Implement
MockResponseforObjectinpackages/rs-sdk/src/mock/requests.rs. -
Implement
FetchMany\<Key\>trait for theObject(or type defined intypes.rs), with inner type Request =Request, if the query returns a collection of objects. Skip if the query returns a single result and onlyFetchis needed. -
Add
mod ...;clause topackages/rs-sdk/tests/fetch/main.rs -
Implement unit tests in
packages/rs-sdk/tests/fetch/*object*.rs. Tests must compile but will fail at this point due to missing test vectors — that is expected. The vector generation script (step 13) runs these tests with--features generate-test-vectorsagainst a live devnet to record responses as test vectors. After vectors are generated, re-runcargo test -p dash-sdkto verify they pass in offline mode. -
Add name of request type to match clause in
packages/rs-sdk/src/mock/sdk.rs:load_expectations() -
(Optional) If not already configured, run
yarn setup(fresh checkout) oryarn reset(reconfigure existing environment). Warning: both commands rebuild everything and reset data — do not run if your environment is already working. This configures the.envfile inpackages/rs-sdk/tests/needed by the tests. -
Start local devnet with
SDK_TEST_DATA=true yarn start. -
Generate test vectors by running
packages/rs-sdk/scripts/generate_test_vectors.sh test_namewheretest_namematches only the new tests (e.g.,test_token_pre_programmed_distributions). Running without arguments regenerates all vectors — avoid this unless intentional. The script executes matching tests with--features generate-test-vectorsagainst the running devnet, saving responses as test vectors inpackages/rs-sdk/tests/vectors/.