Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NEMAPIワークショップ

 NEMAPIワークショップ

MasayaYoshino

June 30, 2018
Tweet

More Decks by MasayaYoshino

Other Decks in Programming

Transcript

  1. NEMΞϓϦ։ൃϫʔΫγϣοϓ&΋͘΋͘ձ ͕͢͞ʹਏ͍ͷͰίϐϖͰ͍͍Ͱ͢Αw var nem = require("nem-sdk").default; const networkId = nem.model.network.data.mainnet.id;

    const rBytes = nem.crypto.nacl.randomBytes(32); const privateKey = nem.utils.convert.ua2hex(rBytes); const keyPair = nem.crypto.keyPair.create(privateKey); const address = nem.model.address.toAddress(keyPair.publicKey.toString(), networkId); const publicKey = keyPair.publicKey.toString(); const neminfo = { address: address, privateKey: privateKey, publicKey: publicKey, }; console.log(neminfo); NEMΞϓϦ։ൃϫʔΫγϣοϓ&΋͘΋͘ձ ௥Ճ
  2. QR NEMΞϓϦ։ൃϫʔΫγϣοϓ&΋͘΋͘ձ ௥Ճ ҎԼͷίʔυ΋௥Ճ ௥Ճ console.log(neminfo); $('.myAddress').text(neminfo.address); var qr =

    { "v": 2, "type": 1, "data": { "addr": neminfo.address, "name": "Primary" } }; $('#qrcode').qrcode({width: 200, height: 200, text: JSON.stringify(qr)}); ௥Ճݸॴ
  3. QR NEMΞϓϦ։ൃϫʔΫγϣοϓ&΋͘΋͘ձ ௥Ճ let PRIVATEKEY = ൿີ伴; let VOLUME =

    ૹΔNEMͷྔ; let PASSWORD = ΢ΥϨοτͷύεϫʔυ; let MESSAGE = ϝοηʔδ; let endpoint = nem.model.objects.create('endpoint')('http:// hachi.nem.ninja', nem.model.nodes.defaultPort); let common = nem.model.objects.create('common')(PASSWORD, PRIVATEKEY); let transferTransaction = nem.model.objects.create('transferTransaction') (PRIVATEKEY, VOLUME, MESSAGE); let preparedTransaction = nem.model.transactions.prepare('transferTransaction')(common, transferTransaction, nem.model.network.data.mainnet.id); nem.model.transactions.send(common, preparedTransaction, endpoint).then(function(res){ console.log(res); }, function(err){ console.log(err); }); ίʔυ͚ͩɺΞοϓ͓͖ͯ͠·͢ (ୠ͠ɺຊ൪ϓϩμΫτͰ͸࢖༻͠ͳ͍Ͱ͍ͩ͘͞ɺൿີ伴ͷ҉߸Խ͕ඞཁͰ͢ɻ)