163
Views

Anyone with link-building experience in Nigeria?

Reply

moshenkos posted a question • 1 users followed • 0 replies • 163 views • 2020-06-10 00:52 • data from similar tags

151
Views

How To Run a Stacks Testnet Node 如何运行一个stacks 测试网络节点

NaMillion posted the article • 0 comments • 151 views • 2020-06-03 15:55 • data from similar tags

Run a Stacks Testnet Node
运行一个stacks 测试网络节点

“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.
“Neon” 是Stacks 2.0测试网络的第一个版本,通过“Neon”, 您可以通过运行一个服务器节点并把它连接到一个公共网络。这篇教程将会指导您在“Neon”网络中,如何下载并运行您自己的服务器节点。

* Prerequisites  前期准备
* Download and install the stacks-blockchain repository 下载并安装stacks区块链库
* Run your node  运行节点
* Running a miner  运行挖矿程序
* Creating an optimized binary   生成一个优化过的二进制
* Enable debug logging  打开调试日志

Prerequisites 前期准备
Note: If you use Linux, you may need to manually install libssl-dev and other packages. In your command line, run the following to get all packages:
请注意:如果您使用linux,您也许需要人工安装 libssl-dev 和其他的程序安装包。在您的命令行终端中运行下面的命令,获得所有的安装包。sudo apt-get install build-essential cmake libssl-dev pkg-config

Download and install the stacks-blockchain repository
下载并安装 stacks区块链库

The first step is to ensure that you have Rust installed. If you are using macOS, Linux, or another Unix-like OS, run the following. If you are on a different OS, follow the official Rust installation guide.
第一步是为了确保您已经安装了Rust,如果您现在正在使用macos,linux,或者其他的Unix系统。您可以运行下面的命令,如果您使用其他的操作系统,请参考这篇 官方Rust安装指南.curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

If Rust is already installed, you might see this prompt. Select ‘Proceed with Installation’ to make sure you have the latest version installed.
如果Rust已经安装,您应该会看到下面的提示,选择‘Proceed with Installation’ 来确保您已经安装了最新的版本。

In case you just installed Rust, you will be prompted to run the following command to make the cargo command available:
为了确保您已经安装了Rust, 您会收到一个提示让您运行下面的命令,从而使cargo 命令有效。source $HOME/.cargo/env

Next, clone this repository:
下一步,克隆这个库:git clone https://github.com/blockstack/ ... n.git
cd stacks-blockchain

Install the Stacks node by running:
执行下面的命令,来安装Stacks 节点:cargo install --path ./testnet/stacks-node

Run your node
运行您的服务器节点

You’re all set to run a node that connects to the Neon network.
Back in the command line, run:
您已经准备好了运行一个节点来连接到Neon 网络,返回到命令行,运行下面的命令:stacks-node neon
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:
当你第一次运行这个命令,您将会看到一些日志表明这个Rust节点正在被编译。一旦编译完成,您会看到类似下面的一些日志:

INFO [1588108047.585] [src/chainstate/stacks/index/marf.rs:732] First-ever block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206

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 to send transactions, fetch information for contracts and accounts, and more.
很好!您的节点已经链接到这个Neon网络了,当出块时,您的电脑会接收到新的区块,并且您可以使用node’s RPC API 来发送交易, 为智能合同程序和账户取回信息,等等。

Running a miner
运行一个挖矿程序

Once you’ve followed the above steps to run a node, it’s only a few more steps to run a Proof-of-burn miner on the Neon testnet.
如果您已经完成了上面所有的步骤,您可以通过下面的方法来运行一个Proof-of-burn的挖矿程序,部署在Neon测试网络上。

First, we need to generate a keychain. With this keychain, we’ll get some testnet BTC from a faucet, and then use that BTC to start mining.
首先,我们需要生存一个keychain,通过keychain,我们可以从一个“水龙头”得到一些测试网络的比特币,并用这些比特币来开始挖矿。

To get a keychain, the simplest way is to use the blockstack-cli. We’ll use the make_keychain command, and pass -t to indicate that we want a testnet keychain.
为了得到一个keychain,最简单的方法就是使用blockstack-cli,我们要用到make_keychain命令 和 pass -t 来表明我们希望得到一个测试网络的keychain。

npx [email protected] make_keychain -t
After this runs, you’ll probably see some installation logs, and at the end you should see some JSON that looks like this:
执行这个命令后,您会看到一些安装日志,最后您会看到一些json代码,显示如下:
 {
"mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur",
"keyInfo": {
"privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801",
"address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF",
"btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND",
"index": 0
}
}
We need to get some testnet BTC to that address. Grab the btcAddress field, and head over to the Stacks testnet website. In the BTC faucet section, past in your btcAddress, and submit. You’ll be sent 0.5 testnet BTC to that address. Don’t lose this information - we’ll need to use the privateKey field later on.
我们需要一些测试网络的比特币转移到那个地址,请备份好btcAddress 字段,然后跳转到 stacks测试网络官网.  在比特币“水龙头”部分 , 粘贴您的btcAddress 然后提交。您需要发送0.5测试网络的比特币到这个地址。不要弄丢这些信息-因为我们还要继续使用这个私钥字段。

Now, we need to configure out node to use this Bitcoin keychain. In the stacks-blockchain folder, create a new file called testnet/stacks-node/conf/neon-miner-conf.toml.
Paste in the following configuration:
现在, 我们需要配置节点来使用比特币 keychain, 在stacks-blockchain文件夹里面,新建一个文件并命名为testnet/stacks-node/conf/neon-miner-conf.toml. 把下面的命令粘贴进去。
 [node]
rpc_bind = "0.0.0.0:20443"
p2p_bind = "0.0.0.0:20444"
bootstrap_node = "048dd4f26101715853533dee005f0915375854fd5be73405f679c1917a5d4d16aaa[email protected]neon.blockstack.org:20444"
# Enter your private key here!
# 在这里输入您的私钥!
seed = "replace-with-your-private-key"
miner = true
[burnchain]
chain = "bitcoin"
mode = "neon"
peer_host = "neon.blockstack.org"
rpc_port = 18443
peer_port = 18444
[[mstx_balance]]
address = "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"
amount = 10000000000000000
[[mstx_balance]]
address = "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y"
amount = 10000000000000000
[[mstx_balance]]
address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR"
amount = 10000000000000000
[[mstx_balance]]
address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP"
amount = 10000000000000000


Now, grab your privateKey from earlier, when you ran the make_keychain command. Replace the seed field with your private key. Save and close this configuration file.
现在,拿好您之前得到的私钥,当你运行make_keychain 命令时, 用您的私钥来填写seed字段, 并保存并关闭这个配置文件。

To run your miner, run this in the command line:
为了运行您的挖矿程序,请运行下面的命令:
 stacks-node start --config=./testnet/stacks-node/conf/neon-miner-conf.toml
Your node should start. It will take some time to sync, and then your miner will be running!
您的节点现在可以开始工作了,它需要花费一些时间来同步,然后您的挖矿程序就可以工作了!

Creating an optimized binary 
生成一个优化过的二进制

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:
以上的步骤是用来运行一个临时的节点,如果您希望配置一个节点在一台服务器上,您可能希望生成一个优化过的二进制。为了实现这一点,请同样执行上面的步骤,然后运行:cd testnet/stacks-node
cargo build --release --bin stacks-node

The above code will compile an optimized binary. To use it, run:
上面的代码将会编译一个优化过的二进制,为了用它,请运行下面的命令:
 cd ../..
./target/release/stacks-node start --config=./testnet/conf/neon-follower-conf.toml

Enable debug logging  启用调试日志功能
In case you are running into issues or would like to see verbose logging, you can run your node with debug logging enabled. In the command line, run:
运行过程中, 为了防止您碰到问题或者看到冗长的日志,您可以在您的节点上开启调试日志功能,请直接运行下面的命令:BLOCKSTACK_DEBUG=1 stacks-node neon view all
Run a Stacks Testnet Node
运行一个stacks 测试网络节点


“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.
“Neon” 是Stacks 2.0测试网络的第一个版本,通过“Neon”, 您可以通过运行一个服务器节点并把它连接到一个公共网络。这篇教程将会指导您在“Neon”网络中,如何下载并运行您自己的服务器节点。

* Prerequisites  前期准备
* Download and install the stacks-blockchain repository 下载并安装stacks区块链库
* Run your node  运行节点
* Running a miner  运行挖矿程序
* Creating an optimized binary   生成一个优化过的二进制
* Enable debug logging  打开调试日志

Prerequisites 前期准备
Note: If you use Linux, you may need to manually install libssl-dev and other packages. In your command line, run the following to get all packages:
请注意:如果您使用linux,您也许需要人工安装 libssl-dev 和其他的程序安装包。在您的命令行终端中运行下面的命令,获得所有的安装包。
sudo apt-get install build-essential cmake libssl-dev pkg-config


Download and install the stacks-blockchain repository
下载并安装 stacks区块链库


The first step is to ensure that you have Rust installed. If you are using macOS, Linux, or another Unix-like OS, run the following. If you are on a different OS, follow the official Rust installation guide.
第一步是为了确保您已经安装了Rust,如果您现在正在使用macos,linux,或者其他的Unix系统。您可以运行下面的命令,如果您使用其他的操作系统,请参考这篇 官方Rust安装指南.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh


If Rust is already installed, you might see this prompt. Select ‘Proceed with Installation’ to make sure you have the latest version installed.
如果Rust已经安装,您应该会看到下面的提示,选择‘Proceed with Installation’ 来确保您已经安装了最新的版本。

In case you just installed Rust, you will be prompted to run the following command to make the cargo command available:
为了确保您已经安装了Rust, 您会收到一个提示让您运行下面的命令,从而使cargo 命令有效。
source $HOME/.cargo/env


Next, clone this repository:
下一步,克隆这个库:
git clone https://github.com/blockstack/ ... n.git
cd stacks-blockchain


Install the Stacks node by running:
执行下面的命令,来安装Stacks 节点:
cargo install --path ./testnet/stacks-node


Run your node
运行您的服务器节点


You’re all set to run a node that connects to the Neon network.
Back in the command line, run:
您已经准备好了运行一个节点来连接到Neon 网络,返回到命令行,运行下面的命令:
stacks-node neon

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:
当你第一次运行这个命令,您将会看到一些日志表明这个Rust节点正在被编译。一旦编译完成,您会看到类似下面的一些日志:

INFO [1588108047.585] [src/chainstate/stacks/index/marf.rs:732] First-ever block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206

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 to send transactions, fetch information for contracts and accounts, and more.
很好!您的节点已经链接到这个Neon网络了,当出块时,您的电脑会接收到新的区块,并且您可以使用node’s RPC API 来发送交易, 为智能合同程序和账户取回信息,等等。

Running a miner
运行一个挖矿程序


Once you’ve followed the above steps to run a node, it’s only a few more steps to run a Proof-of-burn miner on the Neon testnet.
如果您已经完成了上面所有的步骤,您可以通过下面的方法来运行一个Proof-of-burn的挖矿程序,部署在Neon测试网络上。

First, we need to generate a keychain. With this keychain, we’ll get some testnet BTC from a faucet, and then use that BTC to start mining.
首先,我们需要生存一个keychain,通过keychain,我们可以从一个“水龙头”得到一些测试网络的比特币,并用这些比特币来开始挖矿。

To get a keychain, the simplest way is to use the blockstack-cli. We’ll use the make_keychain command, and pass -t to indicate that we want a testnet keychain.
为了得到一个keychain,最简单的方法就是使用blockstack-cli,我们要用到make_keychain命令 和 pass -t 来表明我们希望得到一个测试网络的keychain。

npx [email protected] make_keychain -t

After this runs, you’ll probably see some installation logs, and at the end you should see some JSON that looks like this:
执行这个命令后,您会看到一些安装日志,最后您会看到一些json代码,显示如下:
 
{
"mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur",
"keyInfo": {
"privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801",
"address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF",
"btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND",
"index": 0
}
}

We need to get some testnet BTC to that address. Grab the btcAddress field, and head over to the Stacks testnet website. In the BTC faucet section, past in your btcAddress, and submit. You’ll be sent 0.5 testnet BTC to that address. Don’t lose this information - we’ll need to use the privateKey field later on.
我们需要一些测试网络的比特币转移到那个地址,请备份好btcAddress 字段,然后跳转到 stacks测试网络官网.  在比特币“水龙头”部分 , 粘贴您的btcAddress 然后提交。您需要发送0.5测试网络的比特币到这个地址。不要弄丢这些信息-因为我们还要继续使用这个私钥字段。

Now, we need to configure out node to use this Bitcoin keychain. In the stacks-blockchain folder, create a new file called testnet/stacks-node/conf/neon-miner-conf.toml.
Paste in the following configuration:
现在, 我们需要配置节点来使用比特币 keychain, 在stacks-blockchain文件夹里面,新建一个文件并命名为testnet/stacks-node/conf/neon-miner-conf.toml. 把下面的命令粘贴进去。
 
[node]
rpc_bind = "0.0.0.0:20443"
p2p_bind = "0.0.0.0:20444"
bootstrap_node = "048dd4f26101715853533dee005f0915375854fd5be73405f679c1917a5d4d16aaa[email protected]neon.blockstack.org:20444"
# Enter your private key here!
# 在这里输入您的私钥!
seed = "replace-with-your-private-key"
miner = true
[burnchain]
chain = "bitcoin"
mode = "neon"
peer_host = "neon.blockstack.org"
rpc_port = 18443
peer_port = 18444
[[mstx_balance]]
address = "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"
amount = 10000000000000000
[[mstx_balance]]
address = "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y"
amount = 10000000000000000
[[mstx_balance]]
address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR"
amount = 10000000000000000
[[mstx_balance]]
address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP"
amount = 10000000000000000



Now, grab your privateKey from earlier, when you ran the make_keychain command. Replace the seed field with your private key. Save and close this configuration file.
现在,拿好您之前得到的私钥,当你运行make_keychain 命令时, 用您的私钥来填写seed字段, 并保存并关闭这个配置文件。

To run your miner, run this in the command line:
为了运行您的挖矿程序,请运行下面的命令:
 
stacks-node start --config=./testnet/stacks-node/conf/neon-miner-conf.toml

Your node should start. It will take some time to sync, and then your miner will be running!
您的节点现在可以开始工作了,它需要花费一些时间来同步,然后您的挖矿程序就可以工作了!

Creating an optimized binary 
生成一个优化过的二进制

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:
以上的步骤是用来运行一个临时的节点,如果您希望配置一个节点在一台服务器上,您可能希望生成一个优化过的二进制。为了实现这一点,请同样执行上面的步骤,然后运行:
cd testnet/stacks-node
cargo build --release --bin stacks-node


The above code will compile an optimized binary. To use it, run:
上面的代码将会编译一个优化过的二进制,为了用它,请运行下面的命令:
 
cd ../..
./target/release/stacks-node start --config=./testnet/conf/neon-follower-conf.toml


Enable debug logging  启用调试日志功能
In case you are running into issues or would like to see verbose logging, you can run your node with debug logging enabled. In the command line, run:
运行过程中, 为了防止您碰到问题或者看到冗长的日志,您可以在您的节点上开启调试日志功能,请直接运行下面的命令:
BLOCKSTACK_DEBUG=1 stacks-node neon
135
Views

[FREE LIVE WEBINAR] How To Start Your Career in Data Science- What are The Next Steps?

Reply

Biju Augustian posted a question • 1 users followed • 0 replies • 135 views • 2020-06-03 12:39 • data from similar tags

185
Views

What is bitcoin escrow services? How does Two Party Escrow works? How can bitcoin multi-signature feature be used for online transaction security between sellers and buyers?

Africalocals team posted the article • 0 comments • 185 views • 2020-04-14 15:38 • data from similar tags

Decentralized & Anonymous

the Bitcoin network is used for payments. it is decentralized and anonymous.

Two-Party Escrow

The seller puts up a 1x price of the item as a deposit to a bitcoin multi-signature address, and the buyer puts up 1x price of the item as a deposit to the same bitcoin multi-signature address  + 1x for payment( the buyer can use PayPal, credit card, bank transfer, cash, etc). These deposited bitcoins can only be released when both agree on payment or refund. This keeps incentives aligned without the need for escrow agents or reputation systems.

 
Free, Open & Uncensored

Free client, Open-source code available on Github under an MIT license.
 
 
 Choice Of Two Party Escrow

To appreciate the value of the two-party escrow system and why it is so important for secure, private and middlemen free exchange, it is worth considering problems with the traditional approach of using a 3rd party escrow agent.

In a third party escrow system the buyer and seller ask a third trusted party (an escrow agent) to receive payment from the buyer before the item is delivered and to then release the payment to the seller after the item is delivered. If there is a dispute about the quality of the item or whether it was delivered, the third party acts as a mediator and decides whether to send the payment or refund the buyer. Some of the problems with this model include:
 
    •  Unless escrow agent receives the item before forwarding it to the buyer and has the expertise to verify the quality of the item, they have no means of fairly mediating a dispute. This problem becomes much worse when services are being exchanged. Proof of package delivery doesn't verify what was delivered or its quality and photos from the buyer could be of another item, etc.

     • Credit cards and centralized marketplaces seem like existence proofs of working escrow agents but they are non-anonymous, do not resolve disputes fairly (as most small merchants can tell you) and are known to break in markets with high fraud potential (e.g. third world countries, porn, etc).

     • Untrustworthy escrow agents who may steal escrow, fail to release escrow or collude with (or be) one of the parties.

     • Escrow agents with a strong reputation may be doing a long con to take off with or extort a large payment or group of payments.

     • Escrow agent expenses in the form of labor and risk are passed on to the buyer and seller.
 

 
 
Finding a trustworthy agent requires a reputation system and building reputation systems in anonymous networks remains an unsolved problem (see next section).


Fortunately, a two-party escrow made possible by Bitcoin's multi-signature transactions can solve all of these problems.
 
Where Reputation Systems Are Required

For transactions involving goods delivery of the size typical for a user's cash transactions, we suspect a two-party escrow will be sufficient to address the problem of trust. But there are classes of transactions where reputation systems seem to be required. Some examples include:

 • Larger transactions such as those of the size that typically involve debt (e.g. purchasing a car), where the necessary size of security deposits for two-party escrow may be prohibitive.

 • Transactions involving services where buyer and seller meet in person (e.g. taxis) pose a risk that either party may physically coerce the other into releasing the transaction or otherwise harm them.

 • Transactions where there is a significant cost for nondelivery beyond the price of the item (e.g. urgent medical supplies and services, critical parts, deadline-driven projects).

 • Transactions where quality is difficult to objectively assess or where the client may not have the expertise to assess it (e.g. professional services).

 • Transactions where a buyer has strong concerns about exposing their physical address to a potentially malicious seller.

Reputation System Failures

Although reputation systems are useful, there are many potential ways for malicious agents to attack them. Systems that do not address these may be worse than no reputation system at all as they can result in users extending trust to untrustworthy parties or unwittingly exposing their real identities. These attacks include:

 • Build false trust: Posting fake positive reviews by creating many identities and performing transactions and posting reviews between them.

 • Build false distrust: Posting fake negative reviews of competitors.

 • Long cons: completing in good faith many transactions in order to accumulate and then exploit trust extended for a large or large group of transactions.

• Trusted parties whose computers become compromised. This is not a threat with two-party escrow as economic incentives are aligned regardless of the trustworthiness of the parties.

 • Identity leaks via delivery: Attaching reviews or history information to identities in externally verifiable ways can leak information (e.g. timing analysis by combining real-world delivery records with online transaction and review times), particularly when gathered over time.

 • Identity leaks via network analysis: Combining known real-world connection data (e.g. social network, business or friend networks) with the reputation system's network of reviews and even a single exposed real identity may provide strong hints to the real identities to other relatively direct connections.
 
 

 
 
 
 
While the Bitcoin blockchain and cryptographic signatures could provide a means of externally verifying trade history, when trades where done and whether or not they were completed, it doesn't address the fake review problem and it makes the system potentially more vulnerable to identity leaks. As far as we know, there are no existing reputation systems that sufficiently address any of these issues.
 

Trust Network Challenges

The network of trust solutions, where users keep contact lists of other users they trust and potentially share reviews between them solve the fake review problem. However, the trade-off is having fewer available reviews and that comprising one user can leak the identities of all members of their trust network if the cryptographic identities are tagged with real names.

This problem can be addressed if the market only allows the tagging of a trusted reviewer's cryptographic identities with the user's trust level in them. This also requires a more proactive role for the user in requesting these identities from those they trust and doing so in a way that does not record the connection between cryptographic and real identities.



Choice Of Escrow Ratios

The current version of the www.bitcoinescrow.ga is configured to use a 1-1 deposit/price ratio. So for the sale of an item costing X, the buyer would put up 2X (1X for payment and 1X for deposit) and the seller 1X so a total of 3X would be locked in escrow.

the current fixed ratio was chosen to meet the requirements that:

 • Deposits are large enough that consistently malicious buyers or sellers will on average go bankrupt before destroying the market assuming their bankroll is small compared to the volume of the market.

 • Deposits are large enough incentives to ensure the seller will deliver an acceptable product and that the buyer releases escrow at the end of the transaction (signing a payment or refund request).

 • Deposits are small enough that parties are willing to accept losses in order to punish bad actors. The results of the Ultimatum game experiments provide evidence that this is likely for the sizes in which the people might make cash purchases.

 • Deposits are small enough that locking the funds over the period of the transaction wouldn't be a burden for either party in the sizes in which the buyer might make cash purchases.

 • Simple enough to be easily understood by users.

The 1-1 ratio seems to be the simplest choice which meets all of these requirements.
 
If a buyer and a seller both use bitcoin for deposit and payment for items. What will happen?
 
 

 

 
If a buyer and a seller both use bitcoin for a deposit, and the buyer use PayPal, credit card, cash for payment of items. What will happen? (in this case, x = item's price, the seller deposited 2x bitcoins and the buyer deposited 1x bitcoin. For example, if the item's price = 1000 US$, and time is April 14, 2020. The seller should deposit 0.3 bitcoins and the buyer should deposit 0.15 bitcoins to the same multi-signature address.)
 
 
 
 
If a buyer, a mediator and a seller both use  2 of 3 bitcoin multi-signature,  and the buyer using PayPal, credit card, cash for payment of items. What will happen?
 

 
 
 

 
 
2 of 3 Bitcoin Escrow service uses Bitcoin's multi-signature function. There are 3 participants in this escrow service. A buyer, a seller, and a mediator.

How to use 2 of 3 Bitcoin Escrow service (Bitcoin's multi-signature function)?
you can click here to check the whole tutorial step by step

 1. Anyone of the three participants can generate an escrow address (and a redeem script) by adding the public key of all three participants. The mediator's public key can be selected from the list of mediators' option. Alternatively, you can leave this whole process to the mediator for a smooth transaction.

If you don't have a public key, you can generate your own key combination (an address, a public key, and a private key) using the  New Address tab.
 
2. To confirm the correctness, the redeem script can be verified here.

3. Once the redeem script is verified, the seller can send the Bitcoins to the newly generated escrow address.

4. Once the coins are received into the escrow address, it means the coins are locked into the escrow (meaning, it cannot be released without any of the 2 participants signing the transaction). To confirm if the coins are received in the escrow address, simply check the balance in any Blockchain Explorer.

5. Now that the coins are locked, the buyer can transfer the money and share the details of the same to the mediator and the seller. The seller confirms the completion of the money transfer.

6. The mediator then initiates the unsigned raw transaction using the Transaction tab here by loading the redeem script, adding the total amount (minus the network fee) and entering the Bitcoin address where the buyer wishes to receive the coins. The mediator then shares the unsigned raw transaction with the buyer.

7. The buyer signs the raw transaction using the signing tab with his/her private key. This generates a new 1st signed raw transaction. The buyer then shares the 1st signed raw transaction with the seller/mediator for their signature. Now either the seller or the mediator can sign the 1st signed raw transaction by repeating step 7. This will generate the 2nd signed raw transaction.

8. The 2nd signed raw transaction can then be broadcast to the main network using the Broadcast tab which will generate a new Transaction ID (TX ID). You can use Blockchain Explorer to check the status of the Transaction. This confirms the completion of the escrow transaction
  view all
Decentralized & Anonymous

the Bitcoin network is used for payments. it is decentralized and anonymous.

Two-Party Escrow

The seller puts up a 1x price of the item as a deposit to a bitcoin multi-signature address, and the buyer puts up 1x price of the item as a deposit to the same bitcoin multi-signature address  + 1x for payment( the buyer can use PayPal, credit card, bank transfer, cash, etc). These deposited bitcoins can only be released when both agree on payment or refund. This keeps incentives aligned without the need for escrow agents or reputation systems.

 
Free, Open & Uncensored

Free client, Open-source code available on Github under an MIT license.
 
 
 Choice Of Two Party Escrow

To appreciate the value of the two-party escrow system and why it is so important for secure, private and middlemen free exchange, it is worth considering problems with the traditional approach of using a 3rd party escrow agent.

In a third party escrow system the buyer and seller ask a third trusted party (an escrow agent) to receive payment from the buyer before the item is delivered and to then release the payment to the seller after the item is delivered. If there is a dispute about the quality of the item or whether it was delivered, the third party acts as a mediator and decides whether to send the payment or refund the buyer. Some of the problems with this model include:
 
    •  Unless escrow agent receives the item before forwarding it to the buyer and has the expertise to verify the quality of the item, they have no means of fairly mediating a dispute. This problem becomes much worse when services are being exchanged. Proof of package delivery doesn't verify what was delivered or its quality and photos from the buyer could be of another item, etc.

     • Credit cards and centralized marketplaces seem like existence proofs of working escrow agents but they are non-anonymous, do not resolve disputes fairly (as most small merchants can tell you) and are known to break in markets with high fraud potential (e.g. third world countries, porn, etc).

     • Untrustworthy escrow agents who may steal escrow, fail to release escrow or collude with (or be) one of the parties.

     • Escrow agents with a strong reputation may be doing a long con to take off with or extort a large payment or group of payments.

     • Escrow agent expenses in the form of labor and risk are passed on to the buyer and seller.
 

 
 
Finding a trustworthy agent requires a reputation system and building reputation systems in anonymous networks remains an unsolved problem (see next section).


Fortunately, a two-party escrow made possible by Bitcoin's multi-signature transactions can solve all of these problems.
 
Where Reputation Systems Are Required

For transactions involving goods delivery of the size typical for a user's cash transactions, we suspect a two-party escrow will be sufficient to address the problem of trust. But there are classes of transactions where reputation systems seem to be required. Some examples include:

 • Larger transactions such as those of the size that typically involve debt (e.g. purchasing a car), where the necessary size of security deposits for two-party escrow may be prohibitive.

 • Transactions involving services where buyer and seller meet in person (e.g. taxis) pose a risk that either party may physically coerce the other into releasing the transaction or otherwise harm them.

 • Transactions where there is a significant cost for nondelivery beyond the price of the item (e.g. urgent medical supplies and services, critical parts, deadline-driven projects).

 • Transactions where quality is difficult to objectively assess or where the client may not have the expertise to assess it (e.g. professional services).

 • Transactions where a buyer has strong concerns about exposing their physical address to a potentially malicious seller.

Reputation System Failures

Although reputation systems are useful, there are many potential ways for malicious agents to attack them. Systems that do not address these may be worse than no reputation system at all as they can result in users extending trust to untrustworthy parties or unwittingly exposing their real identities. These attacks include:

 • Build false trust: Posting fake positive reviews by creating many identities and performing transactions and posting reviews between them.

 • Build false distrust: Posting fake negative reviews of competitors.

 • Long cons: completing in good faith many transactions in order to accumulate and then exploit trust extended for a large or large group of transactions.

• Trusted parties whose computers become compromised. This is not a threat with two-party escrow as economic incentives are aligned regardless of the trustworthiness of the parties.

 • Identity leaks via delivery: Attaching reviews or history information to identities in externally verifiable ways can leak information (e.g. timing analysis by combining real-world delivery records with online transaction and review times), particularly when gathered over time.

 • Identity leaks via network analysis: Combining known real-world connection data (e.g. social network, business or friend networks) with the reputation system's network of reviews and even a single exposed real identity may provide strong hints to the real identities to other relatively direct connections.
 
 

 
 
 
 
While the Bitcoin blockchain and cryptographic signatures could provide a means of externally verifying trade history, when trades where done and whether or not they were completed, it doesn't address the fake review problem and it makes the system potentially more vulnerable to identity leaks. As far as we know, there are no existing reputation systems that sufficiently address any of these issues.
 

Trust Network Challenges

The network of trust solutions, where users keep contact lists of other users they trust and potentially share reviews between them solve the fake review problem. However, the trade-off is having fewer available reviews and that comprising one user can leak the identities of all members of their trust network if the cryptographic identities are tagged with real names.

This problem can be addressed if the market only allows the tagging of a trusted reviewer's cryptographic identities with the user's trust level in them. This also requires a more proactive role for the user in requesting these identities from those they trust and doing so in a way that does not record the connection between cryptographic and real identities.



Choice Of Escrow Ratios

The current version of the www.bitcoinescrow.ga is configured to use a 1-1 deposit/price ratio. So for the sale of an item costing X, the buyer would put up 2X (1X for payment and 1X for deposit) and the seller 1X so a total of 3X would be locked in escrow.

the current fixed ratio was chosen to meet the requirements that:

 • Deposits are large enough that consistently malicious buyers or sellers will on average go bankrupt before destroying the market assuming their bankroll is small compared to the volume of the market.

 • Deposits are large enough incentives to ensure the seller will deliver an acceptable product and that the buyer releases escrow at the end of the transaction (signing a payment or refund request).

 • Deposits are small enough that parties are willing to accept losses in order to punish bad actors. The results of the Ultimatum game experiments provide evidence that this is likely for the sizes in which the people might make cash purchases.

 • Deposits are small enough that locking the funds over the period of the transaction wouldn't be a burden for either party in the sizes in which the buyer might make cash purchases.

 • Simple enough to be easily understood by users.

The 1-1 ratio seems to be the simplest choice which meets all of these requirements.
 
If a buyer and a seller both use bitcoin for deposit and payment for items. What will happen?
 
 

 

 
If a buyer and a seller both use bitcoin for a deposit, and the buyer use PayPal, credit card, cash for payment of items. What will happen? (in this case, x = item's price, the seller deposited 2x bitcoins and the buyer deposited 1x bitcoin. For example, if the item's price = 1000 US$, and time is April 14, 2020. The seller should deposit 0.3 bitcoins and the buyer should deposit 0.15 bitcoins to the same multi-signature address.)
 
 
 
 
If a buyer, a mediator and a seller both use  2 of 3 bitcoin multi-signature,  and the buyer using PayPal, credit card, cash for payment of items. What will happen?
 

 
 
 

 
 
2 of 3 Bitcoin Escrow service uses Bitcoin's multi-signature function. There are 3 participants in this escrow service. A buyer, a seller, and a mediator.

How to use 2 of 3 Bitcoin Escrow service (Bitcoin's multi-signature function)?
you can click here to check the whole tutorial step by step

 1. Anyone of the three participants can generate an escrow address (and a redeem script) by adding the public key of all three participants. The mediator's public key can be selected from the list of mediators' option. Alternatively, you can leave this whole process to the mediator for a smooth transaction.

If you don't have a public key, you can generate your own key combination (an address, a public key, and a private key) using the  New Address tab.
 
2. To confirm the correctness, the redeem script can be verified here.

3. Once the redeem script is verified, the seller can send the Bitcoins to the newly generated escrow address.

4. Once the coins are received into the escrow address, it means the coins are locked into the escrow (meaning, it cannot be released without any of the 2 participants signing the transaction). To confirm if the coins are received in the escrow address, simply check the balance in any Blockchain Explorer.

5. Now that the coins are locked, the buyer can transfer the money and share the details of the same to the mediator and the seller. The seller confirms the completion of the money transfer.

6. The mediator then initiates the unsigned raw transaction using the Transaction tab here by loading the redeem script, adding the total amount (minus the network fee) and entering the Bitcoin address where the buyer wishes to receive the coins. The mediator then shares the unsigned raw transaction with the buyer.

7. The buyer signs the raw transaction using the signing tab with his/her private key. This generates a new 1st signed raw transaction. The buyer then shares the 1st signed raw transaction with the seller/mediator for their signature. Now either the seller or the mediator can sign the 1st signed raw transaction by repeating step 7. This will generate the 2nd signed raw transaction.

8. The 2nd signed raw transaction can then be broadcast to the main network using the Broadcast tab which will generate a new Transaction ID (TX ID). You can use Blockchain Explorer to check the status of the Transaction. This confirms the completion of the escrow transaction
 
353
Views

Africalocals.com Buyer Protection, MONEY BACK GUARANTEE and Terms & Conditions

Africalocals team posted the article • 0 comments • 353 views • 2020-03-21 02:14 • data from similar tags

 
 

 
                                                                            MONEY BACK GUARANTEE
 
We promise your money back if the item you received is not as described, or if your item is not delivered within the Buyer Protection period. You can get a refund 15 days after the claim process finishes. This guarantee is in addition to and does not limit your statutory rights as a consumer, as granted by all mandatory laws and regulations applicable in your country of residence.
 
 
1. Contact Seller
 
Go to your order history and select the item. Discuss the issue with the seller and see possible solutions.
 
2. Apply for Refund
 
If you can't come to an amicable agreement after contacting the seller, simply raise a claim by opening a dispute within 15 days following the delivery of your order or the end of the package receipt confirmation period (as listed in your order details).
 
 
3. Get Money Back in 15 Days
 
Most sellers will return your money in 15 days, however; if it's not resolved, you can contact kiwikiwifly from the order detail page to escalate your dispute.
 
 
Q&A From Sellers and Buyers

What can I sell?

Be creative! You can offer any service you wish as long as it's legal and complies with our terms. There are over 200 categories you can browse to get ideas.
 
 

How much time will I need to invest?

It's very flexible. You need to put in some time and effort in the beginning to learn the shopping mall and then you can decide for yourself what amount of work you want to do.
 

How much money can I make?

It's totally up to you. You can work as much as you want. Many sellers work on kiwikiwifly shopping mall full time and some keep their 9-5 job while using Africalocals shopping mall to make extra money.
 

How do I price my service?

With Africalocals shopping mall Packages, you set your pricing anywhere from $1- $9990 and offer different versions of your service at lots of different prices.
 
How much does it cost

It's free to join Africalocals shopping mall. There is no subscription required or fees to list your products or services. You keep 98% of each transaction.

How do I get paid?

Once you complete a buyer's order, the money is transferred to your account. No need to chase clients for payments and wait 60 or 90 days for a check. view all

 
 

 
                                                                            MONEY BACK GUARANTEE
 
We promise your money back if the item you received is not as described, or if your item is not delivered within the Buyer Protection period. You can get a refund 15 days after the claim process finishes. This guarantee is in addition to and does not limit your statutory rights as a consumer, as granted by all mandatory laws and regulations applicable in your country of residence.
 
 
1. Contact Seller
 
Go to your order history and select the item. Discuss the issue with the seller and see possible solutions.
 
2. Apply for Refund
 
If you can't come to an amicable agreement after contacting the seller, simply raise a claim by opening a dispute within 15 days following the delivery of your order or the end of the package receipt confirmation period (as listed in your order details).
 
 
3. Get Money Back in 15 Days

 
Most sellers will return your money in 15 days, however; if it's not resolved, you can contact kiwikiwifly from the order detail page to escalate your dispute.
 
 
Q&A From Sellers and Buyers

What can I sell?

Be creative! You can offer any service you wish as long as it's legal and complies with our terms. There are over 200 categories you can browse to get ideas.
 
 

How much time will I need to invest?

It's very flexible. You need to put in some time and effort in the beginning to learn the shopping mall and then you can decide for yourself what amount of work you want to do.
 

How much money can I make?

It's totally up to you. You can work as much as you want. Many sellers work on kiwikiwifly shopping mall full time and some keep their 9-5 job while using Africalocals shopping mall to make extra money.
 

How do I price my service?

With Africalocals shopping mall Packages, you set your pricing anywhere from $1- $9990 and offer different versions of your service at lots of different prices.
 
How much does it cost

It's free to join Africalocals shopping mall. There is no subscription required or fees to list your products or services. You keep 98% of each transaction.

How do I get paid?

Once you complete a buyer's order, the money is transferred to your account. No need to chase clients for payments and wait 60 or 90 days for a check.
205
Views

how to register blockstack id and get free 1 dollar bitcoin

Dylan posted the article • 0 comments • 205 views • 2019-12-25 18:45 • data from similar tags

how to register blockstack id and get free 1 dollar bitcoin.

blockstack id just like google outh and twitter outh , it has over 6k upvotes on github. Thousands of developers use it developing dapp. Thre are two benefits for using blockstack id:
1. you won’t need to use your own email address or phone number to register or log in a new website, the password is stored in your local computer, you don’t need to remember your password anymore.
2. Developer can save lots of time to write codes for user id logic parts. The API is much simpler than google outh.No one can block or delete your id.
First,we should click their official website:

https://www.yournewinternet.com/?grsf=ssoby4

From here, we can see some messages that we may have about 1 dollar free bitcoins, I tried it, if you use phone number from NYC or China, you cannot get through, Japan phone number is valid. When you see images below, you just need to click the purple “next” button.



![image](https://i.ibb.co/0y3xsQF/2019-12-21-6-30-34.png)
![image](https://i.ibb.co/2Yfm6D9/2019-12-21-6-30-43.png)
![image](https://i.ibb.co/mNTjpT0/2019-12-21-6-30-50.png)
![image](https://i.ibb.co/MVKZTX2/2019-12-21-6-30-56.png)
![image](https://i.ibb.co/X3JGMZy/2019-12-21-6-31-55.png)

After you type your name, phone number, we are directed to https://browser.blockstack.org/ I uses the Japan phone number, you can try other countries.
So, next, click the purple button “creat new id”

![image](https://i.ibb.co/Syjx9H6/1.png)

Type your id name,and see it valid or not.

![image](https://i.ibb.co/nBSrzn9/1.png)


Then you can input your email address for save your recovery key

![image](https://i.ibb.co/Vq8yKpQ/1.png)

⚠️Note:Do not share your recovery key to any body, it's like the private key of bitcoin, if you lose your recovery key, you would lose your data and coins!


![image](https://i.ibb.co/hs4vB1B/1.png)


ok,after you verify your recovery key, the page would prompts you are successfully registered.Now, you can go to: https://browser.blockstack.org/
to check out over 300 decentralized apps and softwares.Or, you can go to dapp.co, there are lots of latest decentralized apps.
you can check your free bitcoin from here: https://browser.blockstack.org/wallet/receive if you have referral of 10 users, you would get 10 dollars of bitcoins.
Tutorial Tags: how to register blockstack id|blockstack id registration tutorial|how to sign up a blockstack id|blockstack id| how to get free bitcoins view all
how to register blockstack id and get free 1 dollar bitcoin.

blockstack id just like google outh and twitter outh , it has over 6k upvotes on github. Thousands of developers use it developing dapp. Thre are two benefits for using blockstack id:
1. you won’t need to use your own email address or phone number to register or log in a new website, the password is stored in your local computer, you don’t need to remember your password anymore.
2. Developer can save lots of time to write codes for user id logic parts. The API is much simpler than google outh.No one can block or delete your id.
First,we should click their official website:

https://www.yournewinternet.com/?grsf=ssoby4

From here, we can see some messages that we may have about 1 dollar free bitcoins, I tried it, if you use phone number from NYC or China, you cannot get through, Japan phone number is valid. When you see images below, you just need to click the purple “next” button.



![image](https://i.ibb.co/0y3xsQF/2019-12-21-6-30-34.png)
![image](https://i.ibb.co/2Yfm6D9/2019-12-21-6-30-43.png)
![image](https://i.ibb.co/mNTjpT0/2019-12-21-6-30-50.png)
![image](https://i.ibb.co/MVKZTX2/2019-12-21-6-30-56.png)
![image](https://i.ibb.co/X3JGMZy/2019-12-21-6-31-55.png)

After you type your name, phone number, we are directed to https://browser.blockstack.org/ I uses the Japan phone number, you can try other countries.
So, next, click the purple button “creat new id”

![image](https://i.ibb.co/Syjx9H6/1.png)

Type your id name,and see it valid or not.

![image](https://i.ibb.co/nBSrzn9/1.png)


Then you can input your email address for save your recovery key

![image](https://i.ibb.co/Vq8yKpQ/1.png)

⚠️Note:Do not share your recovery key to any body, it's like the private key of bitcoin, if you lose your recovery key, you would lose your data and coins!


![image](https://i.ibb.co/hs4vB1B/1.png)


ok,after you verify your recovery key, the page would prompts you are successfully registered.Now, you can go to: https://browser.blockstack.org/
to check out over 300 decentralized apps and softwares.Or, you can go to dapp.co, there are lots of latest decentralized apps.
you can check your free bitcoin from here: https://browser.blockstack.org/wallet/receive if you have referral of 10 users, you would get 10 dollars of bitcoins.
Tutorial Tags: how to register blockstack id|blockstack id registration tutorial|how to sign up a blockstack id|blockstack id| how to get free bitcoins
230
Views

how to register blockstack id and get free 1 dollar bitcoin.step by stey tutorial with images for begnners

Dylan posted the article • 0 comments • 230 views • 2019-12-25 18:41 • data from similar tags

how to register blockstack id and get free 1 dollar bitcoin.
 
blockstack id just like google outh and twitter outh , it has over 6k upvotes on github. Thousands of developers use it developing dapp. Thre are two benefits for using blockstack id:
  1. you won’t need to use your own email address or phone number to register or log in a new website, the password is stored in your local computer, you don’t need to remember your password anymore.
2. Developer can save lots of time to write codes for user id logic parts. The API is much simpler than google outh.No one can block or delete your id.
First,we should click their official website:
  https://www.yournewinternet.com?grsf=539eu3

From here, we can see some messages that we may have about 1 dollar free bitcoins, I tried it, if you use phone number from NYC or China, you cannot get through, Japan phone number is valid. When you see images below, you just need to click the purple “next” button.

 
 
 


 
 
 


After you type your name, phone number, we are directed to https://browser.blockstack.org/   I use the Japan phone number, you can try other countries.
So, next, click the purple button “creat new id”



Type your id name,and see it valid or not.




Then you can input your email address for save your recovery key



⚠️Note:Do not share your recovery key to any body, it's like the private key of bitcoin, if you lose your recovery key, you would lose your data and coins!





ok,after you verify your recovery key, the page would prompts you are successfully registered.Now, you can go to: https://browser.blockstack.org/
to check out over 300 decentralized apps and softwares.Or, you can go to dapp.co, there are lots of latest decentralized apps.
you can check your free bitcoin from here: https://browser.blockstack.org/wallet/receive if you have referral of 10 users, you would get 10 dollars of bitcoins.
Tutorial Tags: how to register blockstack id|blockstack id registration tutorial|how to sign up a blockstack id|blockstack id| how to get free bitcoins view all
how to register blockstack id and get free 1 dollar bitcoin.
 
blockstack id just like google outh and twitter outh , it has over 6k upvotes on github. Thousands of developers use it developing dapp. Thre are two benefits for using blockstack id:
  1. you won’t need to use your own email address or phone number to register or log in a new website, the password is stored in your local computer, you don’t need to remember your password anymore.
2. Developer can save lots of time to write codes for user id logic parts. The API is much simpler than google outh.No one can block or delete your id.
First,we should click their official website:
  https://www.yournewinternet.com?grsf=539eu3

From here, we can see some messages that we may have about 1 dollar free bitcoins, I tried it, if you use phone number from NYC or China, you cannot get through, Japan phone number is valid. When you see images below, you just need to click the purple “next” button.

 
 
 


 
 
 


After you type your name, phone number, we are directed to https://browser.blockstack.org/   I use the Japan phone number, you can try other countries.
So, next, click the purple button “creat new id”



Type your id name,and see it valid or not.




Then you can input your email address for save your recovery key



⚠️Note:Do not share your recovery key to any body, it's like the private key of bitcoin, if you lose your recovery key, you would lose your data and coins!





ok,after you verify your recovery key, the page would prompts you are successfully registered.Now, you can go to: https://browser.blockstack.org/
to check out over 300 decentralized apps and softwares.Or, you can go to dapp.co, there are lots of latest decentralized apps.
you can check your free bitcoin from here: https://browser.blockstack.org/wallet/receive if you have referral of 10 users, you would get 10 dollars of bitcoins.
Tutorial Tags: how to register blockstack id|blockstack id registration tutorial|how to sign up a blockstack id|blockstack id| how to get free bitcoins
156
Views

How to sign up a blockstack id and get 1 dollar free bitcoins,step by step tutorial for beginners

dacre posted the article • 0 comments • 156 views • 2019-12-24 22:26 • data from similar tags

Official blockstack id sign up webiste: https://www.yournewinternet.com/?grsf=ssoby4
 
video tags:how to sign up a blockstack id|How to register a blockstack id |blockstack id|blockstack
 
 
  view all

Official blockstack id sign up webiste: https://www.yournewinternet.com/?grsf=ssoby4
 
video tags:how to sign up a blockstack id|How to register a blockstack id |blockstack id|blockstack
 
 
 


342
Views

【blockstack新手入门教程】如何注册blockstack id, 并免费获得大约1美金的比特币,这应该是最详细的图文教程啦

Dylan posted the article • 0 comments • 342 views • 2019-12-21 22:22 • data from similar tags

如何注册一个blockstack id,一步一步详细图文教程

blockstack id 类似于qq登录或者微信一键登录,在github上高达6k的点赞,已经有数千的程序员使用这个blockstack架构来开发dapp。使用blockstack id 对于普通用户和开发者有2个作用:

1. 可以不用注册app,直接登录。体验众多的dapp。比如类似于百度网盘的xordrive
2. 开发者可以免去写注册、登录的代码,省去大量开发时间,api比google outh或者qq一键登录更加友好、简单。

首先我们打开他们的网站 https://www.yournewinternet.com/?grsf=ssoby4

然后会出现很多提示:你可以通过这个网站注册blockstack id 并获得大约1美金左右的免费比特币。不过经过我测试,中国的手机号是不行的,但是可以得到一个免费的blockstack id。ok,我们继续.当看下面的图片时,我们直接点击紫色的next按钮。

 


最重要的环节来了,当你填写的手机号验证通过后,我们就到了https://browser.blockstack.org/ 这个页面来注册一个blockstack id,我用的是Estonia的号码,大家也可以尝试别的国家试试。
接下来就非常简单了,点击紫色create new id按钮,如图所示:
 

填写一个用户名,程序会自动检测是否已经被注册过。


然后我们在输入一个邮箱地址,用来保存我们的recovery key

⚠️注意:这个密钥不能分享给任何人!!类似于比特币的私钥,这个recovery key也是在本地电脑生成的,如果你丢失,是无法找回这个密钥的!

ok,我们继续,点击紫色按钮secret recovery key 显示密钥明文,把我们的密钥保存到一个安全的地方。




ok,一旦你验证你的密钥后,网页会提示你注册成功。 你就可以到: https://browser.blockstack.org/ 这个页面去体验300个去中心化的网站和应用程序。

或者你也可以去 dapp.co  这个网站里面查看最新的基于blockstack架构开发的 dapp。

去这个网址下面查看你的比特币余额: https://browser.blockstack.org/wallet/receive  我用的是Estonia免费的号码注册,也没有收到。 估计薅羊毛的人太多,被官方屏蔽了。
  view all
如何注册一个blockstack id,一步一步详细图文教程

blockstack id 类似于qq登录或者微信一键登录,在github上高达6k的点赞,已经有数千的程序员使用这个blockstack架构来开发dapp。使用blockstack id 对于普通用户和开发者有2个作用:

1. 可以不用注册app,直接登录。体验众多的dapp。比如类似于百度网盘的xordrive
2. 开发者可以免去写注册、登录的代码,省去大量开发时间,api比google outh或者qq一键登录更加友好、简单。

首先我们打开他们的网站 https://www.yournewinternet.com/?grsf=ssoby4

然后会出现很多提示:你可以通过这个网站注册blockstack id 并获得大约1美金左右的免费比特币。不过经过我测试,中国的手机号是不行的,但是可以得到一个免费的blockstack id。ok,我们继续.当看下面的图片时,我们直接点击紫色的next按钮。

 


最重要的环节来了,当你填写的手机号验证通过后,我们就到了https://browser.blockstack.org/ 这个页面来注册一个blockstack id,我用的是Estonia的号码,大家也可以尝试别的国家试试。
接下来就非常简单了,点击紫色create new id按钮,如图所示:
 

填写一个用户名,程序会自动检测是否已经被注册过。


然后我们在输入一个邮箱地址,用来保存我们的recovery key

⚠️注意:这个密钥不能分享给任何人!!类似于比特币的私钥,这个recovery key也是在本地电脑生成的,如果你丢失,是无法找回这个密钥的!

ok,我们继续,点击紫色按钮secret recovery key 显示密钥明文,把我们的密钥保存到一个安全的地方。




ok,一旦你验证你的密钥后,网页会提示你注册成功。 你就可以到: https://browser.blockstack.org/ 这个页面去体验300个去中心化的网站和应用程序。

或者你也可以去 dapp.co  这个网站里面查看最新的基于blockstack架构开发的 dapp。

去这个网址下面查看你的比特币余额: https://browser.blockstack.org/wallet/receive  我用的是Estonia免费的号码注册,也没有收到。 估计薅羊毛的人太多,被官方屏蔽了。
 
207
Views

【blockstack 新手入門教程】如何註冊blockstack id, 並免費獲得大約1美金的比特幣,內附最詳細的圖文教程

Dylan posted the article • 0 comments • 207 views • 2019-12-21 22:16 • data from similar tags

如何註冊blockstack id, 並免費獲得大約1美金的比特幣,內附一步一步最詳細的圖文教程

blockstack id 類似於qq登錄或者微信一鍵登錄,在github上高達6k的點贊,已經有數千的程序員使用這個blockstack架構來開發dapp。使用blockstack id 對於普通用戶和開發者有2個作用:

1. 可以不用註冊app,直接登錄。體驗眾多的dapp。比如類似於google drive的xordrive
2. 開發者可以免去寫註冊、登錄的代碼,省去大量開發時間,api比google outh或者qq一鍵登錄更加友好、簡單。

首先我們打開他們的網站 https://www.yournewinternet.com/?grsf=ssoby4

然後會出現很多提示:你可以通過這個網站註冊blockstack id 並獲得大約1美金左右的免費比特幣。不過經過我測試,中國的手機號是不行的,但是可以得到一個免費的blockstack id。ok,我們繼續.當看下面的圖片時,我們直接點擊紫色的next按鈕。

 
最重要的環節來了,當你填寫的手機號驗證通過後,我們就到了https://browser.blockstack.org/ 這個頁面來註冊一個blockstack id,我用的是Estonia的號碼,大家也可以嘗試別的國家試試。

接下來就非常簡單了,點擊紫色create new id按鈕,如圖所示:
 
 
填寫一個用戶名,程序會自動檢測是否已經被註冊過。
 

 
 
然後我們在輸入一個郵箱地址,用來保存我們的recovery key 

 
⚠️注意:這個密鑰不能分享給任何人!!類似於比特幣的私鑰,這個recovery key也是在本地電腦生成的,如果你丟失,是無法找回這個密鑰的!
ok,我們繼續,點擊紫色按鈕secret recovery key 顯示密鑰明文,把我們的密鑰保存到一個安全的地方。



ok,一旦你驗證你的密鑰後,網頁會提示你註冊成功。 你就可以到: https://browser.blockstack.org/ 這個頁面去體驗300個去中心化的網站和軟體。

或者你也可以去 dapp.co  這個網站裡面查看最新的基於blockstack架構開發的 dapp。

去這個網址下面查看你的比特幣餘額: https://browser.blockstack.org/wallet/receive  我用的是Estonia免費的號碼註冊,也沒有收到。 估計薅羊毛的人太多,被官方屏蔽了。
  view all
如何註冊blockstack id, 並免費獲得大約1美金的比特幣,內附一步一步最詳細的圖文教程

blockstack id 類似於qq登錄或者微信一鍵登錄,在github上高達6k的點贊,已經有數千的程序員使用這個blockstack架構來開發dapp。使用blockstack id 對於普通用戶和開發者有2個作用:

1. 可以不用註冊app,直接登錄。體驗眾多的dapp。比如類似於google drive的xordrive
2. 開發者可以免去寫註冊、登錄的代碼,省去大量開發時間,api比google outh或者qq一鍵登錄更加友好、簡單。

首先我們打開他們的網站 https://www.yournewinternet.com/?grsf=ssoby4

然後會出現很多提示:你可以通過這個網站註冊blockstack id 並獲得大約1美金左右的免費比特幣。不過經過我測試,中國的手機號是不行的,但是可以得到一個免費的blockstack id。ok,我們繼續.當看下面的圖片時,我們直接點擊紫色的next按鈕。

 
最重要的環節來了,當你填寫的手機號驗證通過後,我們就到了https://browser.blockstack.org/ 這個頁面來註冊一個blockstack id,我用的是Estonia的號碼,大家也可以嘗試別的國家試試。

接下來就非常簡單了,點擊紫色create new id按鈕,如圖所示:
 
 
填寫一個用戶名,程序會自動檢測是否已經被註冊過。
 

 
 
然後我們在輸入一個郵箱地址,用來保存我們的recovery key 

 
⚠️注意:這個密鑰不能分享給任何人!!類似於比特幣的私鑰,這個recovery key也是在本地電腦生成的,如果你丟失,是無法找回這個密鑰的!
ok,我們繼續,點擊紫色按鈕secret recovery key 顯示密鑰明文,把我們的密鑰保存到一個安全的地方。



ok,一旦你驗證你的密鑰後,網頁會提示你註冊成功。 你就可以到: https://browser.blockstack.org/ 這個頁面去體驗300個去中心化的網站和軟體。

或者你也可以去 dapp.co  這個網站裡面查看最新的基於blockstack架構開發的 dapp。

去這個網址下面查看你的比特幣餘額: https://browser.blockstack.org/wallet/receive  我用的是Estonia免費的號碼註冊,也沒有收到。 估計薅羊毛的人太多,被官方屏蔽了。
 
242
Views

How does 2 of 3 Bitcoin Escrow work?

Africalocals team posted the article • 0 comments • 242 views • 2019-12-17 18:40 • data from similar tags

In Simple Infographic Representation
 

 
 

 
 
 
 
Our 2 of 3 Bitcoin Escrow service uses Bitcoin's multisignature function. There are 3 participants in this escrow service. A buyer, a seller and a mediator. All the transaction online and through https://bitcoinescrow.ga/.

1. Any one of the three participants can generate an escrow address (and a redeem script) by adding the public key of all three participants. The mediator's public key can be selected from the list of mediators option. Alternatively, you can leave this whole process to the mediator for a smooth transaction.

If you don't have a public key, you can generate your own key combination (an address, a public key and a private key) using the  New Address tab.NOTE: Never share your Private Key to anyone else. If you do, you would lose your bitcoins! They can sign the transaction on your behalf and redeem all the coins to their address.

2. To confirm the correctness, the redeem script can be verified here   .

3. Once the redeem script is verified, the seller can send the Bitcoins to the newly generated escrow address.

4. Once the coins are received into the escrow address, it means the coins are locked into the escrow (meaning, it cannot be released without any of the 2 participants signing the transaction). To confirm if the coins are received in the escrow address, simply check the balance in any Blockchain Explorer .

5. Now that the coins are locked, the buyer can transfer the money and share the details of the same to the mediator and the seller. The seller confirms the completion of the money transfer.

6. The mediator then initiates the unsigned raw transaction using the Transaction tab here by loading the redeem script, adding the total amount (minue the network fee) and entering the Bitcoin address where the buyer wishes to receive the coins. The mediator then shares the unsigned raw transaction to the buyer.

7. The buyer signs the raw transaction using the sign tab with his/her private key. This generates a new 1st signed raw transaction. The buyer then shares the 1st signed raw transaction with the seller/mediator for their signature. Now either the seller or the mediator can sign the 1st signed raw transaction by repeating step 7. This will generate the 2nd signed raw transaction.

8. The 2nd signed raw transaction can then be broadcast to the main network using Broadcast tab which will generate a new Transaction ID (TX ID). You can use Blockchain Explorer to check the status of the Transaction. This confirms the completion of the escrow transaction



 
 
 

  view all
In Simple Infographic Representation
 

 
 

 
 
 
 
Our 2 of 3 Bitcoin Escrow service uses Bitcoin's multisignature function. There are 3 participants in this escrow service. A buyer, a seller and a mediator. All the transaction online and through https://bitcoinescrow.ga/.

1. Any one of the three participants can generate an escrow address (and a redeem script) by adding the public key of all three participants. The mediator's public key can be selected from the list of mediators option. Alternatively, you can leave this whole process to the mediator for a smooth transaction.

If you don't have a public key, you can generate your own key combination (an address, a public key and a private key) using the  New Address tab.
NOTE: Never share your Private Key to anyone else. If you do, you would lose your bitcoins! They can sign the transaction on your behalf and redeem all the coins to their address.


2. To confirm the correctness, the redeem script can be verified here   .

3. Once the redeem script is verified, the seller can send the Bitcoins to the newly generated escrow address.

4. Once the coins are received into the escrow address, it means the coins are locked into the escrow (meaning, it cannot be released without any of the 2 participants signing the transaction). To confirm if the coins are received in the escrow address, simply check the balance in any Blockchain Explorer .

5. Now that the coins are locked, the buyer can transfer the money and share the details of the same to the mediator and the seller. The seller confirms the completion of the money transfer.

6. The mediator then initiates the unsigned raw transaction using the Transaction tab here by loading the redeem script, adding the total amount (minue the network fee) and entering the Bitcoin address where the buyer wishes to receive the coins. The mediator then shares the unsigned raw transaction to the buyer.

7. The buyer signs the raw transaction using the sign tab with his/her private key. This generates a new 1st signed raw transaction. The buyer then shares the 1st signed raw transaction with the seller/mediator for their signature. Now either the seller or the mediator can sign the 1st signed raw transaction by repeating step 7. This will generate the 2nd signed raw transaction.

8. The 2nd signed raw transaction can then be broadcast to the main network using Broadcast tab which will generate a new Transaction ID (TX ID). You can use Blockchain Explorer to check the status of the Transaction. This confirms the completion of the escrow transaction



 
 
 

 
205
Views

Firefox private network deployment tutorial without ip limitation.100% free ,20190928

dacre posted the article • 1 comments • 205 views • 2019-09-29 07:11 • data from similar tags

 

how to install firefox private network vpn when you outside of USA

Step by step tutorial:

1. Go to  https://www.mozilla.org/en-US/ Download the latest Firefox browser,install it into your computer.

2. Download the cracked Firefox vpn(private network) xpi file from here,and save it on your local computer .

https://xordrive.io/%3Fp%3Dbei ... 9468a
Another download link( password:2019): https://send.firefox.com/downl ... VzN9A
3. Open Firefox ,Click the Firefox “tool” button which on the top of your computer screen ,select “add-ons” option ,then you will go to the extension installation webpage. 

4. Drag that xpi file and drop to that area, and you would see an installation window pops up. Click “add it”

5. Then you would see a grey button like a map icon on the top-right of your Firefox browser,click it,login your Firefox id now, if you don’t have a Firefox id, you would have to register it first.

video tags: how to break the firefox vpn ip address limitation if I not in United States? | Firefox vpn installation tutorial ,When you outside of USA,it still works |what are vpns still working in China Russia,Iran or North Korea?
 
 
  view all
 


how to install firefox private network vpn when you outside of USA

Step by step tutorial:

1. Go to  https://www.mozilla.org/en-US/ Download the latest Firefox browser,install it into your computer.

2. Download the cracked Firefox vpn(private network) xpi file from here,and save it on your local computer .

https://xordrive.io/%3Fp%3Dbei ... 9468a
Another download link( password:2019): https://send.firefox.com/downl ... VzN9A
3. Open Firefox ,Click the Firefox “tool” button which on the top of your computer screen ,select “add-ons” option ,then you will go to the extension installation webpage. 

4. Drag that xpi file and drop to that area, and you would see an installation window pops up. Click “add it”

5. Then you would see a grey button like a map icon on the top-right of your Firefox browser,click it,login your Firefox id now, if you don’t have a Firefox id, you would have to register it first.

video tags: how to break the firefox vpn ip address limitation if I not in United States? | Firefox vpn installation tutorial ,When you outside of USA,it still works |what are vpns still working in China Russia,Iran or North Korea?
 
 
 
273
Views

How to install htop on CentOS 7 -the step by step tutorial with images 20190917

karin posted the article • 0 comments • 273 views • 2019-09-18 19:42 • data from similar tags

Many sysadmins know about top, the standard process management and activity monitor that comes on most Linux systems. But there are times when top does not provide the information you’re really looking for, or you want something that updates more frequently as the state of your system changes.

 

Look no further than htop. It’s interactive, real-time, and sports a variety of metrics and details above and beyond what top provides.

 

You can see CPU utilization at a glance, and that’s just the tip of the iceberg. Sort processes, kill rogue jobs right from htop, and set priorities. To learn more about htop, see the htop website.

Prerequisites to Installing htop on CentOS 7

To install htop on CentOS 7, you’ll need a few things:

 

A CentOS 7 machine
Basic knowledge of Linux and how to use the shell

Installing htop on CentOS 7: Two Methods

There are two different ways you can get htop on your computer. First, you can install it as a binary from your package manager (on CentOS this would be yum). This is a good option if you want to get it right away and don’t much mind what version of htop you’re getting.

 

You can also install htop from source. Since htop is open-source, you can download the code and build it yourself on your system. This takes a little longer, but you can be sure you’re getting the most updated build available (important if you’re looking for a specific new feature).

 

We’ll go through both methods step by step.

Install htop with Yum

The yum package manager does not contain htop by default. This is okay; we just need to add an EPEL repository so yum can find it. Here’s the commands to add that repository:

 yum -y install epel-release

yum -y update

 

Now with the repository properly added, you can tell yum to install the htop process monitoring tool:

 yum -y install htop




If the installation completes successfully, you should be able to type htop at the command line and see the status of your system.

 
(source: htop screenshots)

To learn more about htop’s features and how to customize it, see the htop website or htop explained.

Install htop from Source

To ensure you have the most recent version of htop and all the new features, you can install htop from source. This involves downloading the source code and building it on your machine.

 

Installing from source means you need to gather the dependencies yourself. Before we can install htop, we’ll need Development Tools (gcc and other compilers) and ncurses.

 

yum groupinstall "Development Tools"

yum install ncurses ncurses-devel

 

With the dependencies installed, we can grab the source code and extract it:

 

wget http://hisham.hm/htop/releases ... ar.gz

tar xvfvz htop-2.0.2.tar.gz

cd htop-2.0.2

 

Now that we’re in the folder with the htop source code, we can run these three commands to prepare and build the code:

 

./configure

make

make install

 

Once the make install step completes, you should be able to use htop. Try typing htop into your terminal and you should see the system monitor appear.

 

If you get a htop: command not found error, you’ll need to specify the location of the htop executable in your PATH.

Conclusion: htop on CentOS7 Installed

There’s so much you can do with htop, and we hope it will help monitor your processes more quickly and easily. As always, if you have questions please leave them in the comments below.
  view all
Many sysadmins know about top, the standard process management and activity monitor that comes on most Linux systems. But there are times when top does not provide the information you’re really looking for, or you want something that updates more frequently as the state of your system changes.

 

Look no further than htop. It’s interactive, real-time, and sports a variety of metrics and details above and beyond what top provides.

 

You can see CPU utilization at a glance, and that’s just the tip of the iceberg. Sort processes, kill rogue jobs right from htop, and set priorities. To learn more about htop, see the htop website.

Prerequisites to Installing htop on CentOS 7

To install htop on CentOS 7, you’ll need a few things:

 

A CentOS 7 machine
Basic knowledge of Linux and how to use the shell

Installing htop on CentOS 7: Two Methods

There are two different ways you can get htop on your computer. First, you can install it as a binary from your package manager (on CentOS this would be yum). This is a good option if you want to get it right away and don’t much mind what version of htop you’re getting.

 

You can also install htop from source. Since htop is open-source, you can download the code and build it yourself on your system. This takes a little longer, but you can be sure you’re getting the most updated build available (important if you’re looking for a specific new feature).

 

We’ll go through both methods step by step.

Install htop with Yum

The yum package manager does not contain htop by default. This is okay; we just need to add an EPEL repository so yum can find it. Here’s the commands to add that repository:

 
yum -y install epel-release

yum -y update


 

Now with the repository properly added, you can tell yum to install the htop process monitoring tool:

 
yum -y install htop





If the installation completes successfully, you should be able to type htop at the command line and see the status of your system.

 
(source: htop screenshots)

To learn more about htop’s features and how to customize it, see the htop website or htop explained.

Install htop from Source

To ensure you have the most recent version of htop and all the new features, you can install htop from source. This involves downloading the source code and building it on your machine.

 

Installing from source means you need to gather the dependencies yourself. Before we can install htop, we’ll need Development Tools (gcc and other compilers) and ncurses.

 

yum groupinstall "Development Tools"

yum install ncurses ncurses-devel

 

With the dependencies installed, we can grab the source code and extract it:

 

wget http://hisham.hm/htop/releases ... ar.gz

tar xvfvz htop-2.0.2.tar.gz

cd htop-2.0.2

 

Now that we’re in the folder with the htop source code, we can run these three commands to prepare and build the code:

 

./configure

make

make install

 

Once the make install step completes, you should be able to use htop. Try typing htop into your terminal and you should see the system monitor appear.

 

If you get a htop: command not found error, you’ll need to specify the location of the htop executable in your PATH.

Conclusion: htop on CentOS7 Installed

There’s so much you can do with htop, and we hope it will help monitor your processes more quickly and easily. As always, if you have questions please leave them in the comments below.
 
198
Views

How to deploy your dns records on your Amazon Kindle Fire

leo posted the article • 0 comments • 198 views • 2019-09-11 12:23 • data from similar tags

Configuring the WiFi Settings
 

1.Pull down the notification bar and click on Wireless
 
 

 
 
2.In your Wifi list, tap your network once to show the connection status window and note the IP address assigned to your Kindle

 
3. Click cancel and Tap & Hold the same WiFi network and click Advanced Settings
 

 
 
4. Choose the option "Use Static IP" and some additional fields will display to complete. You're almost done! 

5. Use the following information to complete the Advanced Settings page



IP Address: Use the IP address noted in Step 2
Router: This is also known as the "wireless gateway" or the IP address to log into the router's configuration page. This can be found in your router's manual. Typically, most routers will use the first three parts of the address (a.k.a octets) with the last being number 1. 

For example, if the first three octets of the IP address you noted in Step 2 starts with 192.168.2.xxx, then the router's address is probably 192.168.2.1

Subnet Mask: 255.255.255.0
DNS 1 & 2: 208.67.222.222 and 208.67.220.220

Save your settings and reboot your device to flush the device's caches.
 
 
NOTE:

This will only set up OpenDNS for the network you chose in the Kindle Fire's wifi list. If the device connects to a different WiFi, repeat the steps above for the new network.

CANNOT CONNECT TO INTERNET:

If for any reason the Kindle cannot connect to the Internet after applying OpenDNS to your WiFi advanced settings. Repeat steps 1 - 4 and disable STATIC IP. Save (if possible) and reboot the device. The issue could be an incorrect IP address for the router, which would need to referenced in the router's manual.
 
Test your Kindle


To ensure that OpenDNS is working for your device, visit http://welcome.opendns.com and you will be greeted with a welcome message to show that you're all set! To further test this, go to http://internetbadguys.com to test the block page. 
 
 
  view all
Configuring the WiFi Settings
 

1.Pull down the notification bar and click on Wireless
 
 

 
 
2.In your Wifi list, tap your network once to show the connection status window and note the IP address assigned to your Kindle

 
3. Click cancel and Tap & Hold the same WiFi network and click Advanced Settings
 

 
 
4. Choose the option "Use Static IP" and some additional fields will display to complete. You're almost done! 

5. Use the following information to complete the Advanced Settings page



IP Address: Use the IP address noted in Step 2
Router: This is also known as the "wireless gateway" or the IP address to log into the router's configuration page. This can be found in your router's manual. Typically, most routers will use the first three parts of the address (a.k.a octets) with the last being number 1. 

For example, if the first three octets of the IP address you noted in Step 2 starts with 192.168.2.xxx, then the router's address is probably 192.168.2.1

Subnet Mask: 255.255.255.0
DNS 1 & 2: 208.67.222.222 and 208.67.220.220

Save your settings and reboot your device to flush the device's caches.
 
 
NOTE:

This will only set up OpenDNS for the network you chose in the Kindle Fire's wifi list. If the device connects to a different WiFi, repeat the steps above for the new network.

CANNOT CONNECT TO INTERNET:

If for any reason the Kindle cannot connect to the Internet after applying OpenDNS to your WiFi advanced settings. Repeat steps 1 - 4 and disable STATIC IP. Save (if possible) and reboot the device. The issue could be an incorrect IP address for the router, which would need to referenced in the router's manual.
 
Test your Kindle


To ensure that OpenDNS is working for your device, visit http://welcome.opendns.com and you will be greeted with a welcome message to show that you're all set! To further test this, go to http://internetbadguys.com to test the block page. 
 
 
 
212
Views

How to deploy your dns on Apple Tv | Apple TV Configuration Tutorial

leo posted the article • 0 comments • 212 views • 2019-09-11 12:03 • data from similar tags

1.From the Apple TV main menu, select "Settings." 
2.Select "General."
3.Select "Network."
4.Select "Ethernet" or your WiFi network.
5.Select "Configure DNS"
6.Choose "Manual," overwrite DNS address to "208.67.222.222 & 208.67.220.220" and select Done. view all
1.From the Apple TV main menu, select "Settings." 
2.Select "General."
3.Select "Network."
4.Select "Ethernet" or your WiFi network.
5.Select "Configure DNS"
6.Choose "Manual," overwrite DNS address to "208.67.222.222 & 208.67.220.220" and select Done.
303
Views

How to deploy your dns on Apple Airport v7.7.8 | Apple Router Configuration Tutorial

leo posted the article • 0 comments • 303 views • 2019-09-11 12:00 • data from similar tags

1. Launch the AirPort Utility.

The AirPort Utility can be found in the Utilities folder within your Applications folder.

 

2. Select your Airport Base Station.

Some users have multiple Airport Base Stations, select the one you wish to configure.  

 

3. Enter the configuration menu for the Airport Base Station.

Click "Edit."

 




4. Change the configuration settings.

Click “Internet” to configure your router’s internet settings.

 
 
 
5. Enter the first DNS resolver address.

Enter 208.67.222.222 in the “Primary DNS Server:” field.

6. Enter the second DNS resolver address.

Enter 208.67.220.220 in the “Secondary DNS Server:” field.
 

 
7. Save your settings.

Click  “Update” to apply your settings.
 

 
 

8. Ensure that your AirPort is not in Bridge mode. Your OpenDNS configuration will not work if the AirPort is in Bridge Mode!9. Cache Flushing.

To ensure that OpenDNS is working properly for you, please flush your browser and DNS cache by following the instructions below:

https://support.umbrella.com/h ... Cache
 
 
  view all
1. Launch the AirPort Utility.

The AirPort Utility can be found in the Utilities folder within your Applications folder.

 

2. Select your Airport Base Station.

Some users have multiple Airport Base Stations, select the one you wish to configure.  

 

3. Enter the configuration menu for the Airport Base Station.

Click "Edit."

 




4. Change the configuration settings.

Click “Internet” to configure your router’s internet settings.

 
 
 
5. Enter the first DNS resolver address.

Enter 208.67.222.222 in the “Primary DNS Server:” field.

6. Enter the second DNS resolver address.

Enter 208.67.220.220 in the “Secondary DNS Server:” field.
 

 
7. Save your settings.

Click  “Update” to apply your settings.
 

 
 

8. Ensure that your AirPort is not in Bridge mode. Your OpenDNS configuration will not work if the AirPort is in Bridge Mode!9. Cache Flushing.

To ensure that OpenDNS is working properly for you, please flush your browser and DNS cache by following the instructions below:

https://support.umbrella.com/h ... Cache
 
 
 
316
Views

How to deploy your dns for your android phone | Android Configuration tutorials for OpenDNS

leo posted the article • 0 comments • 316 views • 2019-09-11 11:56 • data from similar tags

Overview

 This Knowledge Base article will show you how to set up your Android device in order to use OpenDNS.
Note:

These instructions only work for Wi-Fi connections because Android does not allow you to change the DNS servers when connected to cellular networks. Also, the changes are network specific, so you'll need to change the DNS servers every time you connect to a new wireless network. The good news is that Android remembers the settings, so you won't have to do repeat these changes whenever you reconnect to a known network.

 Changing your Android's DNS settings:

 
1.From the Android Menu home screen, tap Settings.
2.Tap Wi-Fi on the menu. The screen shown below appears, listing all of the networks your phone is able to discover.

 
 
 
3.Long press the Network you're connected to, and tap Modify Network.
 

4. On some devices, you may need to check the box for "Advanced" to see further settings. To adjust your Android DNS settings, you will need to switch the IP settings from DHCP to Static. Once changed, the menu will appear with the DNS settings available to edit. Don't worry about the editing the IP address as the Android device will fill in the IP address it has acquired through DHCP. Add our DNS resolvers (208.67.222.222 and 208.67.220.220) to the entries for DNS 1 and DNS 2 as shown below:
 

 
 
5. Save your settings.



That's it! You've updated your Android device's DNS servers!
  view all
Overview

 This Knowledge Base article will show you how to set up your Android device in order to use OpenDNS.
Note:

These instructions only work for Wi-Fi connections because Android does not allow you to change the DNS servers when connected to cellular networks. Also, the changes are network specific, so you'll need to change the DNS servers every time you connect to a new wireless network. The good news is that Android remembers the settings, so you won't have to do repeat these changes whenever you reconnect to a known network.

 Changing your Android's DNS settings:

 
1.From the Android Menu home screen, tap Settings.
2.Tap Wi-Fi on the menu. The screen shown below appears, listing all of the networks your phone is able to discover.

 
 
 
3.Long press the Network you're connected to, and tap Modify Network.
 

4. On some devices, you may need to check the box for "Advanced" to see further settings. To adjust your Android DNS settings, you will need to switch the IP settings from DHCP to Static. Once changed, the menu will appear with the DNS settings available to edit. Don't worry about the editing the IP address as the Android device will fill in the IP address it has acquired through DHCP. Add our DNS resolvers (208.67.222.222 and 208.67.220.220) to the entries for DNS 1 and DNS 2 as shown below:
 

 
 
5. Save your settings.



That's it! You've updated your Android device's DNS servers!
 
221
Views

How to modify your dns records on your home routers |Generalized Router Configuration Instructions

leo posted the article • 0 comments • 221 views • 2019-09-11 11:50 • data from similar tags

Overview


In this article, we cover how to change the DNS servers on a router. The aim is to change the servers to use the OpenDNS IPv4 addresses 208.67.222.222 and 208.67.220.220.

Note:

While we have documentation for the most popular routers available here, we do not have the resources to list each single make and model of the router on the market. In general, the instructions below should suffice for most routers.

  Solution

 1. Open the preferences for your router.

Often, the preferences are set in your web browser, via a URL with numbers (example: http://192.168.0.1 or http://192.168.1.1). You may need a password.

If you're like us, and you set the router password long ago and cannot remember it now, you can often reset the password to the manufacturer default by pressing a button on the router itself.

Or preferences may be set via a specific application for your router, which you installed on your computer when you added the router.

 

2. Find the DNS server settings.

Scan for the letters DNS next to a field which allows two or three sets of numbers, each broken into four groups of one to three numbers. It might look like this:

 
 
 
3. Put in the OpenDNS server addresses as your DNS server settings and save/apply.

Please write down your current settings before entering the OpenDNS addresses, just in case.

208.67.222.222
208.67.220.220




4. Cache Flushing.

Once you have configured your DNS settings and saved them, we highly suggest that you flush your DNS resolver cache to ensure that your new DNS configuration settings take immediate effect.

 

5. Check your Settings.

Once you have configured your DNS, check the router has retained the settings.
  view all
Overview


In this article, we cover how to change the DNS servers on a router. The aim is to change the servers to use the OpenDNS IPv4 addresses 208.67.222.222 and 208.67.220.220.

Note:

While we have documentation for the most popular routers available here, we do not have the resources to list each single make and model of the router on the market. In general, the instructions below should suffice for most routers.

  Solution

 1. Open the preferences for your router.

Often, the preferences are set in your web browser, via a URL with numbers (example: http://192.168.0.1 or http://192.168.1.1). You may need a password.

If you're like us, and you set the router password long ago and cannot remember it now, you can often reset the password to the manufacturer default by pressing a button on the router itself.

Or preferences may be set via a specific application for your router, which you installed on your computer when you added the router.

 

2. Find the DNS server settings.

Scan for the letters DNS next to a field which allows two or three sets of numbers, each broken into four groups of one to three numbers. It might look like this:

 
 
 
3. Put in the OpenDNS server addresses as your DNS server settings and save/apply.

Please write down your current settings before entering the OpenDNS addresses, just in case.

208.67.222.222
208.67.220.220




4. Cache Flushing.

Once you have configured your DNS settings and saved them, we highly suggest that you flush your DNS resolver cache to ensure that your new DNS configuration settings take immediate effect.

 

5. Check your Settings.

Once you have configured your DNS, check the router has retained the settings.
 
312
Views

How to modify dns on your apple IOS 11 for OpenDNS

leo posted the article • 0 comments • 312 views • 2019-09-11 11:42 • data from similar tags

Overview


This Knowledge Base article will show you how to set up your IOS device in order to use OpenDNS.
Note:

These instructions only work for Wi-Fi connections because iOS does not allow you to change the DNS servers when connected to cellular networks. Also, the changes are network specific, so you'll need to change the DNS servers every time you connect to a new wireless network. The good news is that iOS remembers the settings, so you won't have to repeat these changes whenever you reconnect to a known network.

Also, this works the same on all iOS devices.
 
Changing your IOS device DNS settings:

 

1.From the IOS device home screen, tap Settings.
2.Tap Wi-Fi, ensure it is enabled and your wireless network is connected.
3.Click the blue symbol next to your wireless network, as shown below.
 

 
 
 
 
 
 
4.The screen shown below appears. Tap the Configure DNS field.

 
 
 
 
 
5. Ensure Manual is selected and delete the current DNS servers by tapping on the   symbol.

 
 
6.Tap Add Server and enter OpenDNS resolvers 208.67.222.222. Repeat this process to add another DNS server as follows 208.67.220.220, as shown below.

7.Tap Save to exit the menu.
 
 
 

 
 

That's it! You've updated your IOS device DNS servers! 
  view all
Overview


This Knowledge Base article will show you how to set up your IOS device in order to use OpenDNS.
Note:

These instructions only work for Wi-Fi connections because iOS does not allow you to change the DNS servers when connected to cellular networks. Also, the changes are network specific, so you'll need to change the DNS servers every time you connect to a new wireless network. The good news is that iOS remembers the settings, so you won't have to repeat these changes whenever you reconnect to a known network.

Also, this works the same on all iOS devices.
 
Changing your IOS device DNS settings:

 

1.From the IOS device home screen, tap Settings.
2.Tap Wi-Fi, ensure it is enabled and your wireless network is connected.
3.Click the blue symbol next to your wireless network, as shown below.
 

 
 
 
 
 
 
4.The screen shown below appears. Tap the Configure DNS field.

 
 
 
 
 
5. Ensure Manual is selected and delete the current DNS servers by tapping on the   symbol.

 
 
6.Tap Add Server and enter OpenDNS resolvers 208.67.222.222. Repeat this process to add another DNS server as follows 208.67.220.220, as shown below.

7.Tap Save to exit the menu.
 
 
 

 
 

That's it! You've updated your IOS device DNS servers! 
 
207
Views

How to Clear the DNS Cache on Browsers

leo posted the article • 0 comments • 207 views • 2019-09-11 11:33 • data from similar tags

If you have recently set up your filtering, or just changed a setting, a cache clear may be necessary before you see your filtering take effect.

The following tutorial provides instructions for clearing the DNS cache within common Internet browsers
 


Internet Explorer 8 and above (Windows)

Go to the History menu, select Delete Browsing History, check all boxes (except passwords, if desired) and click Delete.

Mozilla Firefox (Windows)

Click on Firefox at the top left of your browser, go to the History menu, select Clear Recent History and check all boxes. Under Time range to clear select Everything (except passwords, if desired) and click Clear Now.

Apple Safari (Mac)

Expand the Cog Icon in the upper right corner and select Reset Safari. Check all boxes and click Reset.

Apple Safari (Windows)

Go to the Safari menu, select Reset Safari, check all boxes and click Reset.

Google Chrome (Windows)

Expand the Wrench Icon in the upper right corner and select History and check all boxes. Under Clear data for this time period, select Everything(except passwords, if desired) and click Clear Browsing Data.

Google Chrome (Mac)

Under Go to the Chrome menu, select Clear Browsing Data and check all boxes (except passwords, if desired). Under Clear data for this time period, select Everything and click Clear Browsing Data.
  view all
If you have recently set up your filtering, or just changed a setting, a cache clear may be necessary before you see your filtering take effect.

The following tutorial provides instructions for clearing the DNS cache within common Internet browsers
 


Internet Explorer 8 and above (Windows)

Go to the History menu, select Delete Browsing History, check all boxes (except passwords, if desired) and click Delete.

Mozilla Firefox (Windows)

Click on Firefox at the top left of your browser, go to the History menu, select Clear Recent History and check all boxes. Under Time range to clear select Everything (except passwords, if desired) and click Clear Now.

Apple Safari (Mac)

Expand the Cog Icon in the upper right corner and select Reset Safari. Check all boxes and click Reset.

Apple Safari (Windows)

Go to the Safari menu, select Reset Safari, check all boxes and click Reset.

Google Chrome (Windows)

Expand the Wrench Icon in the upper right corner and select History and check all boxes. Under Clear data for this time period, select Everything(except passwords, if desired) and click Clear Browsing Data.

Google Chrome (Mac)

Under Go to the Chrome menu, select Clear Browsing Data and check all boxes (except passwords, if desired). Under Clear data for this time period, select Everything and click Clear Browsing Data.
 
200
Views

How to clear the DNS Cache on your linux system computers and laptops?

Britt Maree posted the article • 0 comments • 200 views • 2019-09-11 11:29 • data from similar tags

Linux (most distributions)

 

Open a terminal window (gnome-terminal, konsole, xterm, etc)

sudo /etc/init.d/nscd restart

   or

sudo /etc/init.d/nscd restart
 
 
Ubuntu Linux

 

Open a terminal window

     Run the following command in the command line and hit enter view all
Linux (most distributions)

 

Open a terminal window (gnome-terminal, konsole, xterm, etc)

sudo /etc/init.d/nscd restart

   or

sudo /etc/init.d/nscd restart
 
 
Ubuntu Linux

 

Open a terminal window

     Run the following command in the command line and hit enter
200
Views

How to clear the DNS Cache on your windows system computers and laptops?

Britt Maree posted the article • 0 comments • 200 views • 2019-09-11 11:27 • data from similar tags

Windows 7 and Earlier

 

Click the Start Menu
Go to All Programs
Choose Accessories and right-click Command Prompt
Choose Run as Administrator

     Run the following command in the command line and hit enter

ipconfig /flushdns

 

Windows 8

 

Press the Windows Key or hover your mouse over the bottom left corner and click the Windows Icon
Begin typing Command Prompt
Right-click the application and select Run as Administrator

     Run the following command in the command line and hit enter

ipconfig /flushdns view all
Windows 7 and Earlier

 

Click the Start Menu
Go to All Programs
Choose Accessories and right-click Command Prompt
Choose Run as Administrator

     Run the following command in the command line and hit enter

ipconfig /flushdns

 

Windows 8

 

Press the Windows Key or hover your mouse over the bottom left corner and click the Windows Icon
Begin typing Command Prompt
Right-click the application and select Run as Administrator

     Run the following command in the command line and hit enter

ipconfig /flushdns
215
Views

How to clear the DNS Cache on your macOS?

Britt Maree posted the article • 0 comments • 215 views • 2019-09-11 11:23 • data from similar tags

Overview 
 
This article provides instructions on how to clear the DNS Cache on a computers and web browsers. This procedure is necessary in order for previously cached resolutions to be cleared out and subsequent lookup to be performed based on newly configured DNS settings.

 

OS X 10.4 TIGER

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal

     Run the following command in the command line and hit enter
 
lookupd -flushcache

 
 

OS X 10.5 and 10.6 LEOPARD

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal

     Run the following command in the command line and hit enter

dscacheutil -flushcache

  

OS X 10.7 and 10.8 Lion

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal


sudo killall -HUP mDNSResponder

 


 

OS X 10.9 and 10.10.4 Yosemite, 10.11 El Capitan and 10.12 Sierra

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal




sudo dscacheutil -flushcache

sudo killall -HUP mDNSResponder


  view all
Overview 
 
This article provides instructions on how to clear the DNS Cache on a computers and web browsers. This procedure is necessary in order for previously cached resolutions to be cleared out and subsequent lookup to be performed based on newly configured DNS settings.

 

OS X 10.4 TIGER

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal

     Run the following command in the command line and hit enter
 
lookupd -flushcache

 
 

OS X 10.5 and 10.6 LEOPARD

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal

     Run the following command in the command line and hit enter

dscacheutil -flushcache

  

OS X 10.7 and 10.8 Lion

 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal


sudo killall -HUP mDNSResponder

 


 

OS X 10.9 and 10.10.4 Yosemite, 10.11 El Capitan and 10.12 Sierra


 

Click the Terminal icon in the dock or in Finder under Application/Utilities/Terminal




sudo dscacheutil -flushcache

sudo killall -HUP mDNSResponder


 
228
Views

How to modify your DNS on mac OSX Mojave and El Capitan 2020

Britt Maree posted the article • 0 comments • 228 views • 2019-09-11 11:19 • data from similar tags

From this tutorial, you will learn how to modify your dns on your macOS. 
 

Tools:
Mac laptop
 
 1. Go to your mac os System Preferences option, click the apple icon on the top left screen .
 

 
2.  Click on Network
 

 
3. Select the first connection in your list and click Advanced
 

 
 
 
 
 
4. Select the DNS tab and add 208.67.222.222 and 208.67.220.220 to the list of DNS servers. Click OK
 

 
5. cache and web browser caches to ensure that your new DNS configuration settings take immediate effect.



At the point, we highly suggest that you flush your DNS resolver cache and web browser caches to ensure that your new DNS configuration settings take immediate effect.
 
Video Instruction:
 
 





  view all
From this tutorial, you will learn how to modify your dns on your macOS. 
 

Tools:
Mac laptop
 
 1. Go to your mac os System Preferences option, click the apple icon on the top left screen .
 

 
2.  Click on Network
 

 
3. Select the first connection in your list and click Advanced
 

 
 
 
 
 
4. Select the DNS tab and add 208.67.222.222 and 208.67.220.220 to the list of DNS servers. Click OK
 

 
5. cache and web browser caches to ensure that your new DNS configuration settings take immediate effect.



At the point, we highly suggest that you flush your DNS resolver cache and web browser caches to ensure that your new DNS configuration settings take immediate effect.

 
Video Instruction:
 
 






 
399
Views

Things You Should not Forget about a Live Video Interview

Reply

onegoodhead posted a question • 0 users followed • 0 replies • 399 views • 2019-07-29 08:22 • data from similar tags

300
Views

How to let you own local computer out of government spy and censorship from isp companies

Britt Maree posted the article • 0 comments • 300 views • 2019-07-07 05:42 • data from similar tags

1. go to https://www.dnsleaktest.com/ to check out, you will find two buttons in the middle of the screen. one is the standard model, the other is the extended test. Ok, let us click the standard model first. At the same time, you don’t need to use the VPN network. if you see your isp name on it(e.g. China Telecom,China Unicom,verizon, sprint, AT&T, T-mobile, etc),  that means you are recorded by these companies, and the local government would ask them for users’ data illegally. Now we need to go to modify our DNS record on our own computer 
 




After you modified, you can test your network on https://www.dnsleaktest.com/ again, and you would find, your records like these.


https://i.ibb.co/r3VNhRR/2019-07-07-3-17-46.png[/img] 
 
[/url]



cool, now, you can enjoy your fun on the internet, if you always use tor browser and vpn, that would be better get out of the spies of governments and devil eyes. view all

1. go to https://www.dnsleaktest.com/ to check out, you will find two buttons in the middle of the screen. one is the standard model, the other is the extended test. Ok, let us click the standard model first. At the same time, you don’t need to use the VPN network. if you see your isp name on it(e.g. China Telecom,China Unicom,verizon, sprint, AT&T, T-mobile, etc),  that means you are recorded by these companies, and the local government would ask them for users’ data illegally. Now we need to go to modify our DNS record on our own computer 
 




After you modified, you can test your network on https://www.dnsleaktest.com/ again, and you would find, your records like these.


https://i.ibb.co/r3VNhRR/2019-07-07-3-17-46.png[/img] 
 
[/url]



cool, now, you can enjoy your fun on the internet, if you always use tor browser and vpn, that would be better get out of the spies of governments and devil eyes.
282
Views

Clarity- smart contract language reference

blockstack app store posted the article • 0 comments • 282 views • 2019-06-28 01:45 • data from similar tags

Clarity language reference




This file contains the reference for the Clarity language.

Block Properties
Supported types

Int type
Bool type
Buffer type
List type
Principal type
Tuple type
Optional type
Response type

Native variables

block-height
contract-name
tx-sender

Clarity function reference

* (multiply)
+ (add)
- (subtract)
/ (divide)
< (less than)
<= (less than or equal)
> (greater than)
>= (greater than or equal)
and
as-contract
begin
contract-call!
default-to
define-data-var
define-map
define-public
define-read-only
define
delete-entry!
eq?
err
expects!
expects-err!
fetch-contract-entry
fetch-entry
fetch-var
filter
fold
get-block-info
get
hash160
if
insert-entry!
is-none?
is-ok?
keccak256
let
list
map
mod
not
ok
or
pow
print
set-entry!
set-var!
sha256
tuple
xor




Block Properties

The get-block-info function fetches property details for a block at a specified block height. For example:

(get-block-info time 10) ;; Returns 1557860301

Because the Clarity language is in pre-release, the block properties that are fetched are simulated properties from a SQLite database. The available property names are:

Property

Definition

header-hash

A 32-byte buffer containing the block hash.

burnchain-header-hash

A 32-byte buffer that contains the hash from the proof of burn.

vrf-seed

A 32-byte buffer containing the Verifiable Random Function (VRF) seed value used for the block.

time

An integer value containing that roughly corresponds to when the block was mined. This is a Unix epoch timestamp in seconds.

Warning: The time does not increase monotonically with each block. Block times are accurate only to within two hours. See BIP113 for more information.




Supported types

This section lists the types available to smart contracts. The only atomic types supported by the Clarity are booleans, integers, fixed length buffers, and principals.




Int type

The integer type in the Clarity language is a 16-byte signed integer, which allows it to specify the maximum amount of microstacks spendable in a single Stacks transfer. The special BlockHeightInt you can obtain with the get-block-info function.




Bool type

Supports values of 'true or 'false.




Buffer type

Buffer types represent fixed-length byte buffers. Currently, the only way to construct a Buffer is using string literals, for example "alice.id" or hash160("bob.id")

All of the hash functions return buffers:

hash160 sha256 keccak256

The block properties header-hash, burnchain-header-hash, and vrf-seed are all buffers.




List type

Clarity supports lists of the atomic types. However, the only variable length lists in the language appear as function inputs; there is no support for list operations like append or join.




Principal type

Clarity provides this primitive for checking whether or not the smart contract transaction was signed by a particular principal. Principals represent a spending entity and are roughly equivalent to a Stacks address. The principal’s signature is not checked by the smart contract, but by the virtual machine. A smart contract function can use the globally defined tx-sender variable to obtain the current principal.

Smart contracts may also be principals (represented by the smart contract’s identifier). However, there is no private key associated with the smart contract, and it cannot broadcast a signed transaction on the blockchain. A smart contract uses the special variable contract-name to refer to its own principal.




Tuple type

To support the use of named fields in keys and values, Clarity allows the construction of named tuples using a function (tuple ...), for example

(define imaginary-number-a (tuple (real 1) (i 2)))

(define imaginary-number-b (tuple (real 2) (i 3)))

This allows for creating named tuples on the fly, which is useful for data maps where the keys and values are themselves named tuples. Values in a given mapping are set or fetched using:

Function

Description

(fetch-entry map-name key-tuple)

Fetches the value associated with a given key in the map, or returns none if there is no such value.

(set-entry! map-name key-tuple value-tuple)

Sets the value of key-tuple in the data map

(insert-entry! map-name key-tuple value-tuple)

Sets the value of key-tuple in the data map if and only if an entry does not already exist.

(delete-entry! map-name key-tuple)

Deletes key-tuple from the data map.

To access a named value of a given tuple, the (get name tuple) function returns that item from the tuple.




Optional type

Represents an optional value. This is used in place of the typical usage of “null” values in other languages, and represents a type that can either be some value or none. Optional types are used as the return types of data-map functions.




Response type

Response types represent the result of a public function. Use this type to indicate and return data associated with the execution of the function. Also, the response should indicate whether the function error’ed (and therefore did not materialize any data in the database) or ran ok (in which case data materialized in the database).

Response types contain two subtypes – a response type in the event of ok (that is, a public function returns an integer code on success) and an err type (that is, a function returns a buffer on error).




Native variables

The Clarity language includes native variables you can use in your contract.




block-height

The height of a block in the Stacks blockchain. Block height is the number of blocks in the chain between any given block and the very first block in the blockchain. You can obtain a block-height via the get-block-info function.




contract-name

Represents the current contract.




tx-sender

Represents the current principal. This variable does not change during inter-contract calls. This means that if a transaction invokes a function in a given smart contract, that function is able to make calls into other smart contracts on your behalf. This enables a wide variety of applications, but it comes with some dangers for users of smart contracts. Static analysis of Clarity contracts guarantees the language allows clients to deduce which functions a given smart contract will ever call. Good clients should always warn users about any potential side effects of a given transaction.




Clarity function reference




* (multiply)

Syntax (* i1 i2...)

Input type:

int, ...

Output type:

int

Multiplies a variable number of integer inputs and returns the result. In the event of an overflow, throws a runtime error.




Example

(* 2 3) ;; Returns 6

(* 5 2) ;; Returns 10

(* 2 2 2) ;; Returns 8







+ (add)

Syntax (+ i1 i2...)

Input type:

int, ...

Output type:

int

Adds a variable number of integer inputs and returns the result. In the event of an overflow, throws a runtime error.




Example

(+ 1 2 3) ;; Returns 6







- (subtract)

Syntax (- i1 i2...)

Input type:

int, ...

Output type:

int

Subtracts a variable number of integer inputs and returns the result. In the event of an underflow, throws a runtime error.




Example

(- 2 1 1) ;; Returns 0

(- 0 3) ;; Returns -3







/ (divide)

Syntax (/ i1 i2...)

Input type:

int, ...

Output type:

int

Integer divides a variable number of integer inputs and returns the result. In the event of division by zero, throws a runtime error.




Example

(/ 2 3) ;; Returns 0

(/ 5 2) ;; Returns 2

(/ 4 2 2) ;; Returns 1







< (less than)

Syntax (< i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is less than i2 and false otherwise.




Example

(< 1 2) ;; Returns 'true

(< 5 2) ;; Returns 'false







<= (less than or equal)

Syntax (> i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is less than or equal to i2 and false otherwise.




Example

(<= 1 1) ;; Returns 'true

(<= 5 2) ;; Returns 'false







> (greater than)

Syntax (> i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is greater than i2 and false otherwise.




Example

(> 1 2) ;; Returns 'false

(> 5 2) ;; Returns 'true







>= (greater than or equal)

Syntax (>= i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is greater than or equal to i2 and false otherwise.




Example

(>= 1 1) ;; Returns 'true

(>= 5 2) ;; Returns 'true







and

Syntax (and b1 b2 ...)

Input type:

bool, ...

Output type:

bool

Returns true if all boolean inputs are true. Importantly, the supplied arguments are evaluated in-order and lazily. Lazy evaluation means that if one of the arguments returns false, the function short-circuits, and no subsequent arguments are evaluated.




Example

(and 'true 'false) ;; Returns 'false

(and (eq? (+ 1 2) 1) (eq? 4 4)) ;; Returns 'false

(and (eq? (+ 1 2) 3) (eq? 4 4)) ;; Returns 'true







as-contract

Syntax (as-contract expr)

Input type:

A

Output type:

A

The as-contract function switches the current context’s tx-sender value to the contract’s principal and executes expr with that context. It returns the resulting value of expr.




Example

(as-contract (print tx-sender)) ;; Returns 'CTcontract.name







begin

Syntax (begin expr1 expr2 expr3 ... expr-last)

Input type:

AnyType, ... A

Output type:

A

The begin function evaluates each of its input expressions, returning the return value of the last such expression.




Example

(begin (+ 1 2) 4 5) ;; Returns 5







contract-call!

Syntax (contract-call! contract-name function-name arg0 arg1 ...)

Input type:

ContractName, PublicFunctionName, Arg0, ...

Output type:

Response(A,B)

The contract-call! function executes the given public function of the given contract. You may not this function to call a public function defined in the current contract. If the public function returns err, any database changes resulting from calling contract-call! are aborted. If the function returns ok, database changes occurred.




Example

(contract-call! tokens transfer 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 19) ;; Returns (ok 1)







default-to

Syntax (default-to default-value option-value)

Input type:

A, Optional(A)

Output type:

A

The default-to function attempts to ‘unpack’ the second argument: if the argument is a (some ...) option, it returns the inner value of the option. If the second argument is a (none) value, default-to it returns the value of default-value.




Example

(default-to 0 (get id (fetch-entry names-map (tuple (name "blockstack"))))) ;; Returns 1337

(default-to 0 (get id (fetch-entry names-map (tuple (name "non-existant"))))) ;; Returns 0







define-data-var

Syntax (define-data-var var-name type value)

Input type:

VarName, TypeDefinition, Value

Output type:

Not Applicable

define-data-var is used to define a new persisted variable for use in a smart contract. Such variable are only modifiable by the current smart contract.

Persisted variable are defined with a type and a value.

Like other kinds of definition statements, define-data-var may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).




Example

(define-data-var size int 0)

(define (set-size (value int))

  (set-var! size value))

(set-size 1)

(set-size 2)







define-map

Syntax (define-map map-name ((key-name-0 key-type-0) ...) ((val-name-0 val-type-0) ...))

Input type:

MapName, KeyTupleDefinition, MapTupleDefinition

Output type:

Not Applicable

define-map is used to define a new datamap for use in a smart contract. Such maps are only modifiable by the current smart contract.

Maps are defined with a key tuple type and value tuple type. These are defined using a list of name and type pairs, e.g., a key type might be ((id int)), which is a tuple with a single “id” field of type int.

Like other kinds of definition statements, define-map may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).




Example

(define-map squares ((x int)) ((square int)))

(define (add-entry (x int))

  (insert-entry! squares ((x 2)) ((square (* x x)))))

(add-entry 1)

(add-entry 2)

(add-entry 3)

(add-entry 4)

(add-entry 5)







define-public

Syntax (define-public (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define-public is used to define a public function and transaction for a smart contract. Public functions are callable from other smart contracts and may be invoked directly by users by submitting a transaction to the Stacks blockchain.

Like other kinds of definition statements, define-public may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Public functions must return a ResponseType (using either ok or err). Any datamap modifications performed by a public function is aborted if the function returns an err type. Public functions may be invoked by other contracts via contract-call!.




Example

(define-public (hello-world (input int))

  (begin (print (+ 2 input))

         (ok input)))







define-read-only

Syntax (define-read-only (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define-read-only is used to define a public read-only function for a smart contract. Such functions are callable from other smart contracts.

Like other kinds of definition statements, define-read-only may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Read-only functions may return any type. However, read-only functions may not perform any datamap modifications, or call any functions which perform such modifications. This is enforced both during type checks and during the execution of the function. Public read-only functions may be invoked by other contracts via contract-call!.




Example

(define-read-only (just-return-one-hundred)

  (* 10 10))







define

Syntax (define (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define is used to define private functions for a smart contract. Private functions may not be called from other smart contracts, nor may they be invoked directly by users. Instead, these functions may only be invoked by other functions defined in the same smart contract.

Like other kinds of definition statements, define may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Private functions may return any type.




Example

(define (max-of (i1 int) (i2 int))

  (if (> i1 i2)

      i1

      i2))

(max-of 4 6) ;; returns 6







delete-entry!

Syntax (delete-entry! map-name key-tuple)

Input type:

MapName, Tuple

Output type:

bool

The delete-entry! function removes the value associated with the input key for the given map. If an item exists and is removed, the function returns true. If a value did not exist for this key in the data map, the function returns false.




Example

(delete-entry! names-map (tuple (name "blockstack"))) ;; Returns 'true

(delete-entry! names-map (tuple (name "blockstack"))) ;; Returns 'false

(delete-entry! names-map ((name "blockstack"))) ;; Same command, using a shorthand for constructing the tuple







eq?

Syntax (eq? v1 v2...)

Input type:

A, A, ...

Output type:

bool

Compares the inputted values, returning true if they are all equal. Note that unlike the (and ...) function, (eq? ...) will not short-circuit.




Example

(eq? 1 1) ;; Returns 'true

(eq? 1 'false) ;; Returns 'false

(eq? "abc" 234 234) ;; Returns 'false







err

Syntax (err value)

Input type:

A

Output type:

Response(A,B)

The err function constructs a response type from the input value. Use err for creating return values in public functions. An err value indicates that any database changes during the processing of the function should be rolled back.




Example

(err 'true) ;; Returns (err 'true)







expects!

Syntax (expects! option-input thrown-value)

Input type:

Optional(A) | Response(A,B), C

Output type:

A

The expects! function attempts to ‘unpack’ the first argument: if the argument is an option type, and the argument is a (some ...) option, expects! returns the inner value of the option. If the argument is a response type, and the argument is an (ok ...) response, expects! returns the inner value of the ok. If the supplied argument is either an (err ...) or a (none) value, expects! returns thrown-value from the current function and exits the current control-flow.




Example

(expects! (fetch-entry names-map (tuple (name "blockstack"))) (err 1)) ;; Returns (tuple (id 1337))







expects-err!

Syntax (expects-err! response-input thrown-value)

Input type:

Response(A,B), C

Output type:

B

The expects-err! function attempts to ‘unpack’ the first argument: if the argument is an (err ...) response, expects-err! returns the inner value of the err. If the supplied argument is an (ok ...) value, expects-err! returns thrown-value from the current function and exits the current control-flow.




Example

(expects-err! (err 1) 'false) ;; Returns 1







fetch-contract-entry

Syntax (fetch-contract-entry contract-name map-name key-tuple)

Input type:

ContractName, MapName, Tuple

Output type:

Optional(Tuple)

The fetch-contract-entry function looks up and returns an entry from a contract other than the current contract’s data map. The value is looked up using key-tuple. If there is no value associated with that key in the data map, the function returns a (none) option. Otherwise, it returns (some value).




Example

(expects! (fetch-contract-entry names-contract names-map (tuple (name "blockstack")) (err 1))) ;; Returns (tuple (id 1337))

(expects! (fetch-contract-entry names-contract names-map ((name "blockstack")) (err 1)));; Same command, using a shorthand for constructing the tuple







fetch-entry

Syntax (fetch-entry map-name key-tuple)

Input type:

MapName, Tuple

Output type:

Optional(Tuple)

The fetch-entry function looks up and returns an entry from a contract’s data map. The value is looked up using key-tuple. If there is no value associated with that key in the data map, the function returns a (none) option. Otherwise, it returns (some value)




Example

(expects! (fetch-entry names-map (tuple (name "blockstack"))) (err 1)) ;; Returns (tuple (id 1337))

(expects! (fetch-entry names-map ((name "blockstack"))) (err 1)) ;; Same command, using a shorthand for constructing the tuple







fetch-var

Syntax (fetch-var var-name)

Input type:

VarName

Output type:

A

The fetch-var function looks up and returns an entry from a contract’s data map. The value is looked up using var-name.




Example

(fetch-var cursor) ;; Returns cursor







filter

Syntax (filter func list)

Input type:

Function(A) -> bool, (list A)

Output type:

(list A)

The filter function applies the input function func to each element of the input list, and returns the same list with any elements removed for which the func returned false.




Example

(filter not (list true false true false)) ;; Returns (list false false)







fold

Syntax (fold func list initial-value)

Input type:

Function(A, B) -> B, (list A)

Output type:

B

The fold function applies the input function func to each element of the input list and the output of the previous application of the fold function. When invoked on the first list element, it uses the initial-value as the second input. fold returns the last value return by the successive applications.




Example

(fold * (list 2 2 2) 1) ;; Returns 8

(fold * (list 2 2 2) 0) ;; Returns 0







get-block-info

Syntax (get-block-info prop-name block-height-expr)

Input type:

BlockInfoPropertyName, BlockHeightInt

Output type:

buff | int

The get-block-info function fetches data for a block of the given block height. The value and type returned are determined by the specified BlockInfoPropertyName. If the provided BlockHeightInt does not correspond to an existing block, the function is aborted. The currently available property names are time, header-hash, burnchain-header-hash, and vrf-seed.

The time property returns an integer value of the block header time field. This is a Unix epoch timestamp in seconds which roughly corresponds to when the block was mined. Warning: this does not increase monotonically with each block and block times are accurate only to within two hours. See BIP113 for more information.

The header-hash, burnchain-header-hash, and vrf-seed properties return a 32-byte buffer.




Example

(get-block-info time 10) ;; Returns 1557860301

(get-block-info header-hash 2) ;; Returns 0x374708fff7719dd5979ec875d56cd2286f6d3cf7ec317a3b25632aab28ec37bb

(get-block-info vrf-seed 6) ;; Returns 0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4







get

Syntax (get key-name tuple)

Input type:

KeyName and Tuple | Optional(Tuple)

Output type:

AnyType

The get function fetches the value associated with a given key from the supplied typed tuple. If an Optional value is supplied as the inputted tuple, get returns an Optional type of the specified key in the tuple. If the supplied option is a (none) option, get returns (none).




Example

(get id (tuple (name "blockstack") (id 1337))) ;; Returns 1337

(get id (fetch-entry names-map (tuple (name "blockstack")))) ;; Returns (some 1337)

(get id (fetch-entry names-map (tuple (name "non-existent")))) ;; Returns (none)







hash160

Syntax (hash160 value)

Input type:

buff|int

Output type:

(buff 20)

The hash160 function computes RIPEMD160(SHA256(x)) of the inputted value. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(hash160 0) ;; Returns 0xe4352f72356db555721651aa612e00379167b30f







if

Syntax (if bool1 expr1 expr2)

Input type:

bool, A, A

Output type:

A

The if function admits a boolean argument and two expressions which must return the same type. In the case that the boolean input is true, the if function evaluates and returns expr1. If the boolean input is false, the if function evaluates and returns expr2.




Example

(if true 1 2) ;; Returns 1

(if (> 1 2) 1 2) ;; Returns 2







insert-entry!

Syntax (insert-entry! map-name key-tuple value-tuple)

Input type:

MapName, TupleA, TupleB

Output type:

bool

The insert-entry! function sets the value associated with the input key to the inputted value if and only if there is not already a value associated with the key in the map. If an insert occurs, the function returns true. If a value already existed for this key in the data map, the function returns false.




Example

(insert-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'true

(insert-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'false

(insert-entry! names-map ((name "blockstack")) ((id 1337))) ;; Same command, using a shorthand for constructing the tuple







is-none?

Syntax (is-none? value)

Input type:

Optional(A)

Output type:

bool

is-none? tests a supplied option value, returning true if the option value is (none), and false if it is a (some ...).




Example

(is-none? (get id (fetch-entry names-map (tuple (name "blockstack"))))) ;; Returns 'false

(is-none? (get id (fetch-entry names-map (tuple (name "non-existant"))))) ;; Returns 'true







is-ok?

Syntax (is-ok? value)

Input type:

Response(A,B)

Output type:

bool

is-ok? tests a supplied response value, returning true if the response was ok, and false if it was an err.




Example

(is-ok? (ok 1)) ;; Returns 'true

(is-ok? (err 1)) ;; Returns 'false







keccak256

Syntax (keccak256 value)

Input type:

buff|int

Output type:

(buff 32)

The keccak256 function computes KECCAK256(value) of the inputted value. Note that this differs from the NIST SHA-3 (that is, FIPS 202) standard. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(keccak256 0) ;; Returns 0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4







let

Syntax (let ((name1 expr1) (name2 expr2) ...) expr-body)

Input type:

((name2 AnyType) (name2 AnyType) ...), A

Output type:

A

The let function accepts a list of variable name and expression pairs, evaluating each expression and binding it to the corresponding variable name. The context created by this set of bindings is used for evaluating and return the value of expr-body.




Example

(let ((a 2) (b (+ 5 6 7))) (+ a b)) ;; Returns 20







list

Syntax (list expr1 expr2 expr3 ...)

Input type:

A, ...

Output type:

(list A)

The list function constructs a list composed of the inputted values. Each supplied value must be of the same type.




Example

(list (+ 1 2) 4 5) ;; Returns [3 4 5]







map

Syntax (map func list)

Input type:

Function(A) -> B, (list A)

Output type:

(list B)

The map function applies the input function func to each element of the input list, and outputs a list containing the outputs from those function applications.




Example

(map not (list true false true false)) ;; Returns 'false true false true







mod

Syntax (mod i1 i2)

Input type:

int, int

Output type:

int

Returns the integer remainder from integer dividing i1 by i2. In the event of a division by zero, throws a runtime error.




Example

(mod 2 3) ;; Returns 0

(mod 5 2) ;; Returns 1

(mod 7 1) ;; Returns 0







not

Syntax (not b1)

Input type:

bool

Output type:

bool

Returns the inverse of the boolean input.




Example

(not 'true) ;; Returns 'false

(not (eq? 1 2)) ;; Returns 'true







ok

Syntax (ok value)

Input type:

A

Output type:

Response(A,B)

The ok function constructs a response type from the input value. Use ok for creating return values in public functions. An ok value indicates that any database changes during the processing of the function should materialize.




Example

(ok 1) ;; Returns (ok 1)







or

Syntax (or b1 b2 ...)

Input type:

bool, ...

Output type:

bool

Returns true if any boolean inputs are true. Importantly, the supplied arguments are evaluated in-order and lazily. Lazy evaluation means that if one of the arguments returns false, the function short-circuits, and no subsequent arguments are evaluated.




Example

(or 'true 'false) ;; Returns 'true

(or (eq? (+ 1 2) 1) (eq? 4 4)) ;; Returns 'true

(or (eq? (+ 1 2) 1) (eq? 3 4)) ;; Returns 'false

(or (eq? (+ 1 2) 3) (eq? 4 4)) ;; Returns 'true







pow

Syntax (pow i1 i2)

Input type:

int, int

Output type:

int

Returns the result of raising i1 to the power of i2. In the event of an overflow, throws a runtime error.




Example

(pow 2 3) ;; Returns 8

(pow 2 2) ;; Returns 4

(pow 7 1) ;; Returns 7







print

Syntax (print expr)

Input type:

A

Output type:

A

The print function evaluates and returns its input expression. On Blockstack Core nodes configured for development (as opposed to production mining nodes), this function prints the resulting value to STDOUT (standard output).




Example

(print (+ 1 2 3)) ;; Returns 6







set-entry!

Syntax (set-entry! map-name key-tuple value-tuple)

Input type:

MapName, TupleA, TupleB

Output type:

bool

The set-entry! function sets the value associated with the input key to the inputted value. This function performs a blind update; whether or not a value is already associated with the key, the function overwrites that existing association.




Example

(set-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'true

(set-entry! names-map ((name "blockstack")) ((id 1337))) ;; Same command, using a shorthand for constructing the tuple







set-var!

Syntax (set-var! var-name expr1)

Input type:

VarName, AnyType

Output type:

bool

The set-var! function sets the value associated with the input variable to the inputted value.




Example

(set-var! cursor (+ cursor 1)) ;; Returns 'true







sha256

Syntax (sha256 value)

Input type:

buff|int

Output type:

(buff 32)

The sha256 function computes SHA256(x) of the inputted value. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(sha256 0) ;; Returns 0x374708fff7719dd5979ec875d56cd2286f6d3cf7ec317a3b25632aab28ec37bb







tuple

Syntax (tuple ((key0 expr0) (key1 expr1) ...))

Input type:

(list (KeyName AnyType))

Output type:

Tuple

The tuple function constructs a typed tuple from the supplied key and expression pairs. A get function can use typed tuples as input to select specific values from a given tuple. Key names may not appear multiple times in the same tuple definition. Supplied expressions are evaluated and associated with the expressions’ paired key name.




Example

(tuple (name "blockstack") (id 1337))







xor

Syntax (xor i1 i2)

Input type:

int, int

Output type:

int

Returns the result of bitwise exclusive or’ing i1 with i2.




Example

(xor 1 2) ;; Returns 3

(xor 120 280) ;; Returns 352 view all
Clarity language reference




This file contains the reference for the Clarity language.

Block Properties
Supported types

Int type
Bool type
Buffer type
List type
Principal type
Tuple type
Optional type
Response type

Native variables

block-height
contract-name
tx-sender

Clarity function reference

* (multiply)
+ (add)
- (subtract)
/ (divide)
< (less than)
<= (less than or equal)
> (greater than)
>= (greater than or equal)
and
as-contract
begin
contract-call!
default-to
define-data-var
define-map
define-public
define-read-only
define
delete-entry!
eq?
err
expects!
expects-err!
fetch-contract-entry
fetch-entry
fetch-var
filter
fold
get-block-info
get
hash160
if
insert-entry!
is-none?
is-ok?
keccak256
let
list
map
mod
not
ok
or
pow
print
set-entry!
set-var!
sha256
tuple
xor




Block Properties

The get-block-info function fetches property details for a block at a specified block height. For example:

(get-block-info time 10) ;; Returns 1557860301

Because the Clarity language is in pre-release, the block properties that are fetched are simulated properties from a SQLite database. The available property names are:

Property

Definition

header-hash

A 32-byte buffer containing the block hash.

burnchain-header-hash

A 32-byte buffer that contains the hash from the proof of burn.

vrf-seed

A 32-byte buffer containing the Verifiable Random Function (VRF) seed value used for the block.

time

An integer value containing that roughly corresponds to when the block was mined. This is a Unix epoch timestamp in seconds.

Warning: The time does not increase monotonically with each block. Block times are accurate only to within two hours. See BIP113 for more information.




Supported types

This section lists the types available to smart contracts. The only atomic types supported by the Clarity are booleans, integers, fixed length buffers, and principals.




Int type

The integer type in the Clarity language is a 16-byte signed integer, which allows it to specify the maximum amount of microstacks spendable in a single Stacks transfer. The special BlockHeightInt you can obtain with the get-block-info function.




Bool type

Supports values of 'true or 'false.




Buffer type

Buffer types represent fixed-length byte buffers. Currently, the only way to construct a Buffer is using string literals, for example "alice.id" or hash160("bob.id")

All of the hash functions return buffers:

hash160 sha256 keccak256

The block properties header-hash, burnchain-header-hash, and vrf-seed are all buffers.




List type

Clarity supports lists of the atomic types. However, the only variable length lists in the language appear as function inputs; there is no support for list operations like append or join.




Principal type

Clarity provides this primitive for checking whether or not the smart contract transaction was signed by a particular principal. Principals represent a spending entity and are roughly equivalent to a Stacks address. The principal’s signature is not checked by the smart contract, but by the virtual machine. A smart contract function can use the globally defined tx-sender variable to obtain the current principal.

Smart contracts may also be principals (represented by the smart contract’s identifier). However, there is no private key associated with the smart contract, and it cannot broadcast a signed transaction on the blockchain. A smart contract uses the special variable contract-name to refer to its own principal.




Tuple type

To support the use of named fields in keys and values, Clarity allows the construction of named tuples using a function (tuple ...), for example

(define imaginary-number-a (tuple (real 1) (i 2)))

(define imaginary-number-b (tuple (real 2) (i 3)))

This allows for creating named tuples on the fly, which is useful for data maps where the keys and values are themselves named tuples. Values in a given mapping are set or fetched using:

Function

Description

(fetch-entry map-name key-tuple)

Fetches the value associated with a given key in the map, or returns none if there is no such value.

(set-entry! map-name key-tuple value-tuple)

Sets the value of key-tuple in the data map

(insert-entry! map-name key-tuple value-tuple)

Sets the value of key-tuple in the data map if and only if an entry does not already exist.

(delete-entry! map-name key-tuple)

Deletes key-tuple from the data map.

To access a named value of a given tuple, the (get name tuple) function returns that item from the tuple.




Optional type

Represents an optional value. This is used in place of the typical usage of “null” values in other languages, and represents a type that can either be some value or none. Optional types are used as the return types of data-map functions.




Response type

Response types represent the result of a public function. Use this type to indicate and return data associated with the execution of the function. Also, the response should indicate whether the function error’ed (and therefore did not materialize any data in the database) or ran ok (in which case data materialized in the database).

Response types contain two subtypes – a response type in the event of ok (that is, a public function returns an integer code on success) and an err type (that is, a function returns a buffer on error).




Native variables

The Clarity language includes native variables you can use in your contract.




block-height

The height of a block in the Stacks blockchain. Block height is the number of blocks in the chain between any given block and the very first block in the blockchain. You can obtain a block-height via the get-block-info function.




contract-name

Represents the current contract.




tx-sender

Represents the current principal. This variable does not change during inter-contract calls. This means that if a transaction invokes a function in a given smart contract, that function is able to make calls into other smart contracts on your behalf. This enables a wide variety of applications, but it comes with some dangers for users of smart contracts. Static analysis of Clarity contracts guarantees the language allows clients to deduce which functions a given smart contract will ever call. Good clients should always warn users about any potential side effects of a given transaction.




Clarity function reference




* (multiply)

Syntax (* i1 i2...)

Input type:

int, ...

Output type:

int

Multiplies a variable number of integer inputs and returns the result. In the event of an overflow, throws a runtime error.




Example

(* 2 3) ;; Returns 6

(* 5 2) ;; Returns 10

(* 2 2 2) ;; Returns 8







+ (add)

Syntax (+ i1 i2...)

Input type:

int, ...

Output type:

int

Adds a variable number of integer inputs and returns the result. In the event of an overflow, throws a runtime error.




Example

(+ 1 2 3) ;; Returns 6







- (subtract)

Syntax (- i1 i2...)

Input type:

int, ...

Output type:

int

Subtracts a variable number of integer inputs and returns the result. In the event of an underflow, throws a runtime error.




Example

(- 2 1 1) ;; Returns 0

(- 0 3) ;; Returns -3







/ (divide)

Syntax (/ i1 i2...)

Input type:

int, ...

Output type:

int

Integer divides a variable number of integer inputs and returns the result. In the event of division by zero, throws a runtime error.




Example

(/ 2 3) ;; Returns 0

(/ 5 2) ;; Returns 2

(/ 4 2 2) ;; Returns 1







< (less than)

Syntax (< i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is less than i2 and false otherwise.




Example

(< 1 2) ;; Returns 'true

(< 5 2) ;; Returns 'false







<= (less than or equal)

Syntax (> i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is less than or equal to i2 and false otherwise.




Example

(<= 1 1) ;; Returns 'true

(<= 5 2) ;; Returns 'false







> (greater than)

Syntax (> i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is greater than i2 and false otherwise.




Example

(> 1 2) ;; Returns 'false

(> 5 2) ;; Returns 'true







>= (greater than or equal)

Syntax (>= i1 i2)

Input type:

int, int

Output type:

bool

Compares two integers, returning true if i1 is greater than or equal to i2 and false otherwise.




Example

(>= 1 1) ;; Returns 'true

(>= 5 2) ;; Returns 'true







and

Syntax (and b1 b2 ...)

Input type:

bool, ...

Output type:

bool

Returns true if all boolean inputs are true. Importantly, the supplied arguments are evaluated in-order and lazily. Lazy evaluation means that if one of the arguments returns false, the function short-circuits, and no subsequent arguments are evaluated.




Example

(and 'true 'false) ;; Returns 'false

(and (eq? (+ 1 2) 1) (eq? 4 4)) ;; Returns 'false

(and (eq? (+ 1 2) 3) (eq? 4 4)) ;; Returns 'true







as-contract

Syntax (as-contract expr)

Input type:

A

Output type:

A

The as-contract function switches the current context’s tx-sender value to the contract’s principal and executes expr with that context. It returns the resulting value of expr.




Example

(as-contract (print tx-sender)) ;; Returns 'CTcontract.name







begin

Syntax (begin expr1 expr2 expr3 ... expr-last)

Input type:

AnyType, ... A

Output type:

A

The begin function evaluates each of its input expressions, returning the return value of the last such expression.




Example

(begin (+ 1 2) 4 5) ;; Returns 5







contract-call!

Syntax (contract-call! contract-name function-name arg0 arg1 ...)

Input type:

ContractName, PublicFunctionName, Arg0, ...

Output type:

Response(A,B)

The contract-call! function executes the given public function of the given contract. You may not this function to call a public function defined in the current contract. If the public function returns err, any database changes resulting from calling contract-call! are aborted. If the function returns ok, database changes occurred.




Example

(contract-call! tokens transfer 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 19) ;; Returns (ok 1)







default-to

Syntax (default-to default-value option-value)

Input type:

A, Optional(A)

Output type:

A

The default-to function attempts to ‘unpack’ the second argument: if the argument is a (some ...) option, it returns the inner value of the option. If the second argument is a (none) value, default-to it returns the value of default-value.




Example

(default-to 0 (get id (fetch-entry names-map (tuple (name "blockstack"))))) ;; Returns 1337

(default-to 0 (get id (fetch-entry names-map (tuple (name "non-existant"))))) ;; Returns 0







define-data-var

Syntax (define-data-var var-name type value)

Input type:

VarName, TypeDefinition, Value

Output type:

Not Applicable

define-data-var is used to define a new persisted variable for use in a smart contract. Such variable are only modifiable by the current smart contract.

Persisted variable are defined with a type and a value.

Like other kinds of definition statements, define-data-var may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).




Example

(define-data-var size int 0)

(define (set-size (value int))

  (set-var! size value))

(set-size 1)

(set-size 2)







define-map

Syntax (define-map map-name ((key-name-0 key-type-0) ...) ((val-name-0 val-type-0) ...))

Input type:

MapName, KeyTupleDefinition, MapTupleDefinition

Output type:

Not Applicable

define-map is used to define a new datamap for use in a smart contract. Such maps are only modifiable by the current smart contract.

Maps are defined with a key tuple type and value tuple type. These are defined using a list of name and type pairs, e.g., a key type might be ((id int)), which is a tuple with a single “id” field of type int.

Like other kinds of definition statements, define-map may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).




Example

(define-map squares ((x int)) ((square int)))

(define (add-entry (x int))

  (insert-entry! squares ((x 2)) ((square (* x x)))))

(add-entry 1)

(add-entry 2)

(add-entry 3)

(add-entry 4)

(add-entry 5)







define-public

Syntax (define-public (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define-public is used to define a public function and transaction for a smart contract. Public functions are callable from other smart contracts and may be invoked directly by users by submitting a transaction to the Stacks blockchain.

Like other kinds of definition statements, define-public may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Public functions must return a ResponseType (using either ok or err). Any datamap modifications performed by a public function is aborted if the function returns an err type. Public functions may be invoked by other contracts via contract-call!.




Example

(define-public (hello-world (input int))

  (begin (print (+ 2 input))

         (ok input)))







define-read-only

Syntax (define-read-only (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define-read-only is used to define a public read-only function for a smart contract. Such functions are callable from other smart contracts.

Like other kinds of definition statements, define-read-only may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Read-only functions may return any type. However, read-only functions may not perform any datamap modifications, or call any functions which perform such modifications. This is enforced both during type checks and during the execution of the function. Public read-only functions may be invoked by other contracts via contract-call!.




Example

(define-read-only (just-return-one-hundred)

  (* 10 10))







define

Syntax (define (function-name (arg-name-0 arg-type-0) (arg-name-1 arg-type-1) ...) function-body)

Input type:

MethodSignature, MethodBody

Output type:

Not Applicable

define is used to define private functions for a smart contract. Private functions may not be called from other smart contracts, nor may they be invoked directly by users. Instead, these functions may only be invoked by other functions defined in the same smart contract.

Like other kinds of definition statements, define may only be used at the top level of a smart contract definition (i.e., you cannot put a define statement in the middle of a function body).

Private functions may return any type.




Example

(define (max-of (i1 int) (i2 int))

  (if (> i1 i2)

      i1

      i2))

(max-of 4 6) ;; returns 6







delete-entry!

Syntax (delete-entry! map-name key-tuple)

Input type:

MapName, Tuple

Output type:

bool

The delete-entry! function removes the value associated with the input key for the given map. If an item exists and is removed, the function returns true. If a value did not exist for this key in the data map, the function returns false.




Example

(delete-entry! names-map (tuple (name "blockstack"))) ;; Returns 'true

(delete-entry! names-map (tuple (name "blockstack"))) ;; Returns 'false

(delete-entry! names-map ((name "blockstack"))) ;; Same command, using a shorthand for constructing the tuple







eq?

Syntax (eq? v1 v2...)

Input type:

A, A, ...

Output type:

bool

Compares the inputted values, returning true if they are all equal. Note that unlike the (and ...) function, (eq? ...) will not short-circuit.




Example

(eq? 1 1) ;; Returns 'true

(eq? 1 'false) ;; Returns 'false

(eq? "abc" 234 234) ;; Returns 'false







err

Syntax (err value)

Input type:

A

Output type:

Response(A,B)

The err function constructs a response type from the input value. Use err for creating return values in public functions. An err value indicates that any database changes during the processing of the function should be rolled back.




Example

(err 'true) ;; Returns (err 'true)







expects!

Syntax (expects! option-input thrown-value)

Input type:

Optional(A) | Response(A,B), C

Output type:

A

The expects! function attempts to ‘unpack’ the first argument: if the argument is an option type, and the argument is a (some ...) option, expects! returns the inner value of the option. If the argument is a response type, and the argument is an (ok ...) response, expects! returns the inner value of the ok. If the supplied argument is either an (err ...) or a (none) value, expects! returns thrown-value from the current function and exits the current control-flow.




Example

(expects! (fetch-entry names-map (tuple (name "blockstack"))) (err 1)) ;; Returns (tuple (id 1337))







expects-err!

Syntax (expects-err! response-input thrown-value)

Input type:

Response(A,B), C

Output type:

B

The expects-err! function attempts to ‘unpack’ the first argument: if the argument is an (err ...) response, expects-err! returns the inner value of the err. If the supplied argument is an (ok ...) value, expects-err! returns thrown-value from the current function and exits the current control-flow.




Example

(expects-err! (err 1) 'false) ;; Returns 1







fetch-contract-entry

Syntax (fetch-contract-entry contract-name map-name key-tuple)

Input type:

ContractName, MapName, Tuple

Output type:

Optional(Tuple)

The fetch-contract-entry function looks up and returns an entry from a contract other than the current contract’s data map. The value is looked up using key-tuple. If there is no value associated with that key in the data map, the function returns a (none) option. Otherwise, it returns (some value).




Example

(expects! (fetch-contract-entry names-contract names-map (tuple (name "blockstack")) (err 1))) ;; Returns (tuple (id 1337))

(expects! (fetch-contract-entry names-contract names-map ((name "blockstack")) (err 1)));; Same command, using a shorthand for constructing the tuple







fetch-entry

Syntax (fetch-entry map-name key-tuple)

Input type:

MapName, Tuple

Output type:

Optional(Tuple)

The fetch-entry function looks up and returns an entry from a contract’s data map. The value is looked up using key-tuple. If there is no value associated with that key in the data map, the function returns a (none) option. Otherwise, it returns (some value)




Example

(expects! (fetch-entry names-map (tuple (name "blockstack"))) (err 1)) ;; Returns (tuple (id 1337))

(expects! (fetch-entry names-map ((name "blockstack"))) (err 1)) ;; Same command, using a shorthand for constructing the tuple







fetch-var

Syntax (fetch-var var-name)

Input type:

VarName

Output type:

A

The fetch-var function looks up and returns an entry from a contract’s data map. The value is looked up using var-name.




Example

(fetch-var cursor) ;; Returns cursor







filter

Syntax (filter func list)

Input type:

Function(A) -> bool, (list A)

Output type:

(list A)

The filter function applies the input function func to each element of the input list, and returns the same list with any elements removed for which the func returned false.




Example

(filter not (list true false true false)) ;; Returns (list false false)







fold

Syntax (fold func list initial-value)

Input type:

Function(A, B) -> B, (list A)

Output type:

B

The fold function applies the input function func to each element of the input list and the output of the previous application of the fold function. When invoked on the first list element, it uses the initial-value as the second input. fold returns the last value return by the successive applications.




Example

(fold * (list 2 2 2) 1) ;; Returns 8

(fold * (list 2 2 2) 0) ;; Returns 0







get-block-info

Syntax (get-block-info prop-name block-height-expr)

Input type:

BlockInfoPropertyName, BlockHeightInt

Output type:

buff | int

The get-block-info function fetches data for a block of the given block height. The value and type returned are determined by the specified BlockInfoPropertyName. If the provided BlockHeightInt does not correspond to an existing block, the function is aborted. The currently available property names are time, header-hash, burnchain-header-hash, and vrf-seed.

The time property returns an integer value of the block header time field. This is a Unix epoch timestamp in seconds which roughly corresponds to when the block was mined. Warning: this does not increase monotonically with each block and block times are accurate only to within two hours. See BIP113 for more information.

The header-hash, burnchain-header-hash, and vrf-seed properties return a 32-byte buffer.




Example

(get-block-info time 10) ;; Returns 1557860301

(get-block-info header-hash 2) ;; Returns 0x374708fff7719dd5979ec875d56cd2286f6d3cf7ec317a3b25632aab28ec37bb

(get-block-info vrf-seed 6) ;; Returns 0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4







get

Syntax (get key-name tuple)

Input type:

KeyName and Tuple | Optional(Tuple)

Output type:

AnyType

The get function fetches the value associated with a given key from the supplied typed tuple. If an Optional value is supplied as the inputted tuple, get returns an Optional type of the specified key in the tuple. If the supplied option is a (none) option, get returns (none).




Example

(get id (tuple (name "blockstack") (id 1337))) ;; Returns 1337

(get id (fetch-entry names-map (tuple (name "blockstack")))) ;; Returns (some 1337)

(get id (fetch-entry names-map (tuple (name "non-existent")))) ;; Returns (none)







hash160

Syntax (hash160 value)

Input type:

buff|int

Output type:

(buff 20)

The hash160 function computes RIPEMD160(SHA256(x)) of the inputted value. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(hash160 0) ;; Returns 0xe4352f72356db555721651aa612e00379167b30f







if

Syntax (if bool1 expr1 expr2)

Input type:

bool, A, A

Output type:

A

The if function admits a boolean argument and two expressions which must return the same type. In the case that the boolean input is true, the if function evaluates and returns expr1. If the boolean input is false, the if function evaluates and returns expr2.




Example

(if true 1 2) ;; Returns 1

(if (> 1 2) 1 2) ;; Returns 2







insert-entry!

Syntax (insert-entry! map-name key-tuple value-tuple)

Input type:

MapName, TupleA, TupleB

Output type:

bool

The insert-entry! function sets the value associated with the input key to the inputted value if and only if there is not already a value associated with the key in the map. If an insert occurs, the function returns true. If a value already existed for this key in the data map, the function returns false.




Example

(insert-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'true

(insert-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'false

(insert-entry! names-map ((name "blockstack")) ((id 1337))) ;; Same command, using a shorthand for constructing the tuple







is-none?

Syntax (is-none? value)

Input type:

Optional(A)

Output type:

bool

is-none? tests a supplied option value, returning true if the option value is (none), and false if it is a (some ...).




Example

(is-none? (get id (fetch-entry names-map (tuple (name "blockstack"))))) ;; Returns 'false

(is-none? (get id (fetch-entry names-map (tuple (name "non-existant"))))) ;; Returns 'true







is-ok?

Syntax (is-ok? value)

Input type:

Response(A,B)

Output type:

bool

is-ok? tests a supplied response value, returning true if the response was ok, and false if it was an err.




Example

(is-ok? (ok 1)) ;; Returns 'true

(is-ok? (err 1)) ;; Returns 'false







keccak256

Syntax (keccak256 value)

Input type:

buff|int

Output type:

(buff 32)

The keccak256 function computes KECCAK256(value) of the inputted value. Note that this differs from the NIST SHA-3 (that is, FIPS 202) standard. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(keccak256 0) ;; Returns 0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4







let

Syntax (let ((name1 expr1) (name2 expr2) ...) expr-body)

Input type:

((name2 AnyType) (name2 AnyType) ...), A

Output type:

A

The let function accepts a list of variable name and expression pairs, evaluating each expression and binding it to the corresponding variable name. The context created by this set of bindings is used for evaluating and return the value of expr-body.




Example

(let ((a 2) (b (+ 5 6 7))) (+ a b)) ;; Returns 20







list

Syntax (list expr1 expr2 expr3 ...)

Input type:

A, ...

Output type:

(list A)

The list function constructs a list composed of the inputted values. Each supplied value must be of the same type.




Example

(list (+ 1 2) 4 5) ;; Returns [3 4 5]







map

Syntax (map func list)

Input type:

Function(A) -> B, (list A)

Output type:

(list B)

The map function applies the input function func to each element of the input list, and outputs a list containing the outputs from those function applications.




Example

(map not (list true false true false)) ;; Returns 'false true false true







mod

Syntax (mod i1 i2)

Input type:

int, int

Output type:

int

Returns the integer remainder from integer dividing i1 by i2. In the event of a division by zero, throws a runtime error.




Example

(mod 2 3) ;; Returns 0

(mod 5 2) ;; Returns 1

(mod 7 1) ;; Returns 0







not

Syntax (not b1)

Input type:

bool

Output type:

bool

Returns the inverse of the boolean input.




Example

(not 'true) ;; Returns 'false

(not (eq? 1 2)) ;; Returns 'true







ok

Syntax (ok value)

Input type:

A

Output type:

Response(A,B)

The ok function constructs a response type from the input value. Use ok for creating return values in public functions. An ok value indicates that any database changes during the processing of the function should materialize.




Example

(ok 1) ;; Returns (ok 1)







or

Syntax (or b1 b2 ...)

Input type:

bool, ...

Output type:

bool

Returns true if any boolean inputs are true. Importantly, the supplied arguments are evaluated in-order and lazily. Lazy evaluation means that if one of the arguments returns false, the function short-circuits, and no subsequent arguments are evaluated.




Example

(or 'true 'false) ;; Returns 'true

(or (eq? (+ 1 2) 1) (eq? 4 4)) ;; Returns 'true

(or (eq? (+ 1 2) 1) (eq? 3 4)) ;; Returns 'false

(or (eq? (+ 1 2) 3) (eq? 4 4)) ;; Returns 'true







pow

Syntax (pow i1 i2)

Input type:

int, int

Output type:

int

Returns the result of raising i1 to the power of i2. In the event of an overflow, throws a runtime error.




Example

(pow 2 3) ;; Returns 8

(pow 2 2) ;; Returns 4

(pow 7 1) ;; Returns 7







print

Syntax (print expr)

Input type:

A

Output type:

A

The print function evaluates and returns its input expression. On Blockstack Core nodes configured for development (as opposed to production mining nodes), this function prints the resulting value to STDOUT (standard output).




Example

(print (+ 1 2 3)) ;; Returns 6







set-entry!

Syntax (set-entry! map-name key-tuple value-tuple)

Input type:

MapName, TupleA, TupleB

Output type:

bool

The set-entry! function sets the value associated with the input key to the inputted value. This function performs a blind update; whether or not a value is already associated with the key, the function overwrites that existing association.




Example

(set-entry! names-map (tuple (name "blockstack")) (tuple (id 1337))) ;; Returns 'true

(set-entry! names-map ((name "blockstack")) ((id 1337))) ;; Same command, using a shorthand for constructing the tuple







set-var!

Syntax (set-var! var-name expr1)

Input type:

VarName, AnyType

Output type:

bool

The set-var! function sets the value associated with the input variable to the inputted value.




Example

(set-var! cursor (+ cursor 1)) ;; Returns 'true







sha256

Syntax (sha256 value)

Input type:

buff|int

Output type:

(buff 32)

The sha256 function computes SHA256(x) of the inputted value. If an integer (128 bit) is supplied the hash is computed over the little-endian representation of the integer.




Example

(sha256 0) ;; Returns 0x374708fff7719dd5979ec875d56cd2286f6d3cf7ec317a3b25632aab28ec37bb







tuple

Syntax (tuple ((key0 expr0) (key1 expr1) ...))

Input type:

(list (KeyName AnyType))

Output type:

Tuple

The tuple function constructs a typed tuple from the supplied key and expression pairs. A get function can use typed tuples as input to select specific values from a given tuple. Key names may not appear multiple times in the same tuple definition. Supplied expressions are evaluated and associated with the expressions’ paired key name.




Example

(tuple (name "blockstack") (id 1337))







xor

Syntax (xor i1 i2)

Input type:

int, int

Output type:

int

Returns the result of bitwise exclusive or’ing i1 with i2.




Example

(xor 1 2) ;; Returns 3

(xor 120 280) ;; Returns 352
326
Views

Quickstart for the SDK

blockstack app store posted the article • 0 comments • 326 views • 2019-06-28 01:40 • data from similar tags

You can use the software developer kit (SDK) to develop, test, and deploy Clarity smart contracts. The SDK goes beyond the basic test environment to allow for development of Javascript or TypeScript clients that call upon Clarity contracts.

About this tutorial and the prerequisites you need
Task 1: Generate an initial Clarity project
Task 2: Investigate the generated project
Task 3: Try to expand the contract

 
About this tutorial and the prerequisites you need
 
Note: This tutorial was written on macOS High Sierra 10.13.4. If you use a Windows or Linux system, you can still follow along. However, you will need to "translate" appropriately for your operating system.
 
 
For this tutorial, you will use npm to manage dependencies and scripts. The tutorial relies on the npm dependency manager. Before you begin, verify you have installed npm using the which command to verify.
 $ which npm
/usr/local/bin/npm
If you don’t find npm in your system, install it.

You use npm to install Yeoman. Yeoman is a generic scaffolding system that helps users rapidly start new projects and streamline the maintenance of existing projects. Verify you have installed yo using the which command.
 $ which yo
/usr/local/bin/yo
 
If you don’t have Yeoman, you can install it with the npm install -g yo command.
 
Task 1: Generate an initial Clarity project

The SDK uses Yeoman to generate a project scaffold — an initial set of directories and files.

1. Create a new directory for your project.
  mkdir hello-clarity-sdk2. Change into your new project directory.cd hello-clarity-sdk3. Use the npm command to initialize a Clarity project.
 npm init yo clarity-dev npx: installed 15 in 1.892s create package.json create .vscode/extensions.json ... Project created at /private/tmp/hello-clarity-sdk ✔ create-yo ok!Depending on your connection speed, it may take time to construct the scaffolding.
 
Task 2: Investigate the generated project
 
Your project should contain three directories:
 

 
 
The contracts directory contains a single file in sample/hello-world.clar file.
 (define (hello-world)
"hello world")

(define (echo-number (val int))
val)


 
The contract exposes 2 rudimentary functions. The say-hi returns a hello world string. The increment-number: echos val.

The project also includes tests/hello-world.ts file. The test is written in Typescript. You can also write tests in Javascript.
 
 import { Client, Provider, ProviderRegistry, Result } from "@blockstack/clarity";
import { assert } from "chai";

describe("hello world contract test suite", () => {
let helloWorldClient: Client;
let provider: Provider;

before(async () => {
provider = await ProviderRegistry.createProvider();
helloWorldClient = new Client("hello-world", "sample/hello-world", provider);
});

it("should have a valid syntax", async () => {
await helloWorldClient.checkContract();
});

describe("deploying an instance of the contract", () => {
before(async () => {
await helloWorldClient.deployContract();
});

it("should print hello world message", async () => {
const query = helloWorldClient.createQuery({ method: { name: "hello-world", args: } });
const receipt = await helloWorldClient.submitQuery(query);
const result = Result.unwrap(receipt);
const parsedResult = Buffer.from(result.replace("0x", ""), "hex").toString();
assert.equal(parsedResult, "hello world");
});

it("should echo number", async () => {
const query = helloWorldClient.createQuery({
method: { name: "echo-number", args: ["123"] }
});
const receipt = await helloWorldClient.submitQuery(query);
const result = Result.unwrap(receipt);
assert.equal(result, "123");
});
});

after(async () => {
await provider.close();
});
});
 
 
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.
 npm run test

> [email protected] test /private/tmp/hello-clarity-sdk
> mocha



hello world contract test suite
✓ should have a valid syntax
deploying an instance of the contract
✓ should print hello world message
✓ should echo number


3 passing (182ms)
 
In the next section, try your hand at expanding the hello-world.clar program.
 
Task 3: Try to expand the contract

In this task, you are challenged to expand the contents of the contracts/hello-world.clar file. Use your favorite editor and open the contracts/hello-world.clar file. If you use Visual Studio Code, you can install the Blockstack Clarity extension. The extension provides syntax coloration and some autocompletion.

Edit the hello-world.clar file.
 ;; Functions

(define (hello-world)
"hello world")

(define (echo-number (val int))
val)


Use the + function to create a increment-number-by-10 function.
 
answer:
 ;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))


Use the + and - function to create a decrement-number user-defined method.
 
 
answer: ;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))

(define (decrement-number (number int))
(- number 1))
Finally, try adding a counter variable and be sure to store it. Increment counter in your code and add a get-counter funtion to return the result. Here is a hint, you can add a var` to a contract by adding the following line (before the function):
 
 

```cl ;; Storage (define-data-var internal-value int 0)
 
 
 
answer:
 
 ;; Storage

(define-data-var counter int 0)

;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))

(define (decrement-number (number int))
(- number 1))

(define (increment-counter)
(set-var! counter (+ 1 counter)))

(define (get-counter)
(counter))
 
To review other, longer sample programs visit the clarity-js-sdk repository.
 
 
  view all
You can use the software developer kit (SDK) to develop, test, and deploy Clarity smart contracts. The SDK goes beyond the basic test environment to allow for development of Javascript or TypeScript clients that call upon Clarity contracts.


About this tutorial and the prerequisites you need
Task 1: Generate an initial Clarity project
Task 2: Investigate the generated project
Task 3: Try to expand the contract


 
About this tutorial and the prerequisites you need
 
Note: This tutorial was written on macOS High Sierra 10.13.4. If you use a Windows or Linux system, you can still follow along. However, you will need to "translate" appropriately for your operating system.
 
 
For this tutorial, you will use npm to manage dependencies and scripts. The tutorial relies on the npm dependency manager. Before you begin, verify you have installed npm using the which command to verify.
 
$ which npm
/usr/local/bin/npm

If you don’t find npm in your system, install it.

You use npm to install Yeoman. Yeoman is a generic scaffolding system that helps users rapidly start new projects and streamline the maintenance of existing projects. Verify you have installed yo using the which command.
 
$ which yo
/usr/local/bin/yo

 
If you don’t have Yeoman, you can install it with the npm install -g yo command.
 
Task 1: Generate an initial Clarity project

The SDK uses Yeoman to generate a project scaffold — an initial set of directories and files.

1. Create a new directory for your project.
 
 mkdir hello-clarity-sdk
2. Change into your new project directory.
cd hello-clarity-sdk
3. Use the npm command to initialize a Clarity project.
 
npm init yo clarity-dev npx: installed 15 in 1.892s create package.json create .vscode/extensions.json ... Project created at /private/tmp/hello-clarity-sdk ✔ create-yo ok!
Depending on your connection speed, it may take time to construct the scaffolding.
 
Task 2: Investigate the generated project
 
Your project should contain three directories:
 

 
 
The contracts directory contains a single file in sample/hello-world.clar file.
 
(define (hello-world)
"hello world")

(define (echo-number (val int))
val)


 
The contract exposes 2 rudimentary functions. The say-hi returns a hello world string. The increment-number: echos val.

The project also includes tests/hello-world.ts file. The test is written in Typescript. You can also write tests in Javascript.
 
 
import { Client, Provider, ProviderRegistry, Result } from "@blockstack/clarity";
import { assert } from "chai";

describe("hello world contract test suite", () => {
let helloWorldClient: Client;
let provider: Provider;

before(async () => {
provider = await ProviderRegistry.createProvider();
helloWorldClient = new Client("hello-world", "sample/hello-world", provider);
});

it("should have a valid syntax", async () => {
await helloWorldClient.checkContract();
});

describe("deploying an instance of the contract", () => {
before(async () => {
await helloWorldClient.deployContract();
});

it("should print hello world message", async () => {
const query = helloWorldClient.createQuery({ method: { name: "hello-world", args: } });
const receipt = await helloWorldClient.submitQuery(query);
const result = Result.unwrap(receipt);
const parsedResult = Buffer.from(result.replace("0x", ""), "hex").toString();
assert.equal(parsedResult, "hello world");
});

it("should echo number", async () => {
const query = helloWorldClient.createQuery({
method: { name: "echo-number", args: ["123"] }
});
const receipt = await helloWorldClient.submitQuery(query);
const result = Result.unwrap(receipt);
assert.equal(result, "123");
});
});

after(async () => {
await provider.close();
});
});

 
 
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.
 
npm run test

> [email protected] test /private/tmp/hello-clarity-sdk
> mocha



hello world contract test suite
✓ should have a valid syntax
deploying an instance of the contract
✓ should print hello world message
✓ should echo number


3 passing (182ms)

 
In the next section, try your hand at expanding the hello-world.clar program.
 
Task 3: Try to expand the contract

In this task, you are challenged to expand the contents of the contracts/hello-world.clar file. Use your favorite editor and open the contracts/hello-world.clar file. If you use Visual Studio Code, you can install the Blockstack Clarity extension. The extension provides syntax coloration and some autocompletion.

Edit the hello-world.clar file.
 
;; Functions

(define (hello-world)
"hello world")

(define (echo-number (val int))
val)


Use the + function to create a increment-number-by-10 function.
 
answer:
 
;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))


Use the + and - function to create a decrement-number user-defined method.
 
 
answer:
 ;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))

(define (decrement-number (number int))
(- number 1))
Finally, try adding a counter variable and be sure to store it. Increment counter in your code and add a get-counter funtion to return the result. Here is a hint, you can add a var` to a contract by adding the following line (before the function):
 
 

```cl ;; Storage (define-data-var internal-value int 0)
 
 
 
answer:
 
 
;; Storage

(define-data-var counter int 0)

;; Functions

(define (say-hi)
"hello world")

(define (increment-number (number int))
(+ 1 number))

(define (increment-number-by-10 (number int))
(+ 10 number))

(define (decrement-number (number int))
(- number 1))

(define (increment-counter)
(set-var! counter (+ 1 counter)))

(define (get-counter)
(counter))

 
To review other, longer sample programs visit the clarity-js-sdk repository.
 
 
 
235
Views

clarity smart contract language - cli command line

blockstack app store posted the article • 0 comments • 235 views • 2019-06-28 01:27 • data from similar tags

 
 
 
 
You use the clarity-cli command to work with smart contracts within the Blockstack virtual environment. This command has the following subcommands:
 
 
 

initialize
mine_block
get_block_height
check
launch
eval
eval_raw
repl
execute
generate_address

 
initialize
clarity-cli initialize [vm-state.db]Initializes a local VM state database. If the database exists, this command throws an error.
 
mine_block
 
clarity-cli mine_block [block time] [vm-state.db]Simulates mining a new block.

get_block_height
 
clarity-cli get_block_height [vm-state.db]
Prints the simulated block height.
 
 
 
check
 
clarity-cli check [program-file.scm] (vm-state.db)
Type checks a potential contract definition.

launch
 
clarity-cli launch [contract-name] [contract-definition.scm] [vm-state.db]Launches a new contract in the local VM state database.
 
eval
 
clarity-cli eval [context-contract-name] (program.scm) [vm-state.db]Evaluates, in read-only mode, a program in a given contract context.

eval_raw
 
Type check and evaluate an expression for validity inside of a function’s source. It does not evaluate within a contract or database context.

repl
 
 
clarity-cli repl
Type check and evaluate expressions in a stdin/stdout loop.

execute
 
clarity-cli execute [vm-state.db] [contract-name] [public-function-name] [sender-address] [args...]
Executes a public function of a defined contract.

generate_address
 
clarity-cli generate_addressGenerates a random Stacks public address for testing purposes.
 
  view all
 
 
 
 
You use the clarity-cli command to work with smart contracts within the Blockstack virtual environment. This command has the following subcommands:
 
 
 


initialize
mine_block
get_block_height
check
launch
eval
eval_raw
repl
execute
generate_address


 
initialize
clarity-cli initialize [vm-state.db]
Initializes a local VM state database. If the database exists, this command throws an error.
 
mine_block
 
clarity-cli mine_block [block time] [vm-state.db]
Simulates mining a new block.

get_block_height
 
clarity-cli get_block_height [vm-state.db]

Prints the simulated block height.
 
 
 
check
 
clarity-cli check [program-file.scm] (vm-state.db)

Type checks a potential contract definition.

launch
 
clarity-cli launch [contract-name] [contract-definition.scm] [vm-state.db]
Launches a new contract in the local VM state database.
 
eval
 
clarity-cli eval [context-contract-name] (program.scm) [vm-state.db]
Evaluates, in read-only mode, a program in a given contract context.

eval_raw
 
Type check and evaluate an expression for validity inside of a function’s source. It does not evaluate within a contract or database context.

repl
 
 
clarity-cli repl
Type check and evaluate expressions in a stdin/stdout loop.

execute
 
clarity-cli execute [vm-state.db] [contract-name] [public-function-name] [sender-address] [args...]

Executes a public function of a defined contract.

generate_address
 
clarity-cli generate_address
Generates a random Stacks public address for testing purposes.
 
 
286
Views

Hello Clarity tutorial

blockstack app store posted the article • 0 comments • 286 views • 2019-06-28 01:16 • data from similar tags

In this tutorial, you learn how to use Clarity, Blockstack’s smart contracting language. Use this tutorial to get a quick introduction to Clarity and the default Blockstack test environment.

Before you begin (pre-requisites)
Task 1: Set up the test environment
Task 2: Review a simple Clarity program
Task 3: Initialize data-space and launch contracts
Task 4. Examine the SQLite database
Task 5: Execute a public function
Task 6: Spend tokens by registering a name

 
Before you begin (pre-requisites)
 
The Clarity language goes live in the next Stacks blockchain fork. Until the fork, you can run Clarity in a test environment. You run this test environment in a Docker container. Before you begin this tutorial, make sure you have Docker installed on your workstation.

If for some reason you don’t want to run the test environment with Docker, you can build and maintain a local environment. Instructions for downloading and building the environment are available in the blockstack/blockstack-core repository’s README file.
 
Task 1: Set up the test environment
 
Blockstack publishes the clarity-developer-preview image on Docker hub. A container built from this image contains sample programs, the Blockstack Core, and tools for working with them. In this task, you use Docker to pull and and run the image on your local workstation.
 
 
1. Pull the Blockstack core clarity-developer-preview image from Docker Hub.
  $ docker pull blockstack/blockstack-core:clarity-developer-preview2. Start the Blockstack Core test environment with a Bash shell.$ docker run -it -v $HOME/blockstack-dev-data:/data/ blockstack/blockstack-core:clarity-developer-preview bash
 
The launches a container with the Clarity test environment and opens a bash shell into the container. The -v flag creates a local $HOME/blockstack-dev-data directory in your workstation and mounts it at the /data directory inside the container. The shell opens into the src/blockstack-core directory. This directory contains the source for a core and includes Clarity contract samples you can run.
 
 3. List the contents of the sample-programs directory.
 

[email protected]:/src/blockstack-core# ls sample-programs/ names.clar tokens.clar
 
 
 
The sample programs directory contains two simple Clarity programs. Clarity code files have a .clar suffix.
 
 
 
4. Go ahead and display the contents of the tokens.clar program with the cat [email protected]:/src/blockstack-core# cat sample-programs/tokens.clarThe next section gives you an introduction to the Clarity language by way of examining this program’s code.
 
 
Task 2: Review a simple Clarity program
 
If you haven’t already done so, use the cat or more command to display the tokens.clar file’s code. Clarity is designed for static analysis; it is not a compiled language and is not Turing complete. It language is a LISP-like language. LISP is an acronym for list processing.

The first line of the tokens.clar program contains a user-defined get-balance function.
 
 
 (define (get-balance (account principal))
(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.

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.

Along with the principal types, Clarity supports booleans, integers, and fixed length buffers. Variables are created via let binding but there is no support for mutating functions like set.

The next sequence of lines shows an if statement that allows you to set conditions for execution in the language..
 
 (define (token-credit! (account principal) (tokens int))
(if (<= tokens 0)
(err "must move positive balance")
(let ((current-amount (get-balance account)))
(begin
(set-entry! tokens (tuple (account account))
(tuple (balance (+ tokens current-amount))))
(ok tokens)))))


 
Every smart contract has both a data space and code. The data space of a contract may only interact with that contract. This particular function is interacting with a map named tokens. The set-entry! function is a native function that sets the value associated with the input key to the inputted value in the tokens data map. Because set-entry! mutates data so it has an ! exclamation point; this is by convention in Clarity.

In the first token-transfer public function, you see that it calls the private get-balance function and passes it tx-sender. The tx-sender isa a globally defined variable that represents the the current principal.
 (define-public (token-transfer (to principal) (amount int))
(let ((balance (get-balance tx-sender)))
(if (or (> amount balance) (<= amount 0))
(err "must transfer positive balance and possess funds")
(begin
(set-entry! tokens (tuple (account tx-sender))
(tuple (balance (- balance amount))))
(token-credit! to amount)))))

(define-public (mint! (amount int))
(let ((balance (get-balance tx-sender)))
(token-credit! tx-sender amount)))

(token-credit! 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 10000)
(token-credit! 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G 300)


 
The final two lines of the program pass a principal, represented by a Stacks address, and an amount to the private user-defined token-credit function.

Smart contracts may call other smart contracts using a contract-call! function. This means that if a transaction invokes a function in a given smart contract, that function is able to make calls into other smart contracts on your behalf. The ability to read and do a static analysis of Clarity code allows clients to learn which functions a given smart contract will ever call. Good clients should always warn users about any potential side effects of a given transaction.

Take a moment to cat the contents of the names.clar file.
 cat names.clar


 
Which tokens.clar function is being called?
 
Task 3: Initialize data-space and launch contracts
 
1. In this task, you interact with the the contracts using the clarity-cli command line.

Initialize a new db database in the /data/ directory
  # clarity-cli initialize /data/db
Database created

You should see a message saying Database created. The command creates an SQLlite database. The database is available in the container and also in your workstation. In this tutorial, your workstation mount should at this point contain the $HOME/blockstack-dev-data/db directory.
 
2. Type check the names.clar contract.
 
  # clarity-cli check sample-programs/names.clar /data/db
You should get an error:Type check error. NoSuchContract("tokens")This happens because the names.clar contract calls the tokens.clar contract, and that contract has not been created on the blockchain.

3.  Type check the tokens.clar contract, it should pass a check as it does not use the contract-call function:
  # clarity-cli check sample-programs/tokens.clar /data/db
Checks passed.When the check command executes successfully and exits with the stand UNIX 0 exit code.
 
4. Launch the tokens.clar contract.
 
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.
  # clarity-cli launch tokens sample-programs/tokens.clar /data/db
Contract initialized!
Once launched, you can execute the contract or a public method on the contract. Your development database has an instantiated tokens contract. If you were to close the container and restart it later with the same mount point and you wouldn’t need to relaunch that database; it persists until you remove it from your local drive.

5. Recheck the names.clar contract. # clarity-cli check sample-programs/names.clar /data/db
The program should pass validation because its dependency on tokens.clar is fulfilled.

6. Instantiate the names.clar contract as well.
 # clarity-cli launch names sample-programs/names.clar /data/dbTask 4. Examine the SQLite database

The test environment uses a SQLite database to represent the blockchain. You initialized this database when you ran this earlier:
 clarity-cli initialize /data/dbAs you work the contracts, data is added to the db database because you pass this database as a parameter, for example:
 clarity-cli 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:

 
 
 
While not required, you can install SQLite in your local environment and use it to examine the data associated with and impacted by your contract. For example, this what the maps_table contains after you initialize the tokens contract.
 sqlite> select * from maps_table;
1|tokens|tokens|{"Atom":{"TupleType":{"type_map":{"account":{"Atom":"PrincipalType"}}}}}|{"Atom":{"TupleType":{"type_map":{"balance":{"Atom":"IntType"}}}}}
sqlite>
Task 5: Execute a public function
 
In this section, you use the public mint! function in the tokens contract to mint some new tokens.

1. Use the clarity_cli command to create a demo address.

# clarity-cli generate_address SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG

2. Add the address to your environment.

# DEMO_ADDRESS=SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG

3. Get the current balance of your new address.

# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db Program executed successfully! Output: 0

This command uses the private get-balance function in the tokens contract and pipes the result to the eval subcommand. The eval subcommand lets you evaluate both public and private functions of a contract in read-only mode.

4. Try minting some tokens and sending them to an address we’ll use for our demo.

# clarity-cli 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.

# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db Program executed successfully! Output: 100000
 
 
Task 6: Spend tokens by registering a name
 
Now, let’s register a name using the names.clar contract. Names are just integers in this sample contract, so you’ll register the name 10.

Compute the hash of the name we want to register.

You’ll salt the hash with the salt 8888:
  # echo "(hash160 (xor 10 8888))" | clarity-cli eval names /data/db
Program executed successfully! Output:
0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde
The value of the name hash is:
  0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde2. Preorder the name using the execute command:# clarity-cli execute /data/db names preorder $DEMO_ADDRESS 0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde 1000
Transaction executed and committed. Returned: 0This executes the public preorder function defined in the names.clar contract. The function reserves a name by paying the name fee (in this case, 1000 tokens).

3. Check the demo address’ new balance:# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db
Program executed successfully! Output:
99000
4. Register the name by executing the register function:
 # 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

5. Lookup the “owner address” for the name:
 

# echo "(get owner (fetch-entry name-map (tuple (name 10))))" | clarity-cli eval names /data/db Program executed successfully! Output: (some 'SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG)
 
  view all
In this tutorial, you learn how to use Clarity, Blockstack’s smart contracting language. Use this tutorial to get a quick introduction to Clarity and the default Blockstack test environment.


Before you begin (pre-requisites)
Task 1: Set up the test environment
Task 2: Review a simple Clarity program
Task 3: Initialize data-space and launch contracts
Task 4. Examine the SQLite database
Task 5: Execute a public function
Task 6: Spend tokens by registering a name


 
Before you begin (pre-requisites)
 
The Clarity language goes live in the next Stacks blockchain fork. Until the fork, you can run Clarity in a test environment. You run this test environment in a Docker container. Before you begin this tutorial, make sure you have Docker installed on your workstation.

If for some reason you don’t want to run the test environment with Docker, you can build and maintain a local environment. Instructions for downloading and building the environment are available in the blockstack/blockstack-core repository’s README file.
 
Task 1: Set up the test environment
 
Blockstack publishes the clarity-developer-preview image on Docker hub. A container built from this image contains sample programs, the Blockstack Core, and tools for working with them. In this task, you use Docker to pull and and run the image on your local workstation.
 
 
1. Pull the Blockstack core clarity-developer-preview image from Docker Hub.
 
 $ docker pull blockstack/blockstack-core:clarity-developer-preview
2. Start the Blockstack Core test environment with a Bash shell.
$ docker run -it -v $HOME/blockstack-dev-data:/data/ blockstack/blockstack-core:clarity-developer-preview bash

 
The launches a container with the Clarity test environment and opens a bash shell into the container. The -v flag creates a local $HOME/blockstack-dev-data directory in your workstation and mounts it at the /data directory inside the container. The shell opens into the src/blockstack-core directory. This directory contains the source for a core and includes Clarity contract samples you can run.
 
 3. List the contents of the sample-programs directory.
 

[email protected]:/src/blockstack-core# ls sample-programs/ names.clar tokens.clar
 
 
 
The sample programs directory contains two simple Clarity programs. Clarity code files have a .clar suffix.
 
 
 
4. Go ahead and display the contents of the tokens.clar program with the cat command.
[email protected]:/src/blockstack-core# cat sample-programs/tokens.clar
The next section gives you an introduction to the Clarity language by way of examining this program’s code.
 
 
Task 2: Review a simple Clarity program
 
If you haven’t already done so, use the cat or more command to display the tokens.clar file’s code. Clarity is designed for static analysis; it is not a compiled language and is not Turing complete. It language is a LISP-like language. LISP is an acronym for list processing.

The first line of the tokens.clar program contains a user-defined get-balance function.
 
 
 
(define (get-balance (account principal))
(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.

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.

Along with the principal types, Clarity supports booleans, integers, and fixed length buffers. Variables are created via let binding but there is no support for mutating functions like set.

The next sequence of lines shows an if statement that allows you to set conditions for execution in the language..
 
 
(define (token-credit! (account principal) (tokens int))
(if (<= tokens 0)
(err "must move positive balance")
(let ((current-amount (get-balance account)))
(begin
(set-entry! tokens (tuple (account account))
(tuple (balance (+ tokens current-amount))))
(ok tokens)))))


 
Every smart contract has both a data space and code. The data space of a contract may only interact with that contract. This particular function is interacting with a map named tokens. The set-entry! function is a native function that sets the value associated with the input key to the inputted value in the tokens data map. Because set-entry! mutates data so it has an ! exclamation point; this is by convention in Clarity.

In the first token-transfer public function, you see that it calls the private get-balance function and passes it tx-sender. The tx-sender isa a globally defined variable that represents the the current principal.
 
(define-public (token-transfer (to principal) (amount int))
(let ((balance (get-balance tx-sender)))
(if (or (> amount balance) (<= amount 0))
(err "must transfer positive balance and possess funds")
(begin
(set-entry! tokens (tuple (account tx-sender))
(tuple (balance (- balance amount))))
(token-credit! to amount)))))

(define-public (mint! (amount int))
(let ((balance (get-balance tx-sender)))
(token-credit! tx-sender amount)))

(token-credit! 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 10000)
(token-credit! 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G 300)


 
The final two lines of the program pass a principal, represented by a Stacks address, and an amount to the private user-defined token-credit function.

Smart contracts may call other smart contracts using a contract-call! function. This means that if a transaction invokes a function in a given smart contract, that function is able to make calls into other smart contracts on your behalf. The ability to read and do a static analysis of Clarity code allows clients to learn which functions a given smart contract will ever call. Good clients should always warn users about any potential side effects of a given transaction.

Take a moment to cat the contents of the names.clar file.
 
cat names.clar


 
Which tokens.clar function is being called?
 
Task 3: Initialize data-space and launch contracts
 
1. In this task, you interact with the the contracts using the clarity-cli command line.

Initialize a new db database in the /data/ directory
 
 #  clarity-cli initialize /data/db
Database created

You should see a message saying Database created. The command creates an SQLlite database. The database is available in the container and also in your workstation. In this tutorial, your workstation mount should at this point contain the $HOME/blockstack-dev-data/db directory.
 
2. Type check the names.clar contract.
 
 
 #  clarity-cli check sample-programs/names.clar /data/db

You should get an error:
Type check error. NoSuchContract("tokens")
This happens because the names.clar contract calls the tokens.clar contract, and that contract has not been created on the blockchain.

3.  Type check the tokens.clar contract, it should pass a check as it does not use the contract-call function:
 
 # clarity-cli check sample-programs/tokens.clar /data/db
Checks passed.
When the check command executes successfully and exits with the stand UNIX 0 exit code.
 
4. Launch the tokens.clar contract.
 
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.
 
 # clarity-cli launch tokens sample-programs/tokens.clar /data/db
Contract initialized!

Once launched, you can execute the contract or a public method on the contract. Your development database has an instantiated tokens contract. If you were to close the container and restart it later with the same mount point and you wouldn’t need to relaunch that database; it persists until you remove it from your local drive.

5. Recheck the names.clar contract.
 # clarity-cli check sample-programs/names.clar /data/db

The program should pass validation because its dependency on tokens.clar is fulfilled.

6. Instantiate the names.clar contract as well.
 
# clarity-cli launch names sample-programs/names.clar /data/db
Task 4. Examine the SQLite database

The test environment uses a SQLite database to represent the blockchain. You initialized this database when you ran this earlier:
 
clarity-cli 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:
 
clarity-cli 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:

 
 
 
While not required, you can install SQLite in your local environment and use it to examine the data associated with and impacted by your contract. For example, this what the maps_table contains after you initialize the tokens contract.
 
sqlite> select * from maps_table;
1|tokens|tokens|{"Atom":{"TupleType":{"type_map":{"account":{"Atom":"PrincipalType"}}}}}|{"Atom":{"TupleType":{"type_map":{"balance":{"Atom":"IntType"}}}}}
sqlite>

Task 5: Execute a public function
 
In this section, you use the public mint! function in the tokens contract to mint some new tokens.

1. Use the clarity_cli command to create a demo address.

# clarity-cli generate_address SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG

2. Add the address to your environment.

# DEMO_ADDRESS=SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG

3. Get the current balance of your new address.

# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db Program executed successfully! Output: 0

This command uses the private get-balance function in the tokens contract and pipes the result to the eval subcommand. The eval subcommand lets you evaluate both public and private functions of a contract in read-only mode.

4. Try minting some tokens and sending them to an address we’ll use for our demo.

# clarity-cli 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.

# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db Program executed successfully! Output: 100000
 
 
Task 6: Spend tokens by registering a name
 
Now, let’s register a name using the names.clar contract. Names are just integers in this sample contract, so you’ll register the name 10.

Compute the hash of the name we want to register.

You’ll salt the hash with the salt 8888:
 
 # echo "(hash160 (xor 10 8888))" | clarity-cli eval names /data/db
Program executed successfully! Output:
0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde

The value of the name hash is:
 
 0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde
2. Preorder the name using the execute command:
# clarity-cli execute /data/db names preorder $DEMO_ADDRESS 0xb572fb1ce2e9665f1efd0994fe077b50c3a48fde 1000
Transaction executed and committed. Returned: 0
This executes the public preorder function defined in the names.clar contract. The function reserves a name by paying the name fee (in this case, 1000 tokens).

3. Check the demo address’ new balance:
# echo "(get-balance '$DEMO_ADDRESS)" | clarity-cli eval tokens /data/db
Program executed successfully! Output:
99000

4. Register the name by executing the register function:
 
# 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

5. Lookup the “owner address” for the name:
 

# echo "(get owner (fetch-entry name-map (tuple (name 10))))" | clarity-cli eval names /data/db Program executed successfully! Output: (some 'SP26CHZZ26Q25WDD1CFJYSED169PS9HTNX445XKDG)