Exploring the $NDAU blockchain

Learn how to directly query the ndau blockchain using Python scripts and API endpoints.

NDAU
4 min readSep 21, 2020

In addition to being the world’s first adaptive digital currency optimized for a long-term store of value with staking income and a goal of buoyancy, one of the great features of ndau is that it has it’s own native high-performance and public blockchain. This means all ndau transactions are transparent and viewable by anyone.

The simplest way to explore the ndau blockchain is through the ndau blockchain explorer website. And there’s a lot more data you can pull from the ndau blockchain by exploring the ndau API itself. But manually poking around API endpoints or writing your own query scripts from scratch can be tricky.

Which is exactly why we’ve written some handy Python scripts to get you started on your own voyage of blockchain exploration!

Ahoy ndau!

Getting and running the scripts

The first thing you’ll want to do is clone the ndau commands repo on GitHub. Just follow the instructions on how to clone the commands repo and install the necessary tooling. All we want to do here is install and be able to run Python scripts located in /commands/bin/, so for now you can skip the instructions below the “ndau Tools” section which describes building ndau tools and running a localnet. That’s a topic for a different article.

Once you’ve cloned the commands repo and installed the necessary tooling, go to the /commands/bin/ directory on your own computer and look for forAllAccounts.py and forAllTransactions.py. These are the two scripts you’ll be using to explore the ndau blockchain.

clone this repo — https://github.com/ndau/commands

Now you’re ready to run these scripts from the command line in the/commands/bin/ directory on your own computer. To learn all the details about what each of these scripts can do, use --help to see all the options (e.g, ./forAllAccounts.py --help).

Here’s a summary and some example queries you can try.

forAllAccounts.py

This Python script reads an ndau blockchain and returns information from the accounts it finds there. By default, it reads all accounts and returns a csv file containing the full details from all of the accounts. However, it also supports the ability to generate JSON output, to select a subset of fields for each account, and to select a subset of accounts according to the values of their fields.

Examples:

1) Count the total number of accounts:

./forAllAccounts.py --network=main --count

2) Count the number of accounts with more than 1000 ndau that are unlocked:

./forAllAccounts.py --network=main --count --constraints "balance>=100000000000" "islocked == false"

3) Print the account IDs and balances of accounts with a balance of less than 10000 napu:

./forAllAccounts.py --network=main --constraints "balance<10000" --fields id balance

4) Count the number of accounts that are locked with the maximum lock bonus of 5%:

./forAllAccounts.py --network=main --count --constraints "islocked==true" "bonus=50000000000"

5) Count the number of accounts that are locked for less than one year:

./forAllAccounts.py --network=main --count --constraints "islocked==true" "notice<1y"

6) Find the largest 50 accounts (aka, a “Rich List”), sort them by size (largest first) and save the addresses and balances in a .csv file:

./forAllAccounts.py --network=main --output richlisttop50.csv --fields id balance --sort /bal --max 50

forAllTransactions.py

This Python script reads an ndau blockchain and returns information from the transactions it finds there. By default, it reads all transactions and returns a csv file containing the full details from all of them. However, it also supports the ability to generate JSON output, to select a subset of fields for each transaction, and to select a subset of transactions according to the values of their fields or their metadata.

Examples:

1) Show the block heights for all Issue and ReleaseFromEndowment transactions:

./forAllTransactions.py --network=main --txtypes RFE Issue --fields blockheight txtype

2) Count the number of transfer transactions between blocks 20,000 and 30,000:

./forAllTransactions.py --network=main --txtypes Transfer --blockrange 20000 30000 --count

3) Show the timestamps, blockheight, and quantity of all transfers between blocks 20,000 and 30,000:

./forAllTransactions.py --network=main --txtypes Transfer --fields blockheight txdata.qty blocktime --blockrange 20000 30000

4) Show the height and type of all price-related transaction:

./forAllTransactions.py --network=main --txtypes .price --fields blockheight txtype

5) Find all RecordEndowmentNAV transactions and save the results in allRecordEndowmentNAV.csv:

./forAllTransactions.py --network=main --txtypes RecordEndowmentNAV --output allRecordEndowmentNAV.csv --fields blockheight txhash timestamp txtype txdata.nav

6) Show the source accounts for all transfer transactions that paid SIB (and their fees):

./forAllTransactions.py --network=main --txtypes Transfer --fields txdata.source fee sib --constraint "sib>0"

Further Exploration

You can learn a lot about how both forAllAccounts.py and forAllTransactions.py work by opening them in a text editor on your computer and checking out all the helpfully commented code.

And remember, it’s easy to take a .csv file and import it into Excel to clean up the data and tweak things visually. Here’s that “Rich List” example (calculated on September 21, 2020):

If you’ve written your own helpful query using these scripts, please feel free to share your examples in the comments below so other ndau enthusiasts can learn and try them out. And be sure to join our ndau Telegram community if you have any questions.

Have fun exploring!
ndau.io

Updated 8.28.2021: More examples

Here’s another example. You could use this to easily calculate the total amount of ndau that is locked. Just sum the balance column in the alllockedaccounts.csvspreadsheet output.

Find all locked accounts, sort them by size (largest first) and save the addresses and balances in a .csv file:

./forAllAccounts.py --network=main --output alllockedaccounts.csv --fields id balance --sort /bal --constraints "islocked==true"

--

--

NDAU

The world’s first adaptive digital currency optimized for a long-term store of value with staking income and buoyancy. Learn more at ndau.io.