Browse Source

Renaming clarity-cli to just clarity

Signed-off-by: Mary Anthony <mary@blockstack.com>
feat/clarity-updates
Mary Anthony 5 years ago
parent
commit
cf88dae115
  1. 2
      _core/smart/functions.md
  2. 14
      _core/smart/overview.md
  3. 2
      _core/smart/principals.md
  4. 2
      _core/smart/sdk-quickstart.md
  5. 44
      _core/smart/tutorial.md

2
_core/smart/functions.md

@ -13,7 +13,7 @@ Clarity includes _defines_ and native functions for creating user-defined funct
## define and define-public functions
Functions specified via `define-public` statements are public functions. Functions without these designations, simple `define` statements, are private functions. You can run a contract's public functions directly via the `clarity-cli execute` command line directly or from other contracts. You can use the `clarity eval` or `clarity eval_raw` commands to evaluate private functions via the command line.
Functions specified via `define-public` statements are public functions. Functions without these designations, simple `define` statements, are private functions. You can run a contract's public functions directly via the `clarity execute` command line directly or from other contracts. You can use the `clarity eval` or `clarity eval_raw` commands to evaluate private functions via the command line.
Public functions return a Response type result. If the function returns an `ok` type, then the function call is considered valid, and any changes made to the blockchain state will be materialized. If the function returns an `err` type, it is considered invalid, and has no effect on the smart contract's state.

14
_core/smart/overview.md

@ -44,7 +44,7 @@ Clarity is a list processing (LISP) language, as such it is not compiled. Omitti
Clarity is in pre-release and does not yet directly interact with the live Stacks blockchain. For the pre-release period you need a test environment to run Clarity contracts. Blockstack provides a Docker image called `clarity-developer-preview` that you can use or you can build a test environment locally from code. Either the Docker image or a local environment is sufficient for testing Clarity programming for standalone contracts.
You use the `clarity-cli` command line to check, launch, and execute standalone Clarity contracts. You can use this same command line to create simulate mining Stacks and inspecting a blockchain.
You use the `clarity` command line to check, launch, and execute standalone Clarity contracts. You can use this same command line to create simulate mining Stacks and inspecting a blockchain.
Blockstack expects that some decentralized applications (DApp) will want to make use of Clarity contracts as part of their applications. For this purpose, you should use the Clarity SDK, also in pre-release. The SDK is a development environment, testing framework, and deployment tool. It provides a library for safe interactions with Clarity contracts from a DApp written with the blockstack.js library.
@ -72,7 +72,7 @@ You can add comments to your Clarity contracts using `;;` (double semi-colons).
(transfer! tx-sender recipient amount)) ;; returns: boolean
```
You use the `clarity-cli` command to check and launch a Clarity (`.clar`) program.
You use the `clarity` command to check and launch a Clarity (`.clar`) program.
## hello-world example
@ -85,11 +85,11 @@ The easiest program to run in any language is a hello world program. In Clarity,
This program defines a single `hello-world` expression that is excuted when the contract launches. The `begin` is a native Clarity function that evaluates the expressions input to it and returns the value of the last expression. Here there is a single `print` expression. Both the `begin` and the `print` are enclosed in `()` parentheses.
For the pre-release, the Blockstack test environment includes the `clarity-cli` command for interacting with the contract and SQLite to support the data space. You create a SQLLite database to hold data related to Clarity contracts. This database simulates the blockchain by recording the contract activity.
For the pre-release, the Blockstack test environment includes the `clarity` command for interacting with the contract and SQLite to support the data space. You create a SQLLite database to hold data related to Clarity contracts. This database simulates the blockchain by recording the contract activity.
You can't run even an a hello-world program without first initializing a Clarity contract's data space within the database. You can use the `clarity-cli initialize` command to set up the database.
You can't run even an a hello-world program without first initializing a Clarity contract's data space within the database. You can use the `clarity initialize` command to set up the database.
```clarity-cli initialize /data/db```
```clarity initialize /data/db```
This command initializes the `db` database which resides in the `/data` directory of the container. You can name the database anything you like, the name `db` is not required. You can use SQLite to query this database:
@ -103,12 +103,12 @@ sqlite>
After you initialize the contract's data space, you can `check` a Clarity program for problems.
```clarity-cli check ./hello.clar /data/db```
```clarity check ./hello.clar /data/db```
As the name implies, the `check` ensures the contract definition passes a type check; passing programs will returns an exit code of `0` (zero). Once a contract passes a check, you `launch` it.
```bash
root@4224dd95b5f5:/data# clarity-cli launch hello ./hello.clar /data/db
root@4224dd95b5f5:/data# clarity launch hello ./hello.clar /data/db
Buffer(BuffData { data: [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] })
Contract initialized!
```

2
_core/smart/principals.md

@ -38,7 +38,7 @@ The principal's signature is not checked by the smart contract, but by the virtu
Smart contracts themselves are principals and are represented by the smart contract's identifier. You create the identifier when you launch the contract, for example, the contract identifier here is `hanomine`.
```bash
clarity-cli launch hanomine /data/hano.clar /data/db
clarity launch hanomine /data/hano.clar /data/db
```
A smart contract may use the special variable `contract-name` to refer to its own principal.

2
_core/smart/sdk-quickstart.md

@ -131,7 +131,7 @@ describe("hello world contract test suite", () => {
The `hello-world.ts` test file is a client that runs the `hello-world.clar` contract. Tests are critical for smart contracts as they are intended to manipulate assets and their ownership. These manipulations are irreversible within a blockchain. As you create a contracts, you should not be surprise if you end up spending more time and having more code in your `tests` than in your `contracts` directory. The `tests/hello-world.ts` file in the scaffold has the following content:
The first part of the test (lines 1 -10) sets up the test environment. It defines a Clarity `provider` and launches it (line 9). The Client instance contains a contract name and the path to the sample code. This test also checks the client (line 14) and then launches it (line 19), this is equivalent to running `clarity-cli check` with the command line. The remaining test code exercises the contract. Try running this test.
The first part of the test (lines 1 -10) sets up the test environment. It defines a Clarity `provider` and launches it (line 9). The Client instance contains a contract name and the path to the sample code. This test also checks the client (line 14) and then launches it (line 19), this is equivalent to running `clarity check` with the command line. The remaining test code exercises the contract. Try running this test.
```sh

44
_core/smart/tutorial.md

@ -69,7 +69,7 @@ The first line of the `tokens.clar` program contains a user-defined `get-balance
(default-to 0 (get balance (fetch-entry tokens (tuple (account account))))))
```
`get-balance` is a private function because it is constructed with the `define` call. To create public functions, you would use the `define-public` function. Public functions can be called from other contracts or even from the command line with the `clarity-cli`.
`get-balance` is a private function because it is constructed with the `define` call. To create public functions, you would use the `define-public` function. Public functions can be called from other contracts or even from the command line with the `clarity`.
Notice the program is enclosed in `()` (parentheses) and each statement as well. The `get-balance` function takes an `account` argument of the special type `principal`. Principals represent a spending entity and are roughly equivalent to a Stacks address.
@ -124,12 +124,12 @@ Which `tokens.clar` function is being called?
## Task 3: Initialize data-space and launch contracts
In this task, you interact with the the contracts using the `clarity-cli` command line.
In this task, you interact with the the contracts using the `clarity` command line.
1. Initialize a new `db` database in the `/data/` directory
```bash
# clarity-cli initialize /data/db
# clarity initialize /data/db
Database created
```
@ -138,7 +138,7 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
2. Type check the `names.clar` contract.
```bash
# clarity-cli check sample-programs/names.clar /data/db
# clarity check sample-programs/names.clar /data/db
```
You should get an error:
@ -152,7 +152,7 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
3. Type check the `tokens.clar` contract, it should pass a check as it does not use the `contract-call` function:
```bash
# clarity-cli check sample-programs/tokens.clar /data/db
# clarity check sample-programs/tokens.clar /data/db
Checks passed.
```
@ -163,7 +163,7 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
You use the `launch` command to instantiate a contract on the Stacks blockchain. If you have dependencies between contracts, for example names.clar is dependent on tokens.clar, you must launch the dependency first.
```bash
# clarity-cli launch tokens sample-programs/tokens.clar /data/db
# clarity launch tokens sample-programs/tokens.clar /data/db
Contract initialized!
```
@ -172,7 +172,7 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
5. Recheck the `names.clar` contract.
```bash
# clarity-cli check sample-programs/names.clar /data/db
# clarity check sample-programs/names.clar /data/db
```
The program should pass validation because its dependency on `tokens.clar` is fulfilled.
@ -180,7 +180,7 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
6. Instantiate the `names.clar` contract as well.
```bash
# clarity-cli launch names sample-programs/names.clar /data/db
# clarity launch names sample-programs/names.clar /data/db
```
## Task 4. Examine the SQLite database
@ -188,13 +188,13 @@ In this task, you interact with the the contracts using the `clarity-cli` comman
The test environment uses a SQLite database to represent the blockchain. You initialized this database when you ran this earlier:
```bash
clarity-cli initialize /data/db
clarity initialize /data/db
```
As you work the contracts, data is added to the `db` database because you pass this database as a parameter, for example:
```bash
clarity-cli launch tokens sample-programs/tokens.clar /data/db
clarity launch tokens sample-programs/tokens.clar /data/db
```
The database exists on your local workstation and persists through restarts of the container. You can use this database to examine the effects of your Clarity programs. The tables in the SQLite database are the following:
@ -242,7 +242,7 @@ In this section, you use the public `mint!` function in the `tokens` contract t
1. Use the `clarity_cli` command to create a demo address.
```
# clarity-cli generate_address
# clarity generate_address
SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG
```
@ -255,7 +255,7 @@ In this section, you use the public `mint!` function in the `tokens` contract t
3. Get the current balance of your new address.
```bash
# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db
# echo "(get-balance '$DEMO_ADDRESS)" | clarity eval tokens /data/db
Program executed successfully! Output:
0
```
@ -265,15 +265,15 @@ In this section, you use the public `mint!` function in the `tokens` contract t
4. Try minting some tokens and sending them to an address we'll use for our demo.
```bash
# clarity-cli execute /data/db tokens mint! $DEMO_ADDRESS 100000
# clarity execute /data/db tokens mint! $DEMO_ADDRESS 100000
```
This executes the public `mint!` function defined in the tokens contract, sending 100000 tokens to you `$DEMO_ADDRESS`.
5. Use the `clarity-cli eval` command to check the result of this call.
5. Use the `clarity eval` command to check the result of this call.
```bash
# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db
# echo "(get-balance '$DEMO_ADDRESS)" | clarity eval tokens /data/db
Program executed successfully! Output:
100000
```
@ -287,7 +287,7 @@ Now, let's register a name using the `names.clar` contract. Names are just integ
You'll _salt_ the hash with the salt `8888`:
```bash
# echo "(hash160 (xor 10 8888))" | clarity-cli eval names /data/db
# echo "(hash160 (xor 10 8888))" | clarity eval names /data/db
Program executed successfully! Output:
0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde
```
@ -301,7 +301,7 @@ Now, let's register a name using the `names.clar` contract. Names are just integ
2. Preorder the name using the _execute_ command:
```bash
# clarity-cli execute /data/db names preorder $DEMO_ADDRESS 0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde 1000
# clarity execute /data/db names preorder $DEMO_ADDRESS 0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde 1000
Transaction executed and committed. Returned: 0
```
@ -310,7 +310,7 @@ Now, let's register a name using the `names.clar` contract. Names are just integ
3. Check the demo address' new balance:
```bash
# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db
# echo "(get-balance '$DEMO_ADDRESS)" | clarity eval tokens /data/db
Program executed successfully! Output:
99000
```
@ -318,14 +318,14 @@ Now, let's register a name using the `names.clar` contract. Names are just integ
4. Register the name by executing the _register_ function:
```bash
# clarity-cli execute /data/db names register $DEMO_ADDRESS \'$DEMO_ADDRESS 10 8888
Transaction executed and committed. Returned: 0clarity-cli execute /data/db names register $DEMO_ADDRESS \'$DEMO_ADDRESS 10 8888
# clarity execute /data/db names register $DEMO_ADDRESS \'$DEMO_ADDRESS 10 8888
Transaction executed and committed. Returned: 0clarity execute /data/db names register $DEMO_ADDRESS \'$DEMO_ADDRESS 10 8888
```
5. Lookup the "owner address" for the name:
```bash
# echo "(get owner (fetch-entry name-map (tuple (name 10))))" | clarity-cli eval names /data/db
# echo "(get owner (fetch-entry name-map (tuple (name 10))))" | clarity eval names /data/db
Program executed successfully! Output:
(some 'SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG)
```
@ -334,4 +334,4 @@ Now, let's register a name using the `names.clar` contract. Names are just integ
{:.no_toc}
* <a href="clarityRef.html">Clarity Language Reference</a>
* <a href="clarityRef.html">clarity-cli command line</a>
* <a href="clarityRef.html">clarity command line</a>
Loading…
Cancel
Save