{"id":8004,"date":"2018-08-24T19:17:29","date_gmt":"2018-08-24T19:17:29","guid":{"rendered":"https:\/\/nkn.org\/community\/blog\/nkn-javascript-open-source-wallet\/"},"modified":"2018-08-24T19:17:29","modified_gmt":"2018-08-24T19:17:29","slug":"nkn-javascript-open-source-wallet","status":"publish","type":"post","link":"https:\/\/nkn.org\/de\/community\/blog\/nkn-javascript-open-source-wallet\/","title":{"rendered":"NKN Javascript Open-Source Wallet"},"content":{"rendered":"<figure>\n<p><img decoding=\"async\" data-width=\"6667\" data-height=\"3750\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*2pr-_Hn55yneyfGi_8dOYg.jpeg\"><br \/>\n<\/figure>\n<p>We\u2019re excited to share that NKN just released and made open-source our <strong>Javascript Wallet<\/strong> this week.<\/p>\n<p><em>What is it?<\/em><\/p>\n<p>Essentially, the wallet is a JavaScript SDK that developers can use to get information, such as the balance of an NKN user\u2019s wallet, and make payments\/transfers to other accounts. It can also be used to build web and native applications that involve transactions on NKN blockchain platform.<\/p>\n<p>For developers, below is a simple usage example of the wallet:<\/p>\n<ul>\n<li>import<\/li>\n<\/ul>\n<pre>const nknWallet = require('nkn-wallet');<\/pre>\n<ul>\n<li>create a new wallet<\/li>\n<\/ul>\n<pre>const wallet = nknWallet.newWallet('pwd')<\/pre>\n<ul>\n<li>get wallet\u2019s json string<\/li>\n<\/ul>\n<pre>const walletJson = wallet.toJSON()<\/pre>\n<ul>\n<li>load wallet from a wallet json string<\/li>\n<\/ul>\n<pre>const walletFromJson = nknWallet.loadJsonWallet(walletJson, 'pwd')<\/pre>\n<ul>\n<li>restore wallet from a private key<\/li>\n<\/ul>\n<pre>const walletFromPrivateKey = nknWallet.restoreWalletByPrivateKey('the private key', 'new-wallet-password')<\/pre>\n<ul>\n<li>query asset balance for this wallet<\/li>\n<\/ul>\n<pre>wallet.queryAssetBalance().then(function(value) {<br>  console.log('asset balance for this wallet is: ', value.toString())<br>}).catch(function(error) {<br>  console.log('query balance fail: ', error)<br>})<\/pre>\n<ul>\n<li>transfer asset to some address<\/li>\n<\/ul>\n<pre>wallet.transferTo(wallet.address, 100, 'pwd').then(function(data) {<br>  console.log('success: ', data)<br>}).catch(function(error) {<br>  console.log('fail: ', error)<br>})<\/pre>\n<p>The open source wallet will pave the way for future developments and adoption of NKN public testnet, which will be launched at the end of August, 2018 and experimental mining afterwards.<\/p>\n<p>For more detailed guidelines and examples regarding the NKN wallet, please visit our Github: <a href=\"https:\/\/github.com\/nknorg\/nkn-wallet-js\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/nknorg\/nkn-wallet-js<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re excited to share that NKN just released and made open-source our Javascript Wallet this week. What is it? Essentially, the wallet is a JavaScript SDK that developers can use to get information, such as the balance of an NKN user\u2019s wallet, and make payments\/transfers to other accounts. It can also be used to build [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":3589,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"mc4wp_mailchimp_campaign":[]},"categories":[260,212],"tags":[506,438,571,634],"acf":[],"_links":{"self":[{"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/posts\/8004"}],"collection":[{"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/comments?post=8004"}],"version-history":[{"count":0,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/posts\/8004\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/media\/3589"}],"wp:attachment":[{"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/media?parent=8004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/categories?post=8004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nkn.org\/de\/wp-json\/wp\/v2\/tags?post=8004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}