Developer Resources List

From NEM Wiki
Jump to: navigation, search

How do I develop for the NEM Blockchain?

So you have an idea for the NEM blockchain, but you don’t know where to get started. Luckily for you, this article aims to be a one-stop shop for everything you need to get started with the NEM Blockchain, so read on to learn more!

Application Flow

Your app should be able to have a list of a couple of infrastructure servers (NIS) and ping them to see which one gives the best ping. It’s not good to rely on one NIS, as a rogue NIS could give you bad data. For things that are important, double check your data with multiple NIS.

Unlike traditional app development, you should worry about connecting to multiple NIS to balance load, and to reduce the amount of trust required. Because of how the blockchain works, data you store and messages you send will be available from any NIS.

What can I do on the blockchain anyway?

The Blockchain gives you a couple building *blocks* (heh) to use when writing your application. I'll give you a quick overview of all of them, and then show you how to interact with NIS.

Signing and Verifying Messages

Do you need to send a message to another person? This is extremely easy with the NEM blockchain. Private and public keys work in a really nice way that allows you to do this with almost any blockchain platform, but NEM allows you to send your messages through the blockchain.

When a message is signed with someone's public key (publicly available, this is safe to give out to other users), it can only be decrypted by the corresponding private key. If a message is encrypted with your private key, it can only be decrypted with the corresponding public key. This means that if your application needs to implement secure messaging, it's a snap!

Sending Money

The original use for blockchain technology was Bitcoin, a platform for sending money. This too, can be done with NEM, using the built in currency: XEM.

Authentication

You could create an app that signs a message with the name of the app and a randomly generated string for logins. This would allow users to authenticate trustlessly, allowing you to not worry about password security or accounts at all, and let the blockchain handle it.

More

This is by no means an exhaustive list, and you will probably be able to find other uses. If you do, go for it!

How do I interact with NIS?

The great part about how NEM works is that you can use traditional programming concepts to access the blockchain. With just a REST API, you can read and write to the blockchain without needing to store the whole chain yourself.

The full REST API documentation is availible [here](http://bob.nem.ninja/docs/).

You can use whatever networking library you’re familiar with for your language/platform. If you have no preference, [Unirest](http://unirest.io/) works pretty well with NIS. Unirest can be used in the following languages.

- Node.js - Ruby - PHP - Java - Python - Objective-C - .NET - UWP (Windows 8+)

Example API Calls

Generating a New Account

Want to generate a new XEM account? Just send this. ``` GET /account/generate ``` You get back a brand new XEM account, ready for you to use. ```

   {
       "privateKey": "0962c6505d02123c40e858ff8ef21e2b7b5466be12c4770e3bf557aae828390f",
       "address": "NCKMNCU3STBWBR7E3XD2LR7WSIXF5IVJIDBHBZQT",
       "publicKey": "c2e19751291d01140e62ece9ee3923120766c6302e1099b04014fe1009bc89d3"
   }

``` (Although probably not secure if you don't own the NIS, this is here for ease of using a local NIS.)

Check if the NIS is synced to the latest block

Want to make sure the NIS is up to date? ``` GET /chain/height ``` You get back the height. ```

   {
       "height": 42799
   }

```

Sending a Transaction

Sign the transaction using an Ed25519 library, then just make this request. ``` POST /transaction/announce ``` You get back a confirmation you can then check with another NIS (if you want). ```

   {
       "type":1,
       "code":1,
       "message":"SUCCESS",
       "transactionHash": {
       "data":"c1786437336da077cd572a27710c40c378610e8d33880bcb7bdb0a42e3d35586"
       },
       "innerTransactionHash": {
       "data":"cc317a7674d56352b4c711096a7594bd11908bf518293a191fc2faa12eac0fbb"
       }
   }

```

Get Node Info

If you want to tell the user more about the node they’re connecting to, just ask the node! ``` GET /node/info ``` You get back a nice JSON Object with all the information! ``` {

       "metaData":
       {
       "application": "NIS",
       "version": "0.4.33-BETA",
       "platform": "Oracle Corporation (1.8.0_25) on Windows 8"
       },
       "endpoint":
       {
       "protocol": "http",
       "port": 7890,
       "host": "81.224.224.156"
       },
       "identity":
       {
       "name": "Alice",
       "public-key": "a1aaca6c17a24252e674d155713cdf55996ad00175be4af02a20c67b59f9fe8a"
       }
   }

```

Conclusion

The NEM Blockchain is super simple to write apps on. You can use your existing skills as an application developer (REST APIs) - and not have to learn too much about how the blockchain works, or cryptography. This makes it ideal for applications that need 100% uptime, and other trustless features, but these principles can be used in any application.

Happy developing!