Skip to content

Commit

Permalink
Merge pull request xpring-eng#57 from xpring-eng/update-1-1
Browse files Browse the repository at this point in the history
Update documentation for X-Addresses
  • Loading branch information
keefertaylor authored Nov 13, 2019
2 parents 9d127d9 + 3bca9ce commit c8b1881
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![CircleCI](https://img.shields.io/circleci/build/github/xpring-eng/xpring-js/master?style=flat-square)](https://circleci.com/gh/xpring-eng/xpring-js/tree/master) [![CodeCov](https://img.shields.io/codecov/c/github/xpring-eng/xpring-js?style=flat-square)]((https://codecov.io/gh/xpring-eng/xpring-js))
[![CircleCI](https://img.shields.io/circleci/build/github/xpring-eng/Xpring-JS?style=flat-square)](https://circleci.com/gh/xpring-eng/xpring-js/tree/master)
[![CodeCov](https://img.shields.io/codecov/c/github/xpring-eng/xpring-js?style=flat-square)]((https://codecov.io/gh/xpring-eng/xpring-js))
[![Dependabot Status](https://img.shields.io/static/v1?label=Dependabot&message=enabled&color=success&style=flat-square&logo=dependabot)](https://dependabot.com)

# Xpring-JS

Expand Down Expand Up @@ -35,6 +37,9 @@ grpc.xpring.tech:80
Xpring is working on building a zero-config way for XRP node users to deploy and use the adapter as an open-source component of [rippled](https://github.com/ripple/rippled). Watch this space!

## Usage

*Note*: Xpring SDK only works with X-Addresses. You can learn more about working with X-Addresses in the `Utils` section below and at http://xrpaddress.info.

### Wallets
A wallet is a fundamental model object in XpringKit which provides key management, address derivation, and signing functionality. Wallets can be derived from either a seed or a mnemonic and derivation path. You can also choose to generate a new random HD wallet.

Expand Down Expand Up @@ -133,10 +138,10 @@ const { XpringClient } = require("xpring-js");
const remoteURL = "grpc.xpring.tech:80";
const xpringClient = XpringClient.xpringClientWithEndpoint(remoteURL);

const address = "r3v29rxf54cave7ooQE6eE7G5VFXofKZT7";
const address = "X7u4MQVhU2YxS4P9fWzQjnNuDRUkP3GM6kiVjTjcQgUU3Jr";

const balance = await xpringClient.getBalance(address);
console.log(balance.getDrops()); // Logs a balance in drops of XRP
console.log(balance); // Logs a balance in drops of XRP
```

#### Sending XRP
Expand All @@ -150,16 +155,15 @@ const remoteURL = "grpc.xpring.tech:80";
const xpringClient = XpringClient.xpringClientWithEndpoint(remoteURL);

// Amount of XRP to send
const amount = new XRPAmount();
amount.setDrops("10");
const amount = BigInt("10")

// Destination address.
const destinationAddress = "r3v29rxf54cave7ooQE6eE7G5VFXofKZT7";
const destinationAddress = "X7u4MQVhU2YxS4P9fWzQjnNuDRUkP3GM6kiVjTjcQgUU3Jr";

// Wallet which will send XRP
const senderWallet = Wallet.generateRandomWallet();

const result = await xpringClient.send(amount, destinationAddress, senderWallet);
const transactionHash = await xpringClient.send(amount, destinationAddress, senderWallet);
```

### Utilities
Expand All @@ -170,13 +174,52 @@ The Utils object provides an easy way to validate addresses.
```javascript
const { Utils } = require("xpring-js")

const rippleAddress = "rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G";
const rippleClassicAddress = "rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G"
const rippleXAddress = "X7jjQ4d6bz1qmjwxYUsw6gtxSyjYv5iWPqPEjGqqhn9Woti";
const bitcoinAddress = "1DiqLtKZZviDxccRpowkhVowsbLSNQWBE8";

Utils.isValidAddress(rippleAddress); // returns true
Utils.isValidAddress(rippleClassicAddress); // returns true
Utils.isValidAddress(rippleXAddress); // returns true
Utils.isValidAddress(bitcoinAddress); // returns false
```

You can also validate if an address is an X-Address or a classic address.
```javascript
const { Utils } = require("xpring-js")

const rippleClassicAddress = "rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G"
const rippleXAddress = "X7jjQ4d6bz1qmjwxYUsw6gtxSyjYv5iWPqPEjGqqhn9Woti";
const bitcoinAddress = "1DiqLtKZZviDxccRpowkhVowsbLSNQWBE8";

Utils.isValidXAddress(rippleClassicAddress); // returns false
Utils.isValidXAddress(rippleXAddress); // returns true
Utils.isValidXAddress(bitcoinAddress); // returns false

Utils.isValidClassicAddress(rippleClassicAddress); // returns true
Utils.isValidClassicAddress(rippleXAddress); // returns false
Utils.isValidClassicAddress(bitcoinAddress); // returns false
```

### X-Address Encoding

You can encode and decode X-Addresses with the SDK.

```javascript
const { Utils } = require("xpring-js")

const rippleClassicAddress = "rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G"
const tag = 12345;

// Encode an X-Address.
const xAddress = Utils.encodeXAddress(rippleClassicAddress, tag); // X7jjQ4d6bz1qmjwxYUsw6gtxSyjYv5xRB7JM3ht8XC4P45P

// Decode an X-Address.
const decodedClassicAddress = Utils.decodeXAddress(xAddress);

console.log(decodedClassicAddress.address); // rnysDDrRXxz9z66DmCmfWpq4Z5s4TyUP3G
console.log(decodedClassicAddress.tag); // 12345
```

## Development
To get set up for development on Xpring-JS, use the following steps:

Expand Down

0 comments on commit c8b1881

Please sign in to comment.