AIBTC Working Group
  • AIBTC
  • Prompt2DAO
  • AIBTC Contracts
    • DAO Base Layer
    • DAO Extensions
      • Action Proposal Voting
      • Core Proposal Voting
      • DAO Charter
      • Onchain Messaging
      • Payment Processor
      • Timed Vault
      • Token Owner
      • Treasury
    • DAO Proposals
      • Action Proposals
      • Core Proposals
    • Agent Account
  • Agent Tools
    • Overview
    • Available Tools
      • Smart Wallet Tools
      • Agent Wallet Tools
      • DAO Tools
      • Database Tools
      • Faktory Tools
  • AIBTC Cache
    • Overview
    • Contract Calls
      • API Design
      • Endpoints
        • Decode Clarity Value
        • Read-Only Function Calls
        • Contract ABI
        • Known ABI Contracts
      • Clarity Value Types
      • Integration Examples
    • Cache Services
    • Error Handling
    • Utilities
  • Prompting
    • Action Proposal Prompts
    • Smart Wallet Prompts
  • Links
    • Common Terms
    • Our App
    • Discord
    • GitHub
    • Prompt2DAO on X
    • AIBTC on X
  • Documentation Templates
    • Smart Contract Documentation
    • Cache Service Documentation
    • Cache Endpoint Documentation
    • Agent Tool Documentation
    • Prompting Documentation
  • Example Implementations
    • Smart Contract Example
    • Cache Service Example
    • Cache Endpoint Example
    • Agent Tool Example
Powered by GitBook
On this page
  • Simplified Format vs. Stacks.js Format
  • Basic Types
  • Container Types
  • Optional Types
  • Response Types
  • Complex Examples
  • Nested Tuple with List
  • Response with Optional
  • BigInt Handling
  1. AIBTC Cache
  2. Contract Calls

Clarity Value Types

The AIBTC Cache supports two ways to specify Clarity values:

  1. Stacks.js Clarity Values: Using the native Clarity value objects from the @stacks/transactions library

  2. Simplified JSON Format: A JSON-friendly format that's easier to use from non-TypeScript environments

This document focuses on the simplified JSON format, which can be used when specifying function arguments or interpreting decoded values.

Simplified Format vs. Stacks.js Format

Stacks.js Format:

import { uintCV, stringAsciiCV, tupleCV } from '@stacks/transactions';

// Create Clarity values using Stacks.js
const args = [
  uintCV(123),
  stringAsciiCV("hello"),
  tupleCV({
    key1: uintCV(456),
    key2: stringAsciiCV("world")
  })
];

Simplified JSON Format:

// Equivalent values using the simplified format
const args = [
  { type: "uint", value: "123" },
  { type: "string", value: "hello" },
  { 
    type: "tuple", 
    value: {
      key1: { type: "uint", value: "456" },
      key2: { type: "string", value: "world" }
    }
  }
];

When specifying function arguments or decoding values, you can use the following Clarity value types:

Basic Types

Type
Description
Example

uint

Unsigned integer

{"type": "uint", "value": "123"}

int

Signed integer

{"type": "int", "value": "-123"}

bool

Boolean

{"type": "bool", "value": true}

principal

Principal (address)

{"type": "principal", "value": "ST252TFQ08T74ZZ6XK426TQNV4EXF1D4RMTTNCWFA"}

buffer

Byte buffer

{"type": "buffer", "value": "0x68656c6c6f"}

string or stringascii

ASCII string

{"type": "string", "value": "hello"}

stringutf8

UTF-8 string

{"type": "stringutf8", "value": "hello 世界"}

Container Types

Type
Description
Example

list

List of values

{"type": "list", "value": [{"type": "uint", "value": "1"}, {"type": "uint", "value": "2"}]}

tuple

Key-value pairs

{"type": "tuple", "value": {"key1": {"type": "uint", "value": "1"}}}

Optional Types

Type
Description
Example

none

Optional none

{"type": "none"}

some or optional

Optional some

{"type": "some", "value": {"type": "uint", "value": "123"}}

Response Types

Type
Description
Example

ok or responseok

Response OK

{"type": "ok", "value": {"type": "uint", "value": "123"}}

err or responseerr

Response Error

{"type": "err", "value": {"type": "uint", "value": "123"}}

Complex Examples

Nested Tuple with List

{
  "type": "tuple",
  "value": {
    "name": {
      "type": "string",
      "value": "Example DAO"
    },
    "members": {
      "type": "list",
      "value": [
        {
          "type": "principal",
          "value": "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM"
        },
        {
          "type": "principal",
          "value": "ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"
        }
      ]
    }
  }
}

Response with Optional

{
  "type": "responseOk",
  "value": {
    "type": "some",
    "value": {
      "type": "tuple",
      "value": {
        "id": {
          "type": "uint",
          "value": "123"
        },
        "active": {
          "type": "bool",
          "value": true
        }
      }
    }
  }
}

BigInt Handling

When working with large numbers, they are represented as strings to avoid precision loss:

{
  "type": "uint",
  "value": "9007199254740992"
}
PreviousKnown ABI ContractsNextIntegration Examples

Last updated 1 month ago