Get contract source

RPC node

Retrieves the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data.

GET

Parameters

Path Parameters

contract_address
REQUIRED
string Standard Stacks address (e.g. `SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0`). Must be 28-41 characters long using Stacks base58check format.
contract_name
REQUIRED
string Contract name. Must start with a letter and can contain letters, numbers, hyphens, and underscores. Maximum length is 40 characters for new contracts. Legacy contracts may have names up to 128 characters.

Query Parameters

proof
integer Controls MARF proof inclusion in response. Set to 1 (default) to include proof, 0 to exclude. Invalid values default to 0 (no proof).
tip
string Stacks chain tip to query from. Options: - (empty/omitted): Use latest anchored tip (canonical confirmed state) - `latest`: Use latest known tip including unconfirmed microblocks - `{block_id}`: Use specific block ID (64 hex characters)
Status codeDescription
200Success
400Bad request
404Not found
500Internal Server Error
cURL
curl -L \
"https://api.hiro.so/v2/contracts/source/{contract_address}/{contract_name}?proof={proof}&tip={tip}" \
-H 'Accept: application/json'
Response
{
"source": "(define-constant sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)\n(define-constant recipient 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G)\n\n(define-fungible-token novel-token-19)\n(begin (ft-mint? novel-token-19 u12 sender))\n(begin (ft-transfer? novel-token-19 u2 sender recipient))\n\n(define-non-fungible-token hello-nft uint)\n(begin (nft-mint? hello-nft u1 sender))\n(begin (nft-mint? hello-nft u2 sender))\n(begin (nft-transfer? hello-nft u1 sender recipient))\n\n(define-public (test-emit-event)\n (begin\n (print \"Event! Hello world\")\n (ok u1)))\n(begin (test-emit-event))\n\n(define-public (test-event-types)\n (begin\n (unwrap-panic (ft-mint? novel-token-19 u3 recipient))\n (unwrap-panic (nft-mint? hello-nft u2 recipient))\n (unwrap-panic (stx-transfer? u60 tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))\n (unwrap-panic (stx-burn? u20 tx-sender))\n (ok u1)))\n\n(define-map store ((key (buff 32))) ((value (buff 32))))\n(define-public (get-value (key (buff 32)))\n (begin\n (match (map-get? store ((key key)))\n entry (ok (get value entry))\n (err 0))))\n(define-public (set-value (key (buff 32)) (value (buff 32)))\n (begin\n (map-set store ((key key)) ((value value)))\n (ok u1)))",
"publish_height": 3196,
"proof": "0x000000110406000000123456789abcdef"
}

How is this guide?