Browse Source

Added format translate examples.

master
Emilio Almansi 7 years ago
parent
commit
cc99c8f297
  1. 4
      README.md
  2. 28
      docs/examples.md

4
README.md

@ -40,10 +40,12 @@ You can find many useful, up-to-date examples to get you started right away on t
* [Generate a random address](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#generate-a-random-address)
* [Generate a address from a SHA256 hash](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#generate-a-address-from-a-sha256-hash)
* [Translate an address to any Bitcoin Cash address format](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#translate-an-address-to-any-bitcoin-cash-address-format)
* [Read an address from any Bitcoin Cash address format](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#read-an-address-from-any-bitcoin-cash-address-format)
* [Import an address via WIF](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#import-an-address-via-wif)
* [Create a Transaction](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#create-a-transaction)
* [Sign a Bitcoin message](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#sign-a-bitcoin-message)
* [Verify a Bitcoin message](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#verify-a-bitcoin-message)
* [Sign a Bitcoin message](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#sign-a-bitcoin-message)
* [Create an OP RETURN transaction](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#create-an-op-return-transaction)
* [Create a 2-of-3 multisig P2SH address](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#create-a-2-of-3-multisig-p2sh-address)
* [Spend from a 2-of-2 multisig P2SH address](https://github.com/bitcoincashjs/bitcoincashjs/blob/master/docs/examples.md#spend-from-a-2-of-2-multisig-p2sh-address)

28
docs/examples.md

@ -18,6 +18,34 @@ const address = new bitcoinCash.PrivateKey(bn).toAddress();
console.log(address.toString()) // 126tFHmNHNAXDYT1QeEBEwBbEojib1VZyg
```
## Translate an address to any Bitcoin Cash address format
```javascript
const Address = bitcoinCash.Address;
const BitpayFormat = Address.BitpayFormat;
const CashAddrFormat = Address.CashAddrFormat;
const address = new Address('1MF7A5H2nHYYJMieouip2SkZiFZMBKqSZe');
console.log(address.toString()) // 1MF7A5H2nHYYJMieouip2SkZiFZMBKqSZe
console.log(address.toString(BitpayFormat)) // Cchzj7d6fLX5CVd5Vf3jbxNbLNmm4BTYuG
console.log(address.toString(CashAddrFormat)) // bitcoincash:qr0q67nsn66cf3klfufttr0vuswh3w5nt5jqpp20t9
```
## Read an address from any Bitcoin Cash address format
```javascript
const Address = bitcoinCash.Address;
const fromString = Address.fromString;
const BitpayFormat = Address.BitpayFormat;
const CashAddrFormat = Address.CashAddrFormat;
const legacy = fromString('1MF7A5H2nHYYJMieouip2SkZiFZMBKqSZe',
'mainnet', 'pubkeyhash');
const bitpay = fromString('Cchzj7d6fLX5CVd5Vf3jbxNbLNmm4BTYuG',
'mainnet', 'pubkeyhash', BitpayFormat);
const cashaddr = fromString('bitcoincash:qr0q67nsn66cf3klfufttr0vuswh3w5nt5jqpp20t9',
'mainnet', 'pubkeyhash', CashAddrFormat);
```
## Import an address via WIF
```javascript
const wif = 'Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct';

Loading…
Cancel
Save