Skip to main content

Overview

The Staxiq User Profile Contract (staxiq-user-profile.clar) is a Clarity smart contract that stores user risk preferences and AI-generated strategy recommendations on the Stacks blockchain.

Risk Profiles

Users set Conservative, Balanced, or Aggressive risk preferences

Strategy History

AI strategy recommendations are hashed and anchored on-chain

Immutable Records

All data is permanently stored and cannot be altered

User-Owned Data

Users maintain full control via their wallet address

Core Capabilities

1. Risk Profile Management

Users can set and update their risk tolerance level on-chain:
contracts/staxiq-user-profile.clar
(define-public (set-risk-profile (risk-level uint))
  ;; Saves or updates user risk preference
  ;; Validates input is 1, 2, or 3
  ;; Tracks created-at and updated-at block heights
)
Risk Levels:
  • 1 - Conservative: Low-risk, stable strategies
  • 2 - Balanced: Moderate risk/reward
  • 3 - Aggressive: High-risk, high-reward

2. Strategy Anchoring

AI-generated strategies are hashed and stored on-chain for transparency:
contracts/staxiq-user-profile.clar
(define-public (save-strategy
  (strategy-hash (string-ascii 64))
  (protocol (string-ascii 32))
)
  ;; Anchors AI strategy to blockchain
  ;; Requires existing risk profile
  ;; Increments strategy counter
  ;; Returns new strategy-id
)
Each saved strategy includes:
  • Cryptographic hash of strategy details
  • Target DeFi protocol (e.g., “ALEX”, “Velar”)
  • User’s risk level at time of generation
  • Block height timestamp

3. Profile Queries

Read user data without gas fees:
contracts/staxiq-user-profile.clar
;; Get full user profile
(define-read-only (get-user-profile (user principal)))

;; Check if user has a profile
(define-read-only (has-profile (user principal)))

;; Get risk level as human-readable string
(define-read-only (get-risk-label (user principal)))

;; Get total strategy count
(define-read-only (get-strategy-count (user principal)))

;; Get specific strategy details
(define-read-only (get-strategy (user principal) (strategy-id uint)))

Data Structures

User Profile

user-profiles
map
Maps wallet address to profile data

Strategy Record

strategy-history
map
Maps (user, strategy-id) to strategy details

Usage Flow

1

Connect Wallet

User connects their Stacks wallet (Hiro, Xverse, Leather)
2

Set Risk Profile

User selects risk tolerance and calls set-risk-profile
3

Generate Strategy

AI agent creates personalized strategy based on risk profile
4

Anchor Strategy

Strategy is hashed and saved on-chain via save-strategy
5

View History

User can query all past strategies and profile changes

Example: Complete User Journey

import { saveRiskProfile } from './services/contractService';

// User selects "Balanced" risk level
const txId = await saveRiskProfile('Balanced');
console.log('Profile saved:', txId);
// Returns transaction ID on blockchain

Benefits

For Users

Transparency

View complete history of AI recommendations and profile changes

Ownership

Data is tied to your wallet, not a centralized database

Verification

Cryptographically prove what was recommended and when

Portability

Take your data to any compatible platform

For Staxiq

  • Regulatory Compliance: Immutable audit trail for compliance requirements
  • Trust Building: Users can verify AI recommendations weren’t changed
  • Data Integrity: Blockchain prevents data tampering or loss
  • Decentralization: No single point of failure for user data

Contract Address

Testnet: ST9ZZEP9M6VZ9YJA0P69H313CRPV0HQ1ZNPVS8NZ.staxiq-user-profileView on explorer: Stacks Testnet Explorer

Limitations

  • Strategy content is not stored: Only a hash is saved on-chain to save space and gas. Full strategy details should be stored off-chain.
  • No deletion: Data cannot be removed once written. Profiles can be updated but history remains.
  • Gas costs: Writing data to blockchain requires STX tokens for transaction fees.
  • Block time: Transactions take ~10 minutes to confirm (Bitcoin block time).

Next Steps

Function Reference

Detailed documentation of all contract functions

Integration Guide

Learn how to call contracts from your frontend

Testing

Run tests and verify contract behavior

Deployment

Deploy contracts to testnet or mainnet

Build docs developers (and LLMs) love