id,language,category,name,description,code,imports_or_contract,notes
1,clarity,trait,sip010-trait,"SIP-010 fungible token trait","(define-trait sip010-trait ((transfer (uint principal principal (optional (buff 34))) (response bool uint)) (get-name () (response (string-ascii 32) uint)) (get-symbol () (response (string-ascii 32) uint)) (get-decimals () (response uint uint)) (get-balance (principal) (response uint uint)) (get-total-supply () (response uint uint)) (get-token-uri () (response (optional (string-utf8 256)) uint))))","SIP-010 standard","Standard fungible token trait for Stacks"
2,clarity,read,get-balance,"Get token balance","(ok (ft-get-balance token-name account))","SIP-010 function","Returns balance in base units (microTokens)"
3,clarity,read,get-total-supply,"Get total token supply","(ok (ft-get-supply token-name))","SIP-010 function","Returns total minted tokens minus burned"
4,clarity,read,get-decimals,"Get token decimals","(ok u6)","SIP-010 function","Standard: 6 decimals (1 token = 1000000 microTokens)"
5,clarity,read,get-name,"Get token name","(ok token-name)","SIP-010 function","Human-readable token name"
6,clarity,read,get-symbol,"Get token symbol","(ok token-symbol)","SIP-010 function","Token ticker symbol (3-5 chars)"
7,clarity,read,get-token-uri,"Get token metadata URI","(ok (some token-uri))","SIP-010 function","Optional URI to token metadata JSON"
8,clarity,transfer,transfer-token,"Transfer tokens","(begin (asserts! (> amount u0) err-invalid-amount) (try! (ft-transfer? token-name amount sender recipient)) (ok true))","SIP-010 function","Sender must have sufficient balance"
9,clarity,mint,mint-tokens,"Mint new tokens","(begin (asserts! (is-eq tx-sender contract-owner) err-not-authorized) (try! (ft-mint? token-name amount recipient)) (ok true))","Custom function","Only authorized minter can create tokens"
10,clarity,burn,burn-tokens,"Burn (destroy) tokens","(begin (asserts! (is-eq tx-sender owner) err-not-authorized) (try! (ft-burn? token-name amount owner)) (ok true))","Custom function","Reduces total supply; irreversible"
11,clarity,allowance,set-allowance,"Approve spender allowance","(ok (map-set allowances { owner: tx-sender spender: spender } { amount: amount }))","ERC-20 pattern","Allows spender to transfer tokens on behalf of owner"
12,clarity,allowance,get-allowance,"Get spender allowance","(ok (default-to u0 (get amount (map-get? allowances { owner: owner spender: spender }))))","ERC-20 pattern","Returns approved amount for spender"
13,clarity,allowance,transfer-from,"Transfer tokens using allowance","(let ((allowance (unwrap! (get-allowance owner spender) err-no-allowance))) (asserts! (>= allowance amount) err-insufficient-allowance) (try! (ft-transfer? token-name amount owner recipient)) (map-set allowances { owner: owner spender: spender } { amount: (- allowance amount) }) (ok true))","ERC-20 pattern","Spender transfers from owner's balance; reduces allowance"
14,clarity,access,set-minter,"Set authorized minter","(begin (asserts! (is-eq tx-sender contract-owner) err-not-authorized) (ok (map-set minters { minter: new-minter } { authorized: authorized })))","Access control","Manage who can mint tokens"
15,clarity,pause,pause-transfers,"Pause token transfers","(begin (asserts! (is-eq tx-sender contract-owner) err-not-authorized) (ok (var-set paused true)))","Emergency function","Temporarily disable all transfers"
16,clarity,pause,unpause-transfers,"Resume token transfers","(begin (asserts! (is-eq tx-sender contract-owner) err-not-authorized) (ok (var-set paused false)))","Emergency function","Re-enable transfers after pause"
17,clarity,vesting,create-vesting-schedule,"Create token vesting schedule","(map-set vesting-schedules { recipient: recipient } { total-amount: amount start-time: start-block cliff-duration: cliff-blocks vesting-duration: total-blocks released: u0 })","Vesting function","Lock tokens with gradual release schedule"
18,clarity,vesting,calculate-vested-amount,"Calculate vested tokens","(let ((schedule (unwrap! (map-get? vesting-schedules { recipient: recipient }) err-no-schedule)) (elapsed (- block-height (get start-time schedule)))) (if (< elapsed (get cliff-duration schedule)) u0 (min (/ (* (get total-amount schedule) elapsed) (get vesting-duration schedule)) (get total-amount schedule))))","Vesting function","Linear vesting after cliff period"
19,clarity,vesting,release-vested-tokens,"Release vested tokens","(let ((vested (try! (calculate-vested-amount recipient))) (schedule (unwrap! (map-get? vesting-schedules { recipient: recipient }) err-no-schedule)) (released (get released schedule)) (releasable (- vested released))) (try! (ft-transfer? token-name releasable contract-principal recipient)) (map-set vesting-schedules { recipient: recipient } (merge schedule { released: vested })) (ok releasable))","Vesting function","Transfer available vested tokens to recipient"
20,clarity,snapshot,take-balance-snapshot,"Take balance snapshot for voting","(map-set snapshots { snapshot-id: snapshot-id account: account } { balance: (ft-get-balance token-name account) })","Governance function","Record balances at specific block for voting"
21,javascript,read,get-token-balance,"Get token balance via SDK","const response = await fetch(`https://api.hiro.so/extended/v1/address/${address}/balances`); const balances = await response.json(); const token = balances.fungible_tokens[`${contractAddress}.${contractName}::${tokenName}`]; return token ? token.balance : '0'","fetch or axios","Returns balance string in base units"
22,javascript,read,get-token-info,"Get token metadata","const response = await fetch(`https://api.hiro.so/extended/v1/contract/${contractAddress}.${contractName}`); const contract = await response.json(); const metadata = { name: contract.name symbol: contract.symbol decimals: 6 }","fetch or axios","Parse from contract or metadata endpoint"
23,javascript,transfer,transfer-token-tx,"Build token transfer transaction","const txOptions = { contractAddress contractName functionName: 'transfer' functionArgs: [uintCV(amountInBase) principalCV(sender) principalCV(recipient) noneCV()] network postConditions: [Pc.principal(sender).willSendLte(amountInBase).ft(contractAddress contractName tokenName)] }; const tx = await makeContractCall(txOptions)","import { makeContractCall uintCV principalCV noneCV Pc } from '@stacks/transactions'","Amount in base units (microTokens); post-condition protects sender"
24,javascript,mint,mint-token-tx,"Build mint transaction","const txOptions = { contractAddress contractName functionName: 'mint' functionArgs: [uintCV(amount) principalCV(recipient)] senderKey: minterPrivateKey network }; const tx = await makeContractCall(txOptions)","import { makeContractCall uintCV principalCV } from '@stacks/transactions'","Only authorized minter can call; requires private key"
25,javascript,allowance,approve-spender-tx,"Build approve allowance transaction","const txOptions = { contractAddress contractName functionName: 'approve' functionArgs: [principalCV(spender) uintCV(amount)] network }; const tx = await makeContractCall(txOptions)","import { makeContractCall principalCV uintCV } from '@stacks/transactions'","Allows spender to transfer tokens on behalf of sender"
26,javascript,allowance,transfer-from-tx,"Build transfer-from transaction","const txOptions = { contractAddress contractName functionName: 'transfer-from' functionArgs: [principalCV(owner) principalCV(recipient) uintCV(amount)] network postConditions: [Pc.principal(owner).willSendLte(amount).ft(contractAddress contractName tokenName)] }; const tx = await makeContractCall(txOptions)","import { makeContractCall principalCV uintCV Pc } from '@stacks/transactions'","Spender transfers from owner's balance using allowance"
27,javascript,utils,convert-decimals,"Convert between display and base units","function toBaseUnits(displayAmount decimals = 6) { return Math.floor(displayAmount * Math.pow(10 decimals)) } function toDisplayUnits(baseAmount decimals = 6) { return baseAmount / Math.pow(10 decimals) }","None","Display: 1.5 tokens; Base: 1500000 microTokens (6 decimals)"
28,javascript,utils,format-token-amount,"Format token amount with symbol","function formatTokenAmount(baseAmount symbol decimals = 6) { const display = (baseAmount / Math.pow(10 decimals)).toFixed(decimals); return `${parseFloat(display).toLocaleString()} ${symbol}`}","None","Returns formatted string like '1,234.56 DIKO'"
29,javascript,multicall,batch-token-transfers,"Batch transfer to multiple recipients","const transfers = recipients.map(({ address amount }) => ({ contractAddress contractName functionName: 'transfer' functionArgs: [uintCV(amount) principalCV(sender) principalCV(address) noneCV()] })); const txs = await Promise.all(transfers.map(opts => makeContractCall({ ...opts network })))","import { makeContractCall uintCV principalCV noneCV } from '@stacks/transactions'","Each transfer is separate transaction; consider gas costs"
30,api,price,get-token-price,"Get token price from DEX","const response = await fetch(`https://api.alexlab.co/v1/price/${tokenSymbol}`); const data = await response.json(); return data.price_usd","fetch","Returns current USD price from Alex DEX"
31,api,holders,get-token-holders,"Get list of token holders","const response = await fetch(`https://api.hiro.so/extended/v1/tokens/ft/metadata?contract_id=${contractAddress}.${contractName}::${tokenName}`); const data = await response.json(); return data.total_supply","fetch or axios","Returns holder count and distribution data"
32,javascript,validation,validate-token-address,"Validate token contract exists","async function isValidToken(contractAddress contractName) { try { const response = await fetch(`https://api.hiro.so/v2/contracts/interface/${contractAddress}/${contractName}`); const data = await response.json(); return data.functions.some(f => f.name === 'transfer' || f.name === 'get-balance') } catch { return false }}","fetch","Checks if contract implements token interface"
33,javascript,airdrop,calculate-airdrop-amounts,"Calculate proportional airdrop amounts","function calculateAirdrop(holders totalAirdrop) { const totalSupply = holders.reduce((sum h) => sum + h.balance 0); return holders.map(holder => ({ address: holder.address amount: Math.floor((holder.balance / totalSupply) * totalAirdrop) }))}","None","Distribute tokens proportionally to existing holders"
34,javascript,liquidity,calculate-liquidity-value,"Calculate LP token value","function calculateLPValue(lpBalance reserve0 reserve1 totalLpSupply) { const share = lpBalance / totalLpSupply; return { token0Amount: reserve0 * share token1Amount: reserve1 * share }}","None","Calculate underlying assets for LP tokens"
35,clarity,staking,stake-tokens,"Stake tokens for rewards","(begin (try! (ft-transfer? token-name amount tx-sender contract-principal)) (map-set stakes { staker: tx-sender } { amount: (+ (get-stake tx-sender) amount) staked-at: block-height }) (ok true))","Staking function","Lock tokens in contract for reward eligibility"
36,clarity,staking,unstake-tokens,"Unstake tokens","(let ((stake (unwrap! (map-get? stakes { staker: tx-sender }) err-no-stake)) (amount (get amount stake))) (try! (ft-transfer? token-name amount contract-principal tx-sender)) (map-delete stakes { staker: tx-sender }) (ok amount))","Staking function","Withdraw staked tokens; may have cooldown period"
37,clarity,staking,calculate-rewards,"Calculate staking rewards","(let ((stake (unwrap! (map-get? stakes { staker: staker }) err-no-stake)) (blocks-staked (- block-height (get staked-at stake))) (stake-amount (get amount stake))) (ok (/ (* stake-amount blocks-staked reward-rate) u1000000)))","Staking function","Linear rewards based on time and amount staked"
38,javascript,defi,add-token-liquidity,"Add token to liquidity pool","const txOptions = { contractAddress: dexAddress contractName: dexName functionName: 'add-liquidity' functionArgs: [contractPrincipalCV(tokenAddress tokenName) uintCV(tokenAmount) uintCV(stxAmount) uintCV(minTokenAmount) uintCV(minStxAmount)] network postConditions: [Pc.principal(userAddress).willSendLte(tokenAmount).ft(tokenAddress tokenName token) Pc.principal(userAddress).willSendLte(stxAmount).ustx()] }; const tx = await makeContractCall(txOptions)","import { makeContractCall contractPrincipalCV uintCV Pc } from '@stacks/transactions'","Provide token and STX to pool; receive LP tokens"
39,javascript,defi,remove-token-liquidity,"Remove token from liquidity pool","const txOptions = { contractAddress: dexAddress contractName: dexName functionName: 'remove-liquidity' functionArgs: [contractPrincipalCV(tokenAddress tokenName) uintCV(lpTokenAmount) uintCV(minTokenAmount) uintCV(minStxAmount)] network }; const tx = await makeContractCall(txOptions)","import { makeContractCall contractPrincipalCV uintCV } from '@stacks/transactions'","Burn LP tokens; receive underlying token and STX"
40,javascript,governance,create-token-vote,"Create governance proposal","const txOptions = { contractAddress: governanceAddress contractName: governanceName functionName: 'propose' functionArgs: [stringUtf8CV(proposalTitle) stringUtf8CV(proposalDescription) contractPrincipalCV(targetContract targetFunction)] network }; const tx = await makeContractCall(txOptions)","import { makeContractCall stringUtf8CV contractPrincipalCV } from '@stacks/transactions'","Token holders can create and vote on proposals"