Firstly, what is Blockstack (Software for a user owned internet)? (Official site: https://docs.blockstack.org/) In short the goal of Blockstack is to provide a safe, secure and private browsing experience for users. Blockstack apps give users direct ownership of their internet assets and protect their privacy. You need a login ID / name that is secured by a private / public key on your machine. This ID allows you to log in to any of the over 400 Blockstack-enabled apps (See the apps on the web-enabled blockstack browser - https://browser.blockstack.org/) without having to share any details with the app owner. Any data that is needed is typically stored in encrypted format on your own Gaia storage, once again, not giving any access to the app owner. This is a giant leap forward toward Internet 3.0... and gain back leverage from the giants like Amazon, Google and Facebook who like to use your data to enrich themselves...
Last week Blockstack launched it's Stacks 2.0 Testnet to the Blockstack community so that the code and functionality can be fully vetted before launching the Mainnet. In this blog I will describe the process I took to launch a Stacks 2.0 Testnet node on my MS Azure account running an Ubunto Virtual Machine (VM). For the standard documentation process check out the documentation located at https://docs.blockstack.org/core/smart/neon-node.html.
After firing up your VM and connecting to a terminal session follow these steps:
STEP 1 - Install
A. Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
B. Clone the blockstack repository
cd stacks-blockchain
C. Build project
cargo build
D. Run tests:
cargo test test-net -- --test-threads=1
STEP 2 - Generate Keys
Run the following command:
cargo run --bin blockstack-cli generate-sk --testnet
NOTE: Keep a copy of the Keys and Stacks address generated. I have color coordinated them so that you can relate them to the commands that follow.
"secretKey": "aa478bbd514a595d9158afe8dbc28f2a80e91912f927ee626854c5519cd97f5801", "publicKey": "0349da4a4add9f5f28f37893b33384391ab55782dff1f8889c887273b6a1aae3d3", "stacksAddress": "ST2VE5BFP1MYV1PGCBYBVWNASV809BATRFPZA591A"
STEP 3 - Create Contract in Clarity
Create a smart contract file called "kv-store.clar" in the stacks-blockchain folder
(define-map store ((key (buff 32))) ((value (buff 32))))
(define-public (get-value (key (buff 32)))
(match (map-get? store {key: key})
entry (ok (get value entry))
(err 0)))
(define-public (set-value (key (buff 32)) (value (buff 32)))
(begin
(map-set store {key: key} {value: value})
(ok true)))
STEP 4 - Give yourself some STX
Update STX balance in the testnet/Stacks.toml file. Append the following 3 lines to the file:
[[mstx_balance]]
address = "ST2VE5BFP1MYV1PGCBYBVWNASV809BATRFPZA591A"
amount = 100000000
STEP 5 - Run testnet
Launch the Testnet node with the following command:
cargo testnet start --config=./testnet/Stacks.toml
You should start to see transactions coming through the log...
STEP 6 - Interact with Contract
In a separate session:
1. Publish smart contract kv-store
cargo run --bin blockstack-cli publish aa478bbd514a595d9158afe8dbc28f2a80e91912f927ee626854c5519cd97f5801 500 0 kv-store ./kv-store.clar --testnet | xxd -r -p > tx1.bin
NOTE: 500 refers to the fee for the transaction in STX tokens
NOTE: 0 (immediately following the 500 STX fee) is the nonce. We will increment it for each transaction.
1a. Publish contract: Move file tx1.bin to mempool
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx1.bin http://localhost:20443/v2/transactions
2. Read value of “foo” from contract
cargo run --bin blockstack-cli contract-call aa478bbd514a595d9158afe8dbc28f2a80e91912f927ee626854c5519cd97f5801 500 1 ST2VE5BFP1MYV1PGCBYBVWNASV809BATRFPZA591A kv-store get-value -e \"foo\" --testnet | xxd -r -p > tx2.bin
TIP: Check your initial terminal session running the testnet node to see the log of the interaction with each transaction.
2a. Submit transaction: Move tx2.bin to mempool
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx2.bin http://localhost:20443/v2/transactions
3. Set “foo” value to “bar” in contract
cargo run --bin blockstack-cli contract-call aa478bbd514a595d9158afe8dbc28f2a80e91912f927ee626854c5519cd97f5801 500 2 ST2VE5BFP1MYV1PGCBYBVWNASV809BATRFPZA591A kv-store set-value -e \"foo\" -e \"bar\" --testnet | xxd -r -p > tx3.bin
3a. Submit transaction: Move tx3.bin to mempool
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx3.bin http://localhost:20443/v2/transactions
4. Read foo value
cargo run --bin blockstack-cli contract-call aa478bbd514a595d9158afe8dbc28f2a80e91912f927ee626854c5519cd97f5801 500 3 ST2VE5BFP1MYV1PGCBYBVWNASV809BATRFPZA591A kv-store get-value -e \"foo\" --testnet | xxd -r -p > tx4.bin
4a. Submit transaction: Move tx4.bin to mempool
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @./tx4.bin http://localhost:20443/v2/transactions
That's it - If you were able to successfully process the above steps then you are Stacks 2.0 compliant...
Please leave any comments below.