This example demonstrates how a Soroban governance contract can gate voting on KYC verification using TrustLink.
- A governance contract stores a TrustLink contract address
vote()checkshas_valid_claim(voter, "KYC_PASSED")before allowing a vote- Voting reverts if the voter is not KYC-verified
- Unit tests cover blocked and allowed voting flows
The key voting guard is:
let trustlink_client = trustlink::Client::new(&env, &trustlink);
let kyc_claim = String::from_str(&env, "KYC_PASSED");
let has_kyc = trustlink_client.has_valid_claim(&voter, &kyc_claim);
if !has_kyc {
return Err(String::from_str(&env, "voter must have valid KYC"));
}src/lib.rs: Governance contract + testsCargo.toml: Contract dependencies
cd examples/governance
cargo test- Build the contract:
cargo build --target wasm32-unknown-unknown --release- Deploy to testnet:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/governance_example.wasm \
--source <YOUR_SECRET_KEY> \
--network testnet- Initialize with TrustLink contract address:
soroban contract invoke \
--id <GOVERNANCE_CONTRACT_ID> \
--source <YOUR_SECRET_KEY> \
--network testnet \
-- initialize \
--trustlink <TRUSTLINK_CONTRACT_ID>- Cast a vote:
soroban contract invoke \
--id <GOVERNANCE_CONTRACT_ID> \
--source <VOTER_SECRET_KEY> \
--network testnet \
-- vote \
--voter <VOTER_ADDRESS> \
--proposal_id 1 \
--vote true- In production, replace error strings with typed contract errors
- Consider implementing proposal expiration and finalization logic
- Add vote weight based on token holdings or other criteria
- Implement vote delegation for proxy voting
- Consider issuer-specific policies using
has_valid_claim_from_issuer - Add event emission for vote tracking and indexing