Nxt news – December 2016 (III): The future belongs to those who believe in the beauty of their dreams

Newsletter-topDecember 2016 (III)

 

Here’s some of the latest news about Nxt over this past week in December.

NXT COMMUNITY
DEVELOPMENT
NXT IN THE MEDIA
PRICE EVOLUTION

 

Below, are more details about these news pieces:

 

NXT COMMUNITY

  • BetterBets.io – New Use Cases for Nxt

BetterBets.io, a platform launched some time ago by some of the members of Janus, is one of the most popular casinos with the highest volume among provably fair and secure bitcoin gambling sites.

Recently, it has been announced that BetterBets will help promote new use cases for Nxt. Representatives of Janus have choosen the original Nxt thread at Bitcointalk to remind us that the current Nxt 1.0 still has a long way ahead of it and has the potential to explode and that they intend to promote its expansion.

Remember, remember the 15th of December…. we are proud to soon add more use cases to NXT and provably fair betting will be one of them. All people are welcome, especially the Nxt/Ardor community as our team prepares for an awesome 2017 with you all!

bjorn_bb has also published a look into what will be an exclusive NXT game for this platform:

More information:  https://bitcointalk.org/index.php?topic=303898.msg17191730#msg17191730

https://nxtchat.slack.com/archives/janusproject (Link to join Nxtchat on Slack)

Under The Knife #Janus

(Back to the Index)

 

  • CoinTelegraph – Blockshow Europe

CoinTelegraph will host Blockshow Europe on the 6th of April, 2017, at Munich, which will be an international event of great importance in the blockchain field where developers, investors, companies, and great figures will present their initiatives and proposals for this technology.

A few days days ago, Dave Pearce of the Nxt Foundation brought this piece of news to the forum and confirmed that the Nxt Foundation is going to be there:

The Nxt Foundation is very proud to announce that the Nxt and Ardor community will be represented at the CoinTelegraph BlockShow Europe. We’ve got a booth/table in the main exhibition space, and will be organizing an Nxt/Ardor presence at the show.

We’d like to get as many Nxters as possible to Munich for this show, so reserve your ticket now, via Eventbrite, using our referral code NXTMUNICH :

Look forward to seeing you guys there, I’ll post more information as we get it.

Source and more information: https://www.eventbrite.com/e/blockshow-europe-2017

nxtforum.org/nxt-promotion/coin-telegraph-blockshow-europe-april-6-2017-munich

(Back to the Index)

 

DEVELOPMENT

  • Websioux – PHP Libraries for Nxt

User websioux has published the PHP libraries he created to use Nxt on the software he develops at Github. This PHP library easily lets you call the NXT API in your PHP projects AND a command line tool to facilitate node management and some blockchain queries.

I use it in my projects, I extend the CNxtApi class which contains the basics to query the NXT API to devellop more specific function. I cleaned it such it is always a good base to start with.

Making a request to your node in PHP then goes like this:

$oApp = new CNxt;
$oApp->aInput = array(
                'requestType'=>'sendMoney',
                'recipient'=>'NXT-SL44-R65Z-HMNZ-7WVJM',
                'amountNQT'=>'500000000000',
                'secretPhrase'=>'PUT_YOUR_HOT_WALLET_SECRET',
                'message'=>'Here is your payment',
                'messageIsPrunable'=>true,
                'messageToEncrypt'=>true,
                'feeNQT'=>100000000             
);
$oResp = $oApp->getResponse();

Just like websioux, many other developers who use Nxt also agreed to share their developments and tools with the community, so that all nxters can take advantage of it. Lurker10 keeps an updated listing with libraries, snippets of code, examples… from developers such as jonesnxt, ifinta, doctorevil, NxtSwe, ScripterRon, scor2k, Tosch110, among others.

Source and more information: nxtforum.org/nxt-projects/nxt-php-client-library

nxtwiki.org/wiki/The_Nxt_API

(Back to the Index)

 

NXT IN THE MEDIA

  • Bankingtech – Blockchain: a Real Opportunity for Retail Financial Services

In this article, Bas Wisselink of the Nxt Foundation explains how corporations are slowly but surely realizing the benefits that blockchain technology can bring to their business and how this technology can bringing more potential users to them, especially the young ones, who are used to carry out payments and some other operations using their mobile phone.

Nevertheless, according to Bas, blockchain technology won’t completely displace the current banking system because of the regulations, but it will add great new possibilities and replace some of the creaking infrastructure. Blockchain technology will bring new services to retail users in a very rational, comfortable, and transparent way, thus providing services equally to people living outside major urban areas by offering easy payments, cash management, data storage, money transfer, loyalty schemes, and a many other possibilities.

Source: http://www.bankingtech.com/606502/blockchain-a-real-opportunity-for-retail-financial-services

(Back to the Index)

 

  • Fintech Finance – Adel: Fuelling Innovation in a Fundraising Ecosystem

The current futures and security of Nxt, together with the new possibilities that Ardor will offer, are the perfect math for new startups, such as Adel. Fintech Finance has echoed Adel’s future ICO and explains in this article, with the help of Gabriel Dusil and Jan Lamser, two of the founders of Adel, about the mission and values of this platform.

Dusil explains:

It’s astonishing what people can achieve when they believe in something.In January 2016 my friend, Michal Vavrek had an idea to create a community-based ecosystem to fuel project innovation. So he flew to Amsterdam to meet with the Nxt Foundation, and they agreed to support the project. A few weeks later Miša approached me to co-found the company with him, and we began working on what would become Adel. Over the next three months we’ll introduce Adel to the world, with white papers, projects, infographics, and other materials. Our activities in the next few months will lead us to our Internet Coin Offering (ICO) on the 1st of March 2017.

Source and more information:  http://www.fintech.finance/01-news/fuelling-innovation-in-a-fundraising-ecosystem

https://dusil.com/2016/12/06/adel-creating-opportunities-for-blockchain-innovation

https://www.adelphoi.io

(Back to the Index)

 

PRICE EVOLUTION

  • Weekly NXT/ARDR Price Evolution

The following graphic shows the NXT / Bitcoin exchange price at Poloniex for this past week:

The following graphic shows the ARDR / Bitcoin exchange price at Poloniex for this past week:

(Back to the Index)

Lottery on the Nxt Blockchain in Golang

In my first article I introduced blockchain theory, what it can do for your software project and the basics of interacting with the Nxt blockchain in PHP.

Today I am going to present a small Lottery program written in Go.

Pre-requisites:
Golang (tested with Go 1.6.2)
NRS 1.10.1 (https://bitbucket.org/JeanLucPicard/nxt/downloads/)

The program is fully functional and runs a lottery every Sunday [1].
It was originally written in PHP, both sources are available for download from the Nxt Data Cloud [2].

Application logic

Data feed for this app is ‘tickets’ submitted by users in attachments.

A lottery player sends 10 NXT to the lottery account and attaches a public unencrypted message with a string of 5 numbers, ranging from 0 to 30 separated by commas. The attachment must be unencrypted for rewards to be publicly auditable using the blockchain.

The app makes a request to the NXT server to fetch all transactions from the lottery account, sorts through them, selects only valid transactions and creates a slice of maps (multidimensional array in PHP) of players’ accounts and their strings of numbers. It also calculates the total sum of NXT payable to the players from the sums of all valid tickets.

Upon receiving all the valid data the app runs three rounds of the lottery. Each round receives a portion of the total payable sum, split between concurrent winners. In the round of 5, the app finds user(s) who have correctly guessed 5 numbers, and sends out rewards. In the round of 4, the app does the same for users who have guessed 4 numbers, the slice of participating tickets is now short of winner(s) of round of 5. Rinse and repeat for the round of 3.

This is the gist of it.

A little bit on internals

For each of the three rounds the lottery generates sequences of 5 numbers and compares them to the strings of numbers in tickets until one or more winners are found. It can be said that the lottery “forces” the winning sequence onto ticket(s).

With a limited number of users this seems to be the only sensible way of running a lottery and not having to collect and keep a large jackpot for months and years.

Let’s take a look at the function that generates sequences of 5 numbers and returns an array of them to caller function. On average, this function is called hundreds of thousands of times to find the sequence of 5 matching one of the tickets, when we have a very limited number of participants. It takes fractions of a second. In PHP it takes a tiny bit longer (a second or two), although PHP 7 performance is really good.

func genFive(seed string) [5]int {
   var r [5]int
   seedInt, _ := strconv.Atoi(seed)
   d := false
   for a := offset; a < offset+5; a++ { 
      rand.Seed(int64(seedInt + offset)) 
      var dup [31]int 
      d = false 
      r[0] = rand.Intn(31) 
      r[1] = rand.Intn(31) 
      r[2] = rand.Intn(31) 
      r[3] = rand.Intn(31) 
      r[4] = rand.Intn(31) 
      for _, v := range r { 
         dup[v]++ 
      } 
      for k, _ := range dup { 
         if dup[k] > 1 {
            d = true
         }
      }
      offset = offset + 5
      if d == false {
         return r
      }
   }
   return r
}

An important characteristic of a blockchain lottery app is: it must be completely trust-free.
Everybody must be able to validate that results of the lottery haven’t been gamed. A logical and simple solution to this is to generate sequences of numbers with a deterministic seed.

The problem with deterministic seeds: if they are known in advance, sequences of numbers can be predicted and the lottery can be gamed. To address this problem we turn to the Nxt blockchain again, to find a source of seed with a getSeed() function.

func getSeed() (string, string) {
 type BlockchainStatus struct {
    NumberOfBlocks int `json:"numberOfBlocks"`
 }
 var status BlockchainStatus
 if seedBlockOutput, b := 
sendQuery("requestType=getBlockchainStatus", 
true); 
b != false { if err := 
json.Unmarshal([]byte(seedBlockOutput), &status); 
err != nil {
     fmt.Println(err)
   }
  }
 seedBlockHeight := 
strconv.Itoa(status.NumberOfBlocks - 11)

 type BlockId struct {
  Block string `json:"block"`
 }
 var block BlockId
 if seedBlockId, b := 
sendQuery("requestType=getBlockId&height="
+seedBlockHeight, true); b != false {
if err := json.Unmarshal([]byte(seedBlockId), 
&block); err != nil {
         fmt.Println(err)
    }
  }
 seed := block.Block[len(block.Block)-5:]
 return seed, seedBlockHeight
}

The app runs at 18:00 UTC on Sunday.

The first thing it does in the getSeed() function is to fetch the block id of the block which was generated 10 blocks before the app started (as seen in a local copy of the blockchain on the lottery node) and take the 5 last digits of the block id as a seed. Due to network latency and occasional blockchain reorganizations of 1-3 blocks, the lottery node may not see the same block as other nodes. The number 10 for getting the block for seed was chosen to be reasonably sure that block would not be reorganized.

It can be argued that there is a theoretical possibility that the block id is predictable. The odds of this are tiny in my opinion but I’ll leave it to the readers to debate and decide.

Now that the app has its seed, it can do its job in a way so users don’t need to trust the lottery host.

The Go source code doesn’t include the routine to verify past results.
The PHP source code does have it, it is fully functional and can be used to independently verify all past results with the deterministic seeds from the blockchain.

For Go I use this function to send queries to the Nxt Server and return results.

func sendQuery(Query string, Active bool) 
(output string, b bool) {
   output = ""
   b = false
   if Active == false {
      output = "Function disabled"
      return
   }
   body := strings.NewReader(Query)
   req, err := http.NewRequest("POST", 
"http://127.0.0.1:7876/nxt", body)
   if err != nil {
      output = fmt.Sprintf("%s", err)
      return
   }
   req.Header.Set("Content-Type", 
"application/x-www-form-urlencoded")

   resp, err := http.DefaultClient.Do(req)
   if err != nil {
      output = fmt.Sprintf("%s", err)
      return
   }
   bo, err := ioutil.ReadAll(resp.Body)
   defer resp.Body.Close()
   output = fmt.Sprintf("%s", bo)
   match, _ := 
regexp.MatchString(".*errorDescription.*", 
output)
   if match == true {
      fileHandle, _ := 
os.OpenFile("./error.log", os.O_APPEND, 0666)
      writer := bufio.NewWriter(fileHandle)
      defer fileHandle.Close()
      fmt.Fprintln(writer, output)
      writer.Flush()
      return
   }
   b = true
   return
}

The results are returned as a JSON string and need to be unmarshaled into proper structs.

validPlayers := make([]map[string]string, 0)

lotteryAccount := "NXT-YXC4-RB92-F6MQ-2ZRA6"

type Attachment struct {
   Message       string `json:"message"`
   MessageIsText bool   `json:"messageIsText"`
}

type Transaction struct {
   Timestamp   int        `json:"timestamp"`
   AmountNQT   string     `json:"amountNQT"`
   ID          string     `json:"transaction"`
   SenderRS    string     `json:"senderRS"`
   RecipientRS string     `json:"recipientRS"`
   Attached    Attachment `json:"attachment"`
}

type Response struct {
   Transactions []Transaction 
`json:"transactions"`
}
Query := 
"requestType=getBlockchainTransactions&account=" +
lotteryAccount + 
"&type=0&subtype=0&executedOnly=true"

if v, a := sendQuery(Query, true); a == true {
   var transactions Response
   if err := json.Unmarshal([]byte(v), 
&transactions); err != nil {
      fmt.Println(err)
   }

 p := 0
 for k, _ := range transactions.Transactions {
    // code to check tickets for validity.
    // if transaction satisfies all criteria 
    // add it to the slice of valid tickets.
		
    validPlayers = append(validPlayers, 
make(map[string]string))
    validPlayers[p][txSender] = lotteryNumbers
    p++
			
   }
}

Now that ‘validPlayers’ has all the good tickets we can start the game.

process() receives an integer (5, 4, or 3) and other parameters, including validPlayers and runs three rounds of the lottery. It makes a call to getWinners() function, that one calls genFive() to generate sequences of numbers until at least one winner is found. getWinners() returns results to process() which sends out reward, removes the winner ticket from eligible tickets and returns remaining tickets into main() for subsequent rounds. There is a helper function preparePlayers() which recreates validPlayers without the empty spots freed by the removed tickets.

I encourage every programmer to try coding on the Nxt blockchain. It is very easy with its rich API hooking into all the functionality of the core engine. https://nxtwiki.org/wiki/The_Nxt_API

My next app will probably be a poll app, with immutable records of votes saved into the blockchain. Do you think an app like that can find usage in the modern world? By the way, Nxt has its own built-in Voting. It’s too easy to forget what Nxt has, because it has so many features and all those features are accessible through API, kindly programmed by the core developers for userland. You can ‘mine’ your first NXT coins to send transactions in the Lucky node project running a public node, come to nxtforum.org and you will find out how.

Please leave your comments and suggestions.


1.
Lottery at nxtforum.org.

2.
To access Nxt Data Cloud, download and install the NRS (Nxt Reference Software 1.10.1) and search by ‘lottery’ keyword. Source code can also be downloaded from any of the public Open API Nxt servers, for instance:

Go: http://23.94.134.161:7876/nxt?requestType=downloadTaggedData&transaction=7872865106538381099&retrieve=true

PHP: http://23.94.134.161:7876/nxt?requestType=downloadTaggedData&transaction=13031806327722095646&retrieve=true
BACK TO POST.