Smart Contracts API
Complete Clarity smart contract reference for PsicoStacks SBTs.
Contract Name:
psicostacks-sbt
Testnet Address:
ST2QS1D1ZFCGX436QPHACJNC0R2A6HNB7BNM95J9X.psicostacks-sbt
mint-credential
Creates a new Soulbound Token credential.
Function Signature
(define-public (mint-credential
(recipient principal)
(schema (string-ascii 32))
(commit (buff 32))
(ttl-blocks uint))
(response uint uint))
Parameters
Parameter | Type | Description |
---|---|---|
recipient | principal | Wallet address to receive SBT |
schema | string-ascii | Schema version (e.g. "psicostacks:v1") |
commit | buff 32 | SHA-256 commitment hash |
ttl-blocks | uint | Validity in blocks (~52560 = 1 year) |
Returns
(ok credential-id)
on success, error code on failure.
Example Usage (JS)
import { openContractCall } from '@stacks/connect';
import { stringAsciiCV, bufferCV, uintCV, principalCV } from '@stacks/transactions';
const txId = await openContractCall({
contractAddress: 'ST2QS1D1...',
contractName: 'psicostacks-sbt',
functionName: 'mint-credential',
functionArgs: [
principalCV('SP2J6ZY48...'),
stringAsciiCV('psicostacks:v1'),
bufferCV(commitHash),
uintCV(52560)
]
});
verify-paid
Verifies a credential by paying the 10 STX fee.
Function Signature
(define-public (verify-paid (id uint))
(response bool uint))
Parameters
Parameter | Type | Description |
---|---|---|
id | uint | Credential ID to verify |
Cost
Verification Fee: 10 STX (~$3)
Fee is transferred from caller to credential owner
Example Usage (JS)
const txId = await openContractCall({
contractAddress: 'ST2QS1D1...',
contractName: 'psicostacks-sbt',
functionName: 'verify-paid',
functionArgs: [uintCV(22)]
});
revoke
Revokes a credential (owner or issuer only).
Function Signature
(define-public (revoke (id uint))
(response bool uint))
Authorization
Only credential owner OR issuer can revoke. Transaction fails if called by anyone else.
Example Usage (JS)
const txId = await openContractCall({
contractAddress: 'ST2QS1D1...',
contractName: 'psicostacks-sbt',
functionName: 'revoke',
functionArgs: [uintCV(22)]
});
Read-Only Functions
get-credential
Retrieves credential data by ID.
(define-read-only (get-credential (id uint))
(optional {
owner: principal,
issuer: principal,
schema: (string-ascii 32),
commit: (buff 32),
expiry: uint,
revoked: bool
}))
is-valid?
Checks if credential is valid (not revoked or expired).
(define-read-only (is-valid? (id uint))
bool)
get-verify-fee
Returns the current verification fee in micro-STX.
(define-read-only (get-verify-fee)
(response uint uint))
Error Codes
Code | Constant | Meaning |
---|---|---|
u100 | ERR-NOT-AUTH | Unauthorized action |
u404 | ERR-NOT-FOUND | Credential not found |
u409 | ERR-ALREADY-REVOKED | Already revoked |
u410 | ERR-EXPIRED | Credential expired |
Events
Smart contract emits print events for tracking:
mint
{ event: "mint", id: u1, commit: 0x..., expiry: u123456 }
verify
{ event: "verify", id: u1, by: 'SP3K8BC..., fee: u10000000 }
revoke
{ event: "revoke", id: u1 }
Testing with Clarinet
# Clone the repository
git clone https://github.com/jazminewrooman/psicostacks-smarts
cd psicostacks-smarts
# Run tests
clarinet test
# Check syntax
clarinet check