This guide documents the QuorumProof Code Snippet Library, designed to accelerate development, eliminate repetitive boilerplate, and enforce best practices across Soroban smart contracts and client SDK integrations.
When developing smart contracts and decentralized services on Stellar/Soroban, certain patterns repeat constantly:
- Setting up a
#![no_std]contract skeleton with storage keys. - Enforcing caller authorization with
require_auth(). - Safe storage retrieval with custom error handling.
- Writing to persistent storage with automatic TTL extension (
extend_ttl). - Emitting typed events with topics.
- Validating quorum slice weights against threshold limits.
- Verifying verifiable credentials off-chain.
- Invoking smart contracts via the Stellar SDK.
The QuorumProof snippet library encapsulates these patterns into standardized triggers available in popular IDEs.
| Prefix | Name | Description | Key Elements |
|---|---|---|---|
qp-contract |
Soroban Contract Boilerplate | Scaffold struct, initialize, and contractimpl |
#[contract], #[contractimpl], Env, DataKey |
qp-error-enum |
Contract Error Enum | Typed contract errors with error codes | #[contracterror], #[repr(u32)] |
qp-require-auth |
Require Auth | Authentication verification | caller.require_auth() |
qp-storage-get |
Instance Storage Get | Read instance storage with error handling | env.storage().instance().get(), ok_or |
qp-storage-set |
Persistent Storage Set | Write persistent storage and extend TTL | env.storage().persistent().extend_ttl() |
qp-event-publish |
Publish Event | Emit typed Soroban event with topics | env.events().publish() |
qp-contract-test |
Contract Unit Test | Scaffold test module with mock environment | Env::default(), mock_all_auths(), register_contract |
qp-quorum-slice |
Quorum Slice Validation | Sum attestor weights and check threshold | iter().map(|a| a.weight).sum(), InvalidThreshold |
qp-zk-verify |
ZK Proof Verification | Cross-contract call to ZK verifier | zk_verifier::Client::new(), verify_proof() |
| Prefix | Name | Description | Key Elements |
|---|---|---|---|
qp-invoke-contract |
Contract Invocation | Stellar SDK contract call | Contract, TransactionBuilder, submitTransaction |
qp-verify-credential |
Credential Verification | Off-chain credential validation | Timestamp expiration, signature validation |
qp-ws-subscribe |
WebSocket Event Stream | Real-time event listener with reconnect | WebSocket, credentials topic, auto-reconnect |
The repository includes workspace-level snippets in .vscode/quorumproof.code-snippets.
When you open the QuorumProof workspace in VS Code or Cursor:
- Open any
.rs,.ts, or.jsfile. - Type any prefix (e.g.,
qp-contractorqp-invoke-contract). - Press
TaborEnterto expand the snippet. - Press
Tabto navigate between placeholders and tab stops.
In .vscode/settings.json, ensure snippet suggestions appear at the top:
{
"editor.snippetSuggestions": "top",
"editor.tabCompletion": "on"
}The repository provides ready-to-import Live Templates in snippets/jetbrains/QuorumProof.xml.
- Open Settings / Preferences (
Cmd + ,on macOS,Ctrl + Alt + Son Linux/Windows). - Navigate to Editor > Live Templates.
- Click the gear icon (Manage) or
+and choose Import Templates. - Select
snippets/jetbrains/QuorumProof.xmlfrom the repository root. - Click Apply and OK.
Triggers will now auto-complete in Rust and TypeScript files.
UltiSnips format snippets are provided in:
snippets/ultisnips/rust.snippetssnippets/ultisnips/typescript.snippets
Add the snippet directory to your ~/.vimrc or init.vim:
let g:UltiSnipsSnippetDirectories=["UltiSnips", "/path/to/QuorumProof/snippets/ultisnips"]If using LuaSnip with friendly-snippets:
require("luasnip.loaders.from_vscode").lazy_load({
paths = { "./.vscode" }
})- In a new
.rsfile, typeqp-contractand pressTab. Enter your contract name:
#![no_std]
use soroban_sdk::{contract, contractimpl, contracttype, symbol_short, Address, Env, String, Symbol, Vec};
#[contract]
pub struct ComplianceRegistry;- Add custom error codes by typing
qp-error-enum:
use soroban_sdk::contracterror;
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum RegistryError {
NotInitialized = 1,
AlreadyInitialized = 2,
Unauthorized = 3,
InvalidThreshold = 4,
}- Inside your method, enforce authentication by typing
qp-require-auth:
admin.require_auth();- Retrieve stored parameters using
qp-storage-get:
let threshold: u32 = env
.storage()
.instance()
.get(&DataKey::Threshold)
.ok_or(RegistryError::NotInitialized)?;- Validate quorum weight using
qp-quorum-slice:
let total_weight: u32 = attestations
.iter()
.map(|a| a.weight)
.sum();
if total_weight < threshold {
return Err(RegistryError::InvalidThreshold);
}- Persist results and emit an on-chain event using
qp-storage-setandqp-event-publish:
env.storage().persistent().set(&key, &total_weight);
env.storage().persistent().extend_ttl(&key, 100_000, 200_000);
env.events().publish(
(symbol_short!("attest"), subject),
total_weight
);Type qp-contract-test to scaffold a complete test harness:
#[cfg(test)]
mod test {
use super::*;
use soroban_sdk::{testutils::Address as _, Address, Env};
#[test]
fn test_initialize_and_verify() {
let env = Env::default();
env.mock_all_auths();
let contract_id = env.register_contract(None, ComplianceRegistry);
let client = ComplianceRegistryClient::new(&env, &contract_id);
let admin = Address::generate(&env);
client.initialize(&admin);
assert!(client.is_initialized());
}
}Full runnable examples showing how all snippets integrate together are located in examples/snippets/:
credential_attestation_contract.rs: Complete contract implementation.verify_credential_client.ts: Client SDK integration.contract_unit_test.rs: Test suite.
To verify all snippet files conform to standard schema and naming rules, run the test script:
python3 scripts/test_snippets.py