API
Introduction
The Stacks Blockchain API allows you to query the Stacks blockchain and interact with smart contracts. It was built to maintain pageable materialized views of the Stacks Blockchain.
Note that the Stacks Node RPC API and the Hiro Stacks API are two different things. The Hiro API is a centralized service run by Hiro, a developer tooling company, that makes it easy to get onboarded and begin interacting with the Stacks blockchain in a RESTful way. You can also run your own API server.
The Hiro Stacks API is a proxy for the Stacks Node API that makes it a bit easier to work with by providing additional functionality.
The RPC API is generated by every Stacks node and allows developers to self-host their own node and API for a more decentralized architecture.
The RPC API can be used without any authorization. The basepath for the API is:
# for mainnet, replace `testnet` with `mainnet`
https://api.testnet.hiro.so/
If you run a local node, it exposes an HTTP server on port 20443
. The info endpoint would be localhost:20443/v2/info
.
Stacks Node RPC API endpoints
The Stacks 2.0 Blockchain API (Hiro's API) is centrally hosted. However, every running Stacks node exposes an RPC API, which allows you to interact with the underlying blockchain. Instead of using a centrally hosted API, you can directly access the RPC API of a locally hosted Node.
Broadcast raw transactions on the network. You can use the @stacks/transactions project to generate a raw transaction payload.
The node performs static validation checks on transactions before accepting them into the mempool, including:
- Transaction format validation
- Signature verification
- Nonce checking
- Fee validation
- Size limits
Transaction ID of successful post of a raw tx to the node's mempool.
e161978626f216b2141b156ade10501207ae535fa365a13ef5d7a7c9310a09f2
Pattern: ^[0-9a-f]{64}$
Bad request
Internal Server Error
POST /v2/transactions HTTP/1.1
Host: localhost:20443
Content-Type: application/octet-stream
Accept: */*
Content-Length: 379
"binary format of 00000000010400bed38c2aadffa348931bcb542880ff79d607afec000000000000000000000000000000c800012b0b1fff6cccd0974966dcd665835838f0985be508e1322e09fb3d751eca132c492bda720f9ef1768d14fdabed6127560ba52d5e3ac470dcb60b784e97dc88c9030200000000000516df0ba3e79792be7be5e50a370289accfc8c9e032000000000000303974657374206d656d6f00000000000000000000000000000000000000000000000000"
e161978626f216b2141b156ade10501207ae535fa365a13ef5d7a7c9310a09f2
Get contract interface using a contract_address
and contract name
Contract interface
Bad request
Not found
Internal Server Error
GET /v2/contracts/interface/{contract_address}/{contract_name} HTTP/1.1
Host: localhost:20443
Accept: */*
{
"$ref": "#/x-ext/a873530"
}
Attempt to fetch data from a contract data map. The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The map is identified with [Map Name].
The key to lookup in the map is supplied via the POST body. This should be supplied as the hex string serialization of the key (which should be a Clarity value). Note, this is a JSON string.
The response is a JSON object with the following properties:
data
: The hex serialization of the map response. Note that map responses are Clarity option types, for non-existent values, this is a serialized none, and for all other responses, it is a serialized (some ...) object.proof
: The hex serialization of the Merkle proof for the data.
Success
Bad request
Not found
Internal Server Error
POST /v2/map_entry/{contract_address}/{contract_name}/{map_name} HTTP/1.1
Host: localhost:20443
Content-Type: application/json
Accept: */*
Content-Length: 6
"text"
{
"$ref": "./components/examples/clarity-data.example.json"
}
Returns the Clarity source code of a given contract, along with the block height it was published in, and the MARF proof for the data.
Success
Bad request
Not found
Internal Server Error
GET /v2/contracts/source/{contract_address}/{contract_name} HTTP/1.1
Host: localhost:20443
Accept: */*
{
"$ref": "./components/examples/contract-source.example.json"
}
Call a read-only public function on a given contract.
The contract is identified with [Stacks Address] and [Contract Name] in the URL path. The function is identified with [Function Name].
The arguments to the function are supplied via the POST body. This should be a JSON object with two main properties:
sender
which should be a standard Stacks addressarguments
which should be an array of hex-encoded Clarity values.
Function executed successfully
Bad request
Not found
Internal Server Error
POST /v2/contracts/call-read/{contract_address}/{contract_name}/{function_name} HTTP/1.1
Host: localhost:20443
Content-Type: application/json
Accept: */*
No content
Get the account data for the provided principal
Where balance is the hex encoding of a unsigned 128-bit integer (big-endian), nonce is a unsigned 64-bit integer, and the proofs are provided as hex strings.
For non-existent accounts, this does not 404, rather it returns an object with balance and nonce of 0.
Success
Bad request
Not found
Internal Server Error
GET /v2/accounts/{principal} HTTP/1.1
Host: localhost:20443
Accept: */*
{
"$ref": "./components/examples/account-data.example.json"
}
Get an estimated fee for the supplied transaction. This estimates the execution cost of the transaction, the current fee rate of the network, and returns estimates for fee amounts.
transaction_payload
is a hex-encoded serialization of the TransactionPayload for the transaction.estimated_len
is an optional argument that provides the endpoint with an estimation of the final length (in bytes) of the transaction, including any post-conditions and signatures
If the node cannot provide an estimate for the transaction
(e.g., if the node has never seen a contract-call for the
given contract and function) or if estimation is not
configured on this node, a 400 response is returned.
The 400 response will be a JSON error containing a reason
field which can be one of the following:
DatabaseError
- this Stacks node has had an internal database error while trying to estimate the costs of the supplied transaction.NoEstimateAvailable
- this Stacks node has not seen this kind of contract-call before, and it cannot provide an estimate yet.CostEstimationDisabled
- this Stacks node does not perform fee or cost estimation, and it cannot respond on this endpoint.
The 200 response contains the following data:
estimated_cost
- the estimated multi-dimensional cost of executing the Clarity VM on the provided transaction.estimated_cost_scalar
- a unitless integer that the Stacks node uses to compare how much of the block limit is consumed by different transactions. This value incorporates the estimated length of the transaction and the estimated execution cost of the transaction. The range of this integer may vary between different Stacks nodes. In order to compute an estimate of total fee amount for the transaction, this value is multiplied by the same Stacks node"s estimated fee rate.cost_scalar_change_by_byte
- a float value that indicates how much theestimated_cost_scalar
value would increase for every additional byte in the final transaction.estimations
- an array of estimated fee rates and total fees to pay in microSTX for the transaction. This array provides a range of estimates (default: 3) that may be used. Each element of the array contains the following fields:fee_rate
- the estimated value for the current fee rates in the networkfee
- the estimated value for the total fee in microSTX that the given transaction should pay. These values are the result of computing:fee_rate
xestimated_cost_scalar
. If the estimated fees are less than the minimum relay fee(1 ustx x estimated_len)
, then that minimum relay fee will be returned here instead.
Note: If the final transaction"s byte size is larger than
supplied to estimated_len
, then applications should increase
this fee amount by:
fee_rate
x cost_scalar_change_by_byte
x (final_size
- estimated_size
)
Estimated fees for the transaction
Fee estimation error
Internal Server Error
POST /v2/fees/transaction HTTP/1.1
Host: localhost:20443
Content-Type: application/json
Accept: */*
Content-Length: 69
{
"$ref": "./components/examples/fee-transaction-request.example.json"
}
{
"$ref": "./components/examples/fee-transaction-response.example.json"
}
Get an estimated fee rate for STX transfer transactions. This is a fee rate per byte, returned as a JSON integer (microSTX per byte).
Fee rate in microSTX per byte
Fee rate in microSTX per byte
Internal Server Error
GET /v2/fees/transfer HTTP/1.1
Host: localhost:20443
Accept: */*
3
Determine whether or not a specified trait is implemented (either explicitly or implicitly) within a given contract.
Stacks address of the trait-defining contract.
SP2Z1K16238380NBP4T38A4G10A90Q03JJ2C2003
Pattern: ^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{28,41}$
Contract name of the trait-defining contract.
some-trait
Pattern: ^[a-zA-Z]([a-zA-Z0-9]|[-_]){0,127}$
some-trait
Success
Bad request
Not found
GET /v2/traits/{contract_address}/{contract_name}/{trait_contract_address}/{trait_contract_name}/{trait_name} HTTP/1.1
Host: localhost:20443
Accept: */*
{
"$ref": "./components/examples/is-trait-implemented.example.json"
}
Used by stackers to validate a proposed Stacks block from a miner. This API endpoint requires a basic Authorization header.
Hex-encoded block data
Chain ID for the block
Block proposal has been accepted for processing. The result will be returned via the event observer.
Bad Request
Unauthorized. Invalid or missing authentication token.
There is an ongoing proposal validation being processed, the new request cannot be accepted until the prior request has been processed.
Internal Server Error
POST /v3/block_proposal HTTP/1.1
Host: localhost:20443
authorization: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 73
{
"$ref": "./components/examples/post-block-proposal-request.example.json"
}
{
"$ref": "./components/examples/post-block-proposal-response.example.json"
}
Used to get stacker and signer set information for a given cycle.
This will only return information for cycles started in Epoch-2.5 where PoX-4 was active and subsequent cycles.
reward cycle number
Information for the given reward cycle
Could not fetch the given reward set
GET /v3/stacker_set/{cycle_number} HTTP/1.1
Host: localhost:20443
Accept: */*
{
"$ref": "./components/examples/get-stacker-set.example.json"
}
Get a specific Nakamoto block (Stacks 3.x+) by its index block hash. This endpoint streams the block data from the Nakamoto staging blocks database where Nakamoto blocks are stored with additional metadata including tenure information.
Compatibility: Works with Nakamoto blocks only. For Stacks 2.x blocks, use /v2/blocks/{block_id}
.
The block"s ID hash
The raw SIP-003-encoded block will be returned.
Bad request
Not found
Internal Server Error
GET /v3/blocks/{block_id} HTTP/1.1
Host: localhost:20443
Accept: */*
binary
Fetch a Nakamoto block by its height and optional tip.
The block's height
The raw SIP-003-encoded block will be returned.
Bad request
Not found
Internal Server Error
GET /v3/blocks/height/{block_height} HTTP/1.1
Host: localhost:20443
Accept: */*
binary
Fetch metadata about the ongoing Nakamoto tenure. This information is sufficient to obtain and authenticate the highest complete tenure, as well as obtain new tenure blocks.
Metadata about the ongoing tenure
GET /v3/tenures/info HTTP/1.1
Host: localhost:20443
Accept: */*
Metadata about the ongoing tenure
{
"$ref": "./components/examples/get-tenure-info.example.json"
}
Fetch a sequence of Nakamoto blocks in a tenure. The blocks will be served in order from highest to lowest. The blocks will be encoded in their SIP-003 wire format, and concatenated together.
The tenure-start block ID of the tenure to query
The block ID hash of the highest block in this tenure that is already known to the caller. Neither the corresponding block nor any of its ancestors will be served. This is used to fetch tenure blocks that the caller does not have.
SIP-003-encoded Nakamoto blocks, concatenated together
GET /v3/tenures/{block_id} HTTP/1.1
Host: localhost:20443
Accept: */*
SIP-003-encoded Nakamoto blocks, concatenated together
binary
Last updated
Was this helpful?