Java converter from legacy address to new bitcoincash format and vice versa
Simple address converter from legacy to new bitcoincash format and vice versa. It is fully covered by unit tests.
The class AddressConverter
is the entrypoint to the bitcoin-cash-converter API, use it to convert addresses.
You can convert legacy address from a String
to new bitcoincash format:
String bitcoincash_address = AddressConverter.toCashAddress(legacy_address);
You can convert bitcoincash address from a String
with format “bitcoincash:${your_address}” to legacy fomat:
String legacy_address = AddressConverter.toLegacyAddress(bitcoincash_address);
String legacy_address = "18uzj5qpkmg88uF3R4jKTQRVV3NiQ5SBPf";
String bitcoincash_address = AddressConverter.toCashAddress(legacy_address);
System.out.println(bitcoincash_address); // output: bitcoincash:qptvav58e40tcrcwuvufr94u7enkjk6s2qlxy5uf9j
String cash_address = "bitcoincash:qptvav58e40tcrcwuvufr94u7enkjk6s2qlxy5uf9j";
String legacy_address = AddressConverter.toLegacyAddress(cash_address);
System.out.println(legacy_address); // output: 18uzj5qpkmg88uF3R4jKTQRVV3NiQ5SBPf
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.sealedtx</groupId>
<artifactId>bitcoin-cash-converter</artifactId>
<version>1.0</version>
</dependency>
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.sealedtx:bitcoin-cash-converter:1.0'
}