0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

Bitcoin CashのLegacy Address1B9UNtBfkkpgt8kVbwLN9ktE62QKnMbDzR

Cash Addressbitcoincash:qph5kuz78czq00e3t85ugpgd7xmer5kr7c5f6jdpwk
に変換したいというようなことがあったりします。

変換用ライブラリはたくさんあるようですが、bchaddrjsを使ってみたら
使いやすかったので、ご紹介します。

実装

bchAddressConverter.js
import bchaddr from 'bchaddrjs';

var address = process.argv[2];

var isCashAddress = bchaddr.isCashAddress;
var isLegacyAddress = bchaddr.isLegacyAddress;
var toLegacyAddress = bchaddr.toLegacyAddress;
var toCashAddress  = bchaddr.toCashAddress;

if (isCashAddress(address)) {
  var legacy_address = toLegacyAddress(address);
  console.log(legacy_address);
} else if (isLegacyAddress(address)) {
  var cash_address = toCashAddress(address);
  console.log(cash_address);
}

↓にソースコードを置いています。

node bchAddressConverter.js bitcoincash:qph5kuz78czq00e3t85ugpgd7xmer5kr7c5f6jdpwk
1B9UNtBfkkpgt8kVbwLN9ktE62QKnMbDzR

Cash AddressをLegacy Addressに変換できました。

node bchAddressConverter.js qph5kuz78czq00e3t85ugpgd7xmer5kr7c5f6jdpwk    
1B9UNtBfkkpgt8kVbwLN9ktE62QKnMbDzR

Cash Addressの「bitcoincash:」がなくてもLegacy Addressに変換できます。

node bchAddressConverter.js 1B9UNtBfkkpgt8kVbwLN9ktE62QKnMbDzR 
bitcoincash:qph5kuz78czq00e3t85ugpgd7xmer5kr7c5f6jdpwk

逆にLegacy AddressをCash Addressにできました。

簡単なのでお試しあれ。

↓もっと色々やってみたい方は「bchaddrjs」のREADMEを読んでみましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?