#bitcoin #cash #address #base58 #cashaddr

bitcoincash-addr

A simple library providing the encoding/decoding of Bitcoin Cash addresses

9 releases (4 breaking)

✓ Uses Rust 2018 edition

0.5.2 Apr 25, 2020
0.5.1 Dec 27, 2019
0.4.0 Dec 6, 2019
0.3.0 Nov 20, 2019
0.1.1 Aug 11, 2019

#66 in Cryptocurrencies

Download history 33/week @ 2020-03-05 15/week @ 2020-03-12 26/week @ 2020-03-19 18/week @ 2020-03-26 2/week @ 2020-04-02 33/week @ 2020-04-09 195/week @ 2020-04-16 49/week @ 2020-04-23 51/week @ 2020-04-30 105/week @ 2020-05-07 35/week @ 2020-05-14 36/week @ 2020-05-21 56/week @ 2020-05-28 120/week @ 2020-06-04 20/week @ 2020-06-11 118/week @ 2020-06-18

150 downloads per month

MIT license

32KB
636 lines

Rust Bitcoin Cash Address Library

Build Status License Cargo Documentation

A simple library providing an Address struct enabling encoding/decoding of Bitcoin Cash addresses.

Examples

Convert Base58 to CashAddr

use bitcoincash_addr::{Address, Network, Scheme};

fn main() {
    // Decode base58 address
    let legacy_addr = "1NM2HFXin4cEQRBLjkNZAS98qLX9JKzjKn";
    let mut addr = Address::decode(legacy_addr).unwrap();

    // Change the base58 address to a test network cashaddr
    addr.network = Network::Test;
    addr.scheme = Scheme::CashAddr;

    // Encode cashaddr
    let cashaddr_str = addr.encode().unwrap();

    // bchtest:qr4zgpuznfg923ntyauyeh5v7333v72xhum2dsdgfh
    println!("{}", cashaddr_str);
}

Encode from raw address

use bitcoincash_addr::Address;

fn main() {
    // Raw hash160 bytes
    let raw_address = [
        227, 97, 202, 154, 127, 153, 16, 124, 23, 166, 34, 224, 71, 227, 116, 93, 62, 25, 207, 128,
        78, 214, 60, 92, 64, 198, 186, 118, 54, 150, 185, 130, 65, 34, 61, 140, 230, 42, 212, 141,
        134, 63, 76, 177, 140, 147, 14, 76,
    ];

    // Construct address struct (defaults to pubkey hash, cashaddr and main network)
    let address = Address {
        body: raw_address.to_vec(),
        ..Default::default()
    };

    // Encode address
    let address_str = address.encode().unwrap();

    // bitcoincash:qh3krj5607v3qlqh5c3wq3lrw3wnuxw0sp8dv0zugrrt5a3kj6ucysfz8kxwv2k53krr7n933jfsunqex2w82sl
    println!("{}", address_str);
}

Dependencies

~165KB