data var - Stacks

Returns the current value of a contract data variable, as a hex-encoded Clarity value, with an optional MARF proof.

Endpoint

httpGET /v2/data_var/{principal}/{contract_name}/{var_name}

Path Parameters

ParameterTypeDescription
principalstringThe contract deployer's standard address
contract_namestringThe contract name
var_namestringThe data-variable name

Query Parameters

ParameterTypeDescription
proofnumberSet to 0 to omit the MARF Merkle proof

Example

bashexport STACKS_RPC=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

curl "${STACKS_RPC}v2/data_var/SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7/my-contract/total-supply?proof=0"

Response

json{
    "data": "0x010000000000000000000000003b9aca00",
    "proof": "0x0c3a5b6e..."
}

Response Fields

FieldTypeDescription
datastringThe variable's value, hex-encoded Clarity
proofstringMARF proof (empty when proof=0)

Use Cases

  • State reads: Read a contract's mutable data variable
  • Supply tracking: Read a token's total-supply variable

Error Handling

ErrorMessageDescription
400 / Bad requestBad requestA path, query, or body parameter was invalid or the transaction was rejected
404 / Not foundNot foundThe account, contract, map entry, variable, or constant does not exist
403 / RBAC: access deniedAccess deniedThe GetBlock access token is missing or incorrect