Skip to main content

Overview

This guide shows you how to integrate the Staxiq User Profile contract into your web application using the Stacks JavaScript SDKs.

Prerequisites

1

Install Dependencies

Install the required Stacks packages:
2

Wallet Integration

Users need a Stacks wallet (Hiro, Xverse, or Leather) to interact with smart contracts.
3

Network Configuration

Decide whether to use testnet or mainnet.

Contract Service Implementation

Staxiq provides a contractService.js module that wraps all contract interactions:
src/services/contractService.js

Writing Data (Public Functions)

Public functions modify blockchain state and require user wallet signatures.

Save Risk Profile

Allow users to set their risk tolerance:
src/services/contractService.js:28
string
required
One of: "Conservative", "Balanced", or "Aggressive"
string | null
Transaction ID on success, null on failure

Usage Example

React Component

Anchor Strategy

Save an AI-generated strategy hash on-chain:
src/services/contractService.js:90
string
required
64-character hex string (SHA-256 hash of strategy)
string
required
Protocol name (max 32 characters), e.g., "ALEX", "Velar"
string | null
Transaction ID on success, null on failure

Usage Example

React Component

Reading Data (Read-Only Functions)

Read-only functions are free to call and don’t require wallet signatures.

Get User Profile

Retrieve a user’s complete profile:
src/services/contractService.js:55
string
required
Stacks wallet address (principal)
object | null
Profile object or null if not found

Usage Example

React Component

Check if User Has Profile

src/services/contractService.js:73
string
required
Stacks wallet address
boolean
true if user has a profile, false otherwise

Usage Example

React Component

Get Strategy Count

src/services/contractService.js:118
string
required
Stacks wallet address
number
Total number of strategies (0 if none)

Wallet Connection

Before users can interact with contracts, they need to connect their wallet using Stacks Connect:
Wallet Connection

Usage in React

Wallet Provider

Complete Integration Example

Here’s a complete example showing the full user flow:

Error Handling

Handle common errors gracefully:
Error Handling

Testing Integration

Always test on testnet before deploying to mainnet:
  1. Use testnet STX from the Stacks Faucet
  2. Connect with a testnet wallet
  3. Verify transactions on Testnet Explorer

Next Steps

Function Reference

See detailed function documentation

Testing

Learn how to test contracts locally

Deployment

Deploy contracts to testnet or mainnet

Stacks.js Docs

Official Stacks JavaScript documentation