Commit 813813a7 authored by Zhenzhen Zhan's avatar Zhenzhen Zhan
Browse files

Address conversion

parent c2de5cdb
......@@ -2,7 +2,7 @@
Represents a bitcoin address. Addresses are the most popular way to make bitcoin transactions. See [the official Bitcoin Wiki](https://en.bitcoin.it/wiki/Address) for technical background information.
## Instantiate an Address
To be able to receive bitcoins an address is needed, but in order to spend them a private key is necessary. Please take a look at the [`PrivateKey`](privatekey.md) docs for more information about exporting and saving a key.
To be able to receive bitcoins an address is needed, but in order to spend them a private key is necessary. Please take a look at the [`PrivateKey`](privatekey.md) docs for more information about exporting and saving a key.
```javascript
var privateKey = new PrivateKey();
......@@ -13,7 +13,7 @@ You can also instantiate an Address from a String, [PublicKey](publickey.md), or
```javascript
// from a string
var address = Address.fromString('mwkXG8NnB2snbqWTcpNiK6qqGHm1LebHDc');
var address = Address.fromString('tCRWVDx5gcuXTn7ThFDQe4qjaD6EGygiRV865');
// a default network address from a public key
var publicKey = PublicKey(privateKey);
......
......@@ -29,14 +29,14 @@ var privateKey = new bitcore.PrivateKey('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs
var utxo = {
"txId" : "115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986",
"outputIndex" : 0,
"address" : "17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV",
"address" : "CRWJVB3eyhMULvHBZyUzKsA6qw8f8ioR1fQt",
"script" : "76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac",
"satoshis" : 50000
};
var transaction = new bitcore.Transaction()
.from(utxo)
.to('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)
.to('CRWTmk5gJNCpTgTWaoLkJHBAQF1fs7ZEw5Ed', 15000)
.sign(privateKey);
```
......@@ -54,7 +54,7 @@ var signature = message.sign(privateKey);
```javascript
var Message = require('bitcore-message');
var address = '13Js7D3q4KvfSqgKN8LpNq57gcahrVc5JZ';
var address = 'CRWEGrRmKHAvcSy32wahvbrEMKzKCNURmJ6S';
var signature = 'IBOvIfsAs/da1e36W8kw1cQOPqPVXCW5zJgNQ5kI8m57FycZXdeFmeyoIqJSREzE4W7vfDmdmPk0HokuJPvgPPE=';
var verified = new Message('This is an example of a signed message.').verify(address, signature);
......@@ -66,7 +66,7 @@ var privateKey = new bitcore.PrivateKey('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs
var utxo = {
"txId" : "115e8f72f39fad874cfab0deed11a80f24f967a84079fb56ddf53ea02e308986",
"outputIndex" : 0,
"address" : "17XBj6iFEsf8kzDMGQk5ghZipxX49VXuaV",
"address" : "CRWJVB3eyhMULvHBZyUzKsA6qw8f8ioR1fQt",
"script" : "76a91447862fe165e6121af80d5dde1ecb478ed170565b88ac",
"satoshis" : 50000
};
......@@ -108,6 +108,6 @@ var utxo = {
var transaction = new bitcore.Transaction()
.from(utxo, publicKeys, 2)
.to('mtoKs9V381UAhUia3d7Vb9GNak8Qvmcsme', 20000)
.to('tCRWSGkghjAUSNVZLTKqSod1cddYjM6HA26Xb', 20000)
.sign(privateKeys);
```
......@@ -75,7 +75,7 @@ var p2shAddress = new bitcore.Address([publicKey1, publicKey2, publicKey3], 2);
```javascript
var paymentInfo = {
address: '1DNtTk4PUCGAdiNETAzQFWZiy2fCHtGnPx',
address: 'CRWQLsnJKqanwx9uirfkaBiuqwGjGs1g63Az',
amount: 120000 //satoshis
};
var uri = new bitcore.URI(paymentInfo).toString();
......
......@@ -40,14 +40,14 @@ Example:
> compressedPK.compressed;
true
> compressedPK.toAddress().toString();
'1KbUJ4x8epz6QqxkmZbTc4f79JbWWz6g37'
'CRWWZTcdDamRfsw3KNz9BF5TwKT1DBDVsX8j'
// compressed public key starting with 0x02 (smaller than midpoint of curve)
> var compressedPK2 = new bitcore.PublicKey('02a1633cafcc01ebfb6d78e39f687a1f'+
'0995c62fc95f51ead10a02ee0be551b5dc');
> compressedPK2.compressed;
true
> compressedPK.toAddress().toString();
'1KbUJ4x8epz6QqxkmZbTc4f79JbWWz6g37'
'CRWWZTcdDamRfsw3KNz9BF5TwKT1DBDVsX8j'
// uncompressed public key, starting with 0x04. Contains both X and Y encoded
> var uncompressed = bitcore.PublicKey('0479BE667EF9DCBBAC55A06295CE870B07029'+
'BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68'+
......@@ -55,5 +55,5 @@ true
> uncompressed.compressed
false
> uncompressed.toAddress().toString()
'1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm'
'CRWRFMtefWRaihSZbaYdiuEdLG2T9NdzpipH'
```
......@@ -15,7 +15,7 @@ This is the most commonly used transaction output script. It's used to pay to a
```javascript
// create a new p2pkh paying to a specific address
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var address = Address.fromString('CRWZYSpVnfL4zN3QmCxP9vqEZvHmX8gbhNJm');
var script = Script.buildPublicKeyHashOut(address);
assert(script.toString() === 'OP_DUP OP_HASH160 20 0xecae7d092947b7ee4998e254aa48900d26d2ce1d OP_EQUALVERIFY OP_CHECKSIG');
```
......
......@@ -18,14 +18,14 @@ The constructor is quite permissive with the input arguments. It can take output
var utxo = new UnspentOutput({
"txid" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9",
"vout" : 0,
"address" : "mgJT8iegL4f9NCgQFeFyfvnSw1Yj4M5Woi",
"address" : "tCRWDmsxGtogVZUE4RA3Tx76Q9htzmQRUJ9Nh",
"scriptPubKey" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
"amount" : 0.00070000
});
var utxo = new UnspentOutput({
"txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9",
"outputIndex" : 0,
"address" : "mgJT8iegL4f9NCgQFeFyfvnSw1Yj4M5Woi",
"address" : "tCRWDmsxGtogVZUE4RA3Tx76Q9htzmQRUJ9Nh",
"script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
"satoshis" : 70000
});
......
......@@ -4,9 +4,9 @@ Represents a bitcoin payment URI. Bitcoin URI strings became the most popular wa
URI Examples:
```
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2
bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2&message=Payment&label=Satoshi&extra=other-param
bitcoin:CRWD7zgXvyi6nDDpmnmpRb8ytJ2u25UupSKC
bitcoin:CRWD7zgXvyi6nDDpmnmpRb8ytJ2u25UupSKC?amount=1.2
bitcoin:CRWD7zgXvyi6nDDpmnmpRb8ytJ2u25UupSKC?amount=1.2&message=Payment&label=Satoshi&extra=other-param
```
## URI Validation
......@@ -15,7 +15,7 @@ The main use that we expect you'll have for the `URI` class in bitcore is valida
The code for validating URIs looks like this:
```javascript
var uriString = 'bitcoin:12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu?amount=1.2';
var uriString = 'bitcoin:CRWD7zgXvyi6nDDpmnmpRb8ytJ2u25UupSKC?amount=1.2';
var valid = URI.isValid(uriString);
var uri = new URI(uriString);
console.log(uri.address.network, uri.amount); // 'livenet', 120000000
......@@ -33,7 +33,7 @@ The code for creating an URI from an Object looks like this:
```javascript
var uriString = new URI({
address: '12A1MyfXbW6RhdRAZEqofac5jCQQjwEPBu',
address: 'CRWD7zgXvyi6nDDpmnmpRb8ytJ2u25UupSKC',
amount : 10000, // in satoshis
message: 'My payment request'
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment