Skip to content

Using nanook

Luke Duncalfe edited this page Jul 27, 2021 · 16 revisions

First steps

Log into your node, and install the gem:

gem install nanook

Then fire up the Ruby CLI, like irb or pry, and require the gem:

require 'nanook'

Connect

You'll need to know which host and port the Nano RPC is running on in order to connect.

If you've installed nano on your server using docker, the RPC host will either be "http://[::1]:7076" or "http://127.0.0.1:7076".

By default Nanook will connect to "http://[::1]:7076":

nanook = Nanook.new

If we want to test the connection details are correct:

nanook.rpc.test # => true

If you see an error when you perform this test, provide the specific host. For example, it might be:

nanook = Nanook.new('http://127.0.0.1:7076')

Explore

If your node is still bootstrapping with the network, it might not have a lot of confirmed blocks synchronized yet, in which case it won't know much about blocks or accounts on the network.

Let's check:

node = nanook.node
node.block_count # => {:cemented=>2, :count=>2, :unchecked=>10695575}
node.sync_progress # => 1.869897050947963e-05

We still have a long time to wait.

Let's grab the first synchronizing block (also called an unchecked or unconfirmed block):

block = node.synchronizing_blocks(limit: 1).keys.first # => Nanook::Block(id: "A7F96F5...480E")
block.exists? # => false

It's considered to not exist because it's unconfirmed, but if we say that unchecked is okay:

block.exists?(allow_unchecked: true) # => true

Let's have a look at the nano network:

nanook.network_telemetry # => { ... }

There's a lot of stats about the overall state of the network.

One thing in particular is the genesis_block, the first block of the Nano network. Let's check that out:

genesis_block = nanook.network_telemetry[:genesis_block] # => Nanook::Block(id: "991CF19...8948")
genesis_block.exists? # => true 
genesis_block.info # => { ... }

Create a wallet and account

Let's create a new wallet and a new account for that wallet:

Your node will need to have the enable_control setting enabled. If you don't, these calls will raise Nanook::NodeRpcConfigurationError exceptions.

If you don't want to enable the enable_control setting, you can still use any methods in Nanook::Account to query accounts in the ledger. Special methods for accounts within your wallets are in Nanook::WalletAccount.

Wallets exist only on your node, and nowhere else. The seed for the wallet is saved on your node, but is not available to the RPC for security reasons, so you can't get the seed from Nanook. The ids you see in Nanook can only be used on your node. Read Wallet seeds vs ids to see how to retrieve your wallet seeds from your node.

Important: If you plan to use the account for payments, also know that your node is a security liability. Unless you are confident with running a server securely, then please only run your node with enable_control enabled in order to do tests of amounts of nano that you are happy to lose if an attacker gained access to your node, and therefore its wallet seeds and accounts. Consider playing around with amounts of nano that are 0.00001 or less (it's feeless, so small amounts are fine to play with!). Also, consider retrieving your wallet seeds, otherwise, if you lose access to your node (or delete its data) you will lose access to your accounts.

wallet = nanook.wallet.create # => Nanook::Wallet(id: "17AC102...B3AD")
account = wallet.account.create # => Nanook::WalletAccount(id: "3mwtqby...n9z3")

wallet.accounts # => [Nanook::WalletAccount(id: "3mwtqby...n9z3")]

wallet.exists? # => true
account.exists? # => false

Our account doesn't exist because it hasn't been opened yet. To open an account it has to receive its first nano payment.

Send a small (<0.00001 nano is all that's needed or less!) amount to the account. Consider finding a nano faucet to send a small amount of nano.

Call #id on the account to see its full address. Use that address to send some nano to it.

account.id # => This is your account's full address

When you've sent some nano to the account, let's receive it to open your account!

account.receive # => Nanook::Block

Now let's check its balance:

account.balance # => { .. }
account.exists? # => true
account.block_count # => 1
account.history # [{ ... }]

open_block = account.blocks(sort: :desc).first # => Nanook::Block
open_block.type # => "open"
open_block == account.open_block # => true

Have fun and check out the rest of the wiki and read the docs!