Browse Source

feat: merge rpc and stacks api references

fix/update-miner-config
Alexander Graebe 4 years ago
parent
commit
76d96b4965
  1. 7
      next.config.js
  2. 1
      src/common/navigation.yaml
  3. 5
      src/includes/different_apis.md
  4. 19
      src/pages/references/stacks-blockchain.md
  5. 278
      src/pages/references/stacks-rpc-api.md

7
next.config.js

@ -285,7 +285,7 @@ async function redirects() {
},
{
source: '/core/smart/rpc-api.html',
destination: '/references/stacks-rpc-api',
destination: '/references/stacks-blockchain',
permanent: true,
},
{
@ -414,6 +414,11 @@ async function redirects() {
destination: '/storage-hubs/amazon-ec2-deploy',
permanent: true,
},
{
source: '/references/stacks-rpc-api',
destination: '/references/stacks-blockchain',
permanent: true,
},
];
}

1
src/common/navigation.yaml

@ -109,7 +109,6 @@ sections:
- path: /blockstack-cli
- path: /language-clarity
- path: /stacks-blockchain
- path: /stacks-rpc-api
- external:
href: 'https://blockstack.github.io/blockstack.js/'
title: blockstack.js

5
src/includes/different_apis.md

@ -1,5 +0,0 @@
## Difference between Blockchain API and Stacks Node RPC API
The Stacks 2.0 Blockchain API is a centrally-hosted API that is accessible via the internet and enables interactions with the publicly-viewable state of the Stacks 2.0 blockchain, including transaction, account, and smart contract data.
The [Node RPC API](/references/stacks-rpc-api) is locally-hosted and runs on Stacks 2.0 Blockchain nodes, providing similar functionality but in a way that is scoped to that specific node, giving access to raw transaction data as the node sees it.

19
src/pages/references/stacks-blockchain.md

@ -13,8 +13,23 @@ The Stacks 2.0 Blockchain API was built to maintain pageable materialized views
A generated JS Client is available for consumption of this API. The client library enables typesafe REST and WebSocket communication. [Please review the client documentation for more details](https://blockstack.github.io/stacks-blockchain-api/client/index.html).
@include "different_apis.md"
## Stacks Node RPC API
The Stacks 2.0 Blockchain 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.
-> The Stacks Blockchain API proxies to Node RPC endpoints
While the Node RPC API doesn't give the same functionality as the hosted Stacks 2.0 Blockchain API, you get similar functionality in a way that is scoped to that specific node. The RPC API includes the following endpoints:
- [POST /v2/transactions](https://blockstack.github.io/stacks-blockchain-api/#operation/post_core_node_transactions)
- [GET /v2/contracts/interface/{stacks_address}/{contract_name}](https://blockstack.github.io/stacks-blockchain-api/#operation/get_contract_interface)
- [POST /v2/map_entry/{stacks_address}/{contract_name}/{map_name}](https://blockstack.github.io/stacks-blockchain-api/#operation/get_contract_data_map_entry)
- [GET /v2/contracts/source/{stacks_address}/{contract_name}](https://blockstack.github.io/stacks-blockchain-api/#operation/get_contract_source)
- [GET /v2/accounts/{principal}](https://blockstack.github.io/stacks-blockchain-api/#operation/get_account_info)
- [POST /v2/contracts/call-read/{stacks_address}/{contract_name}/{function_name}](https://blockstack.github.io/stacks-blockchain-api/#operation/call_read_only_function)
- [GET /v2/fees/transfer](https://blockstack.github.io/stacks-blockchain-api/#operation/get_fee_transfer)
- [GET /v2/info](https://blockstack.github.io/stacks-blockchain-api/#operation/get_core_api_info)
## Legacy API
-> If you are looking for the Stacks 1.0 RPC endpoint references, please follow [this link](https://core.blockstack.org/).
If you are looking for the Stacks 1.0 RPC endpoint references, please follow [this link](https://core.blockstack.org/).

278
src/pages/references/stacks-rpc-api.md

@ -1,278 +0,0 @@
---
title: Stacks Node RPC API
description: Every running Stacks node exposes an RPC API, which allows you to interact with the underlying blockchain.
---
## Introduction
Every running Stacks node exposes an RPC API, which allows you to interact with the underlying blockchain.
@include "different_apis.md"
### POST /v2/transactions
This endpoint is for posting _raw_ transaction data to the node's mempool.
Rejections result in a 400 error.
### GET /v2/accounts/[Principal]
Get the account data for the provided principal.
The principal string is either a Stacks address or a Contract identifier (e.g.,
`SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info`
Returns JSON data in the form:
```json
{
"balance": "0x100..",
"nonce": 1,
"balance_proof": "0x01fa...",
"nonce_proof": "0x01ab..."
}
```
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.
This endpoint also accepts a querystring parameter `?proof=` which when supplied `0`, will return the
JSON object _without_ the `balance_proof` or `nonce_proof` fields.
### POST /v2/map_entry/[Stacks Address]/[Contract Name]/[Map Name]
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 atom.
Returns JSON data in the form:
```json
{
"data": "0x01ce...",
"proof": "0x01ab..."
}
```
Where data is 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.
This endpoint also accepts a querystring parameter `?proof=` which when supplied `0`, will return the
JSON object _without_ the `proof` field.
### GET /v2/fees/transfer
Get an estimated fee rate for STX transfer transactions. This a a fee rate / byte, and is returned as a JSON integer.
### GET /v2/contracts/interface/[Stacks Address]/[Contract Name]
Fetch the contract interface for a given contract, identified by [Stacks Address] and [Contract Name].
This returns a JSON object of the form:
```json
{
"functions": [
{
"name": "exotic-block-height",
"access": "private",
"args": [
{
"name": "height",
"type": "uint128"
}
],
"outputs": {
"type": "bool"
}
},
{
"name": "update-info",
"access": "public",
"args": [],
"outputs": {
"type": {
"response": {
"ok": "bool",
"error": "none"
}
}
}
},
{
"name": "get-exotic-data-info",
"access": "read_only",
"args": [
{
"name": "height",
"type": "uint128"
}
],
"outputs": {
"type": {
"tuple": [
{
"name": "btc-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "burn-block-time",
"type": "uint128"
},
{
"name": "id-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "stacks-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "stacks-miner",
"type": "principal"
},
{
"name": "vrf-seed",
"type": {
"buffer": {
"length": 32
}
}
}
]
}
}
}
],
"variables": [],
"maps": [
{
"name": "block-data",
"key": [
{
"name": "height",
"type": "uint128"
}
],
"value": [
{
"name": "btc-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "burn-block-time",
"type": "uint128"
},
{
"name": "id-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "stacks-hash",
"type": {
"buffer": {
"length": 32
}
}
},
{
"name": "stacks-miner",
"type": "principal"
},
{
"name": "vrf-seed",
"type": {
"buffer": {
"length": 32
}
}
}
]
}
],
"fungible_tokens": [],
"non_fungible_tokens": []
}
```
### GET /v2/contracts/source/[Stacks Address]/[Contract Name]
Fetch the source for a smart contract, along with the block height it was
published in, and the MARF proof for the data.
```json
{
"source": "(define-private ...",
"publish_height": 1,
"proof": "0x00213..."
}
```
This endpoint also accepts a querystring parameter `?proof=` which
when supplied `0`, will return the JSON object _without_ the `proof`
field.
### POST /v2/contracts/call-read/[Stacks Address]/[Contract Name]/[Function Name]
Call a read-only public function on a given smart contract.
The smart contract and function are specified using the URL path. The arguments and
the simulated `tx-sender` are supplied via the POST body in the following JSON format:
```json
{
"sender": "SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info",
"arguments": ["0x0011...", "0x00231..."]
}
```
Where sender is either a Contract identifier or a normal Stacks address, and arguments
is an array of hex serialized Clarity values.
This endpoint returns a JSON object of the following form:
```json
{
"okay": true,
"result": "0x0011..."
}
```
Where `"okay"` is `true` if the function executed successfully, and result contains the
hex serialization of the Clarity return value.
If an error occurs in processing the function call, this endpoint returns a 200 response with a JSON
object of the following form:
```json
{
"okay": false,
"cause": "Unchecked(PublicFunctionNotReadOnly(..."
}
```
Loading…
Cancel
Save