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

Bitcoin x Javascript

Bitcoin x Javascript

東京ノード学園#17

Yuki Akiyama

August 31, 2015
Tweet

More Decks by Yuki Akiyama

Other Decks in Technology

Transcript

  1. アドレスを作成してみる(口座の作成) var bitcore = require("bitcore"); var privateKey = new bitcore.PrivateKey();

    var address = privateKey.toAddress(); var wif = privateKey.toWIF(); console.log(address.toString(), wif);
  2. 残高の確認 var explorers = require("bitcore-explorers"); var insight = new explorers.Insight();

    var address = '1NdJsXeKxNv5EtHPVBQ1QfpEgyi5aTvV3B'; insight.getUnspentUtxos(address, function(err, utxos) { if (err) {} else { console.log(utxos.map(function(v){ return { txid : v.txId, vout : v.outputIndex, satoshi : v.satoshis, btc : (v.satoshis * 1e-8).toFixed(8), }})) } });
  3. 送金処理 var bitcore = require("bitcore"); var explorers = require("bitcore-explorers"); var

    insight = new explorers.Insight(); var wif = ''KyJw2R3uzQ7svEDGYMuoNnryTaXojmmoz8ajk9XwzJTdGPaoQkuQ''; var privateKey = bitcore.PrivateKey.fromWIF(wif); var address = privateKey.toAddress(); var send_address = '1xxxx'; var amount = 100000; var fee = 10000; // つづく
  4. 送金処理 insight.getUnspentUtxos(address.toString(), function(err, utxos) { if (err) {} else if(utxos.length>0){

    var transaction = new bitcore.Transaction() .from(utxos) .to(send_address, amount) .fee(fee) .change(address) .sign(privateKey) var rawtx = transaction.serialize().toString('hex'); insight.broadcast(rawtx, function(err, txid){ console.log(txid); }) } });