bitcore-lib-zcash/docs/api/index.md

52 lines
1.1 KiB
Markdown
Raw Normal View History

2014-12-23 07:28:31 -08:00
title: Bitcore Examples
description: Sample code for the most common task in any bitcoin application.
---
2014-12-12 11:26:33 -08:00
# Examples
2014-12-19 14:23:48 -08:00
## Create a Private Key
2014-12-12 11:26:33 -08:00
```
var privKey = new bitcore.PrivateKey();
```
## Create an Address
```
var privKey = new bitcore.PrivateKey();
var address = privKey.toAddress();
```
## Create a Multisig Address
```
2014-12-17 12:43:58 -08:00
// Build a 2-of-3 address from public keys
var P2SHAddress = new bitcore.Address([publicKey1, publicKey2, publicKey3], 2);
2014-12-12 11:26:33 -08:00
```
## Request a Payment
```
var paymentInfo = {
address: '1DNtTk4PUCGAdiNETAzQFWZiy2fCHtGnPx',
amount: 120000 //satoshis
};
var uri = new bitcore.URI(paymentInfo).toString();
```
2014-12-19 14:23:48 -08:00
## Create a Transaction
2014-12-12 11:26:33 -08:00
```
2014-12-17 12:43:58 -08:00
var transaction = new Transaction()
.from(utxos) // Feed information about what unspend outputs one can use
.to(address, amount) // Add an output with the given amount of satoshis
.change(address) // Sets up a change address where the rest of the funds will go
.sign(privkeySet) // Signs all the inputs it can
2014-12-12 11:26:33 -08:00
```
2014-12-19 14:23:48 -08:00
## Connect to the Network
2014-12-12 11:26:33 -08:00
```
var peer = new Peer('5.9.85.34');
peer.on('inv', function(message) {
// new invetory
});
peer.connect();
```