Browse Source

feat: add neon node docs, RPC docs (#551)

* feat: add neon node docs

* docs: update peer_host for real DNS

* docs: more cleanup of neon page

* docs: optimized neon binary

* fix: typo in follower-conf filename

* feat: add info for re-installing rust toolchain

* feat: add RPC API docs

* docs: copy changes on RPC page
revert-567-feat/cli-testnet-updates
Hank Stoever 5 years ago
committed by GitHub
parent
commit
c33846b18d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      _core/images/rust-install.png
  2. 87
      _core/smart/neon-node.md
  3. 280
      _core/smart/rpc-api.md
  4. 2
      _data/navigation_smart.yml

BIN
_core/images/rust-install.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

87
_core/smart/neon-node.md

@ -1,17 +1,17 @@
---
layout: core
description: "Blockstack smart contracting language"
layout: smart
description: "Run a Stacks Testnet Node"
permalink: /:collection/:path.html
---
# Running a Neon Testnet Node
{:.no_toc}
"Neon" is phase 1 of the Stacks 2.0 testnet. In Neon, you can run a Stacks node and participate in proof-of-burn mining.
"Neon" is phase 1 of the Stacks 2.0 testnet. In Neon, you can run a node and connect it to a public network. This guide will walk you through downloading and running your own node in the Neon network.
* TOC
{:toc}
### Download and build stacks-blockchain
### Download the `stacks-blockchain` repository
The first step is to ensure that you have Rust and the support software installed.
@ -19,7 +19,11 @@ The first step is to ensure that you have Rust and the support software installe
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
From there, you can clone this repository:
If you already have the Rust toolchain installed, you might see this prompt. Select 'Proceed with Installation' to make sure you have the latest version installed.
![rustup prompt](/core/images/rust-install.png)
Next, clone this repository:
```bash
git clone https://github.com/blockstack/stacks-blockchain.git
@ -27,64 +31,57 @@ git clone https://github.com/blockstack/stacks-blockchain.git
cd stacks-blockchain
```
Then build the project:
### Configure your node to connect to the Neon network
```bash
cargo build
```
You'll need to update your node's configuration to connect to the public Neon testnet.
Building the project on ARM:
In the `stacks-blockchain` repository, open up the file `testnet/follower-conf.toml`.
```bash
cargo build --features "aarch64" --no-default-features
```
### Setup your Proof-of-Burn miner
First, find the `bootstrap_node` line in the `[node]` section, and update it to the following:
In this phase of the testnet, miners will be burning BTC to participate in leader election. In order to mine, you'll need to configure your node with a BTC keychain, and you'll need to fund it with BTC. We're providing a BTC faucet to make it easy to run a miner.
```toml
bootstrap_node = "048dd4f26101715853533dee005f0915375854fd5be73405f679c1917a5d4d16aaaf3c4c0d7a9c132a36b8c5fe1287f07dad8c910174d789eb24bdfb5ae26f5f27@35.245.47.179:20444"
```
Let's start by generating a keypair:
Next, find the uncommented `peer_host` line in the `[burnchain]` section, and update it to:
```bash
cargo run --bin blockstack-cli generate-sk --testnet
# Output
# {
# secretKey: "b8d99fd45da58038d630d9855d3ca2466e8e0f89d3894c4724f0efc9ff4b51f001",
# publicKey: "02781d2d3a545afdb7f6013a8241b9e400475397516a0d0f76863c6742210539b5",
# stacksAddress: "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH"
# }
```toml
peer_host = "35.245.47.179"
```
**TODO**: guidance / update on generating a BTC address from this keypair.
### Run your node
Once you have your BTC address, head over to our testnet website to use the BTC faucet:
You're all set to run a node that connects to the Neon network.
**TODO**: URL, guidance for BTC faucet
Back in the command line, run:
Now that you have some testnet BTC, you'll need to configure your Stacks node to use this wallet.
```bash
cargo testnet ./testnet/follower-conf.toml
```
Open up the file `testnet/Stacks.toml`. Find the section that starts with `[burnchain]`. Update that section so that it looks like this:
The first time you run this, you'll see some logs indicating that the Rust code is being compiled. Once that's done, you should see some logs that look something like the this:
```toml
[burnchain]
chain = "bitcoin"
mode = "neon"
peer_host = "127.0.0.1" # todo(ludo): update URL with neon.blockstack.org when deployed
burnchain_op_tx_fee = 1000
commit_anchor_block_within = 10000
rpc_port = 3000
peer_port = 18444
```
Starting testnet with config ./testnet/follower-conf.toml...
Transactions can be posted on the endpoint:
POST http://127.0.0.1:9001/v2/transactions
INFO [1587602447.879] [src/chainstate/stacks/index/marf.rs:732] First-ever block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206
```
**TODO**: update `peer_host`, and how do you specify your BTC keychain?
Awesome! Your node is now connected to the Neon network. Your node will receive new blocks when they are produced, and you can use your [node's RPC API](/core/smart/rpc-api) to send transactions, fetch information for contracts and accounts, and more.
### Running your mining node
### Creating an optimized binary
Now that you're all set up, you can run your miner. In the command line, run:
The steps above are great for trying to run a node temporarily. If you want to host a node on a server somewhere, you might want to generate an optimized binary. To do so, use the same configuration as above, but run:
```bash
cargo testnet ./testnet/Stacks.toml
cd testnet
cargo build --release --bin stacks-testnet
cd ..
```
**TODO**: some way of confirming that the miner is running - expected logs, explorer, etc?
The above code will compile an optimized binary. To use it, run:
```bash
./target/release/stacks-testnet ./testnet/follower-conf.toml
```

280
_core/smart/rpc-api.md

@ -0,0 +1,280 @@
---
layout: smart
description: "Stacks Node RPC API Reference"
permalink: /:collection/:path.html
---
# RPC API Reference
{:.no_toc}
Every running Stacks node exposes an RPC API, which allows you to interact with the underlying blockchain.
* TOC
{:toc}
### 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(..."
}
```

2
_data/navigation_smart.yml

@ -11,9 +11,11 @@
docs:
- core/smart/principals
- core/smart/functions
- core/smart/neon-node
- title: References
docs:
- core/smart/clarityRef
- core/smart/clarityCLI
- core/smart/sdk-quickstart
- core/smart/rpc-api

Loading…
Cancel
Save