constant val - Stacks

Returns the value of a constant defined in a contract, as a hex-encoded Clarity value.

Endpoint

httpGET /v2/constant_val/{deployer_address}/{contract_name}/{constant_name}

Path Parameters

ParameterTypeDescription
deployer_addressstringThe contract deployer's standard address
contract_namestringThe contract name
constant_namestringThe constant name

Example

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

curl "${STACKS_RPC}v2/constant_val/SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7/my-contract/ERR-NOT-AUTHORIZED"

Response

json{
    "data": "0x080000000000000000000000000000000d"
}

Response Fields

FieldTypeDescription
datastringThe constant's value, hex-encoded Clarity

Use Cases

  • Error decoding: Resolve a contract's error-code constants
  • Config reads: Inspect fixed parameters baked into a contract

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