mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-04-29 15:37:50 +00:00
Use example.com instead of ripple.com Co-authored-by: Elliot Lee <github.public@intelliot.com>
101 lines
3.2 KiB
Plaintext
101 lines
3.2 KiB
Plaintext
# Static Methods
|
|
|
|
You can access static methods directly on the `RippleAPI` class. For example, `RippleAPI.computeBinaryTransactionHash(...)`.
|
|
|
|
A few of the most commonly-used methods are documented below.
|
|
|
|
For a full list, refer to these docs:
|
|
|
|
- [XRP Ledger Hashes](https://github.com/ripple/ripple-lib/blob/develop/src/common/hashes/README.md)
|
|
- [ripple-address-codec API](https://github.com/ripple/ripple-address-codec/blob/master/README.md#api)
|
|
|
|
## computeBinaryTransactionHash
|
|
|
|
`computeBinaryTransactionHash(txBlobHex: string): string`
|
|
|
|
Returns the hash (id) of a binary transaction blob.
|
|
|
|
This is a static method on the `RippleAPI` class.
|
|
|
|
### Parameters
|
|
|
|
This method takes one parameter, a string containing a binary transaction in hex.
|
|
|
|
### Return Value
|
|
|
|
This method returns a string representing the transaction's id (hash).
|
|
|
|
### Example
|
|
|
|
```javascript
|
|
const signed_blob = '120000228000000024000B2E5A201B0066374B61400000003B9ACA0068400000000000000C732102356E89059A75438887F9FEE2056A2890DB82A68353BE9C0C0C8F89C0018B37FC74473045022100B3721EEB1ED6DFF29FB8B209E2DE6B54A0A6E44D52D926342F3D334BE98F08640220367A74107AD5DEAEFA3AB2984C161FC23F30B2704BB5CC984358BA262177A4568114F667B0CA50CC7709A220B0561B85E53A48461FA883142B71D8B09B4EE8DAA68FB936C23E3A974713BDAC'
|
|
if (typeof signed_blob === 'string' && signed_blob.match(/^[A-F0-9]+$/)) {
|
|
const id = RippleAPI.computeBinaryTransactionHash(signed_blob)
|
|
console.log('Transaction hash:', id')
|
|
}
|
|
```
|
|
|
|
```
|
|
Transaction hash: 80C5E11E1A21A626759D6CB944B33DBAAC66BD704A289C86E330B847904F5C13
|
|
```
|
|
|
|
[RunKit Example: computeBinaryTransactionHash](https://runkit.com/intelliot/computebinarytransactionhash-example)
|
|
|
|
## classicAddressToXAddress
|
|
|
|
`classicAddressToXAddress(classicAddress: string, tag: number | false[, test: boolean]): string`
|
|
|
|
Convert a classic address and tag to an X-address.
|
|
|
|
If `test` is `true`, the address starts with `T` to show that the address is intended for use on a test network.
|
|
|
|
### Example: Encode an X-address with tag 4294967295
|
|
|
|
```javascript
|
|
const RippleAPI = require('ripple-lib').RippleAPI
|
|
const xAddress = RippleAPI.classicAddressToXAddress('rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf', 4294967295)
|
|
console.log(xAddress)
|
|
```
|
|
|
|
```
|
|
XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi
|
|
```
|
|
|
|
### Example: Encode a test address for use with Testnet or Devnet
|
|
|
|
```javascript
|
|
const RippleAPI = require('ripple-lib').RippleAPI
|
|
const address = RippleAPI.classicAddressToXAddress('r3SVzk8ApofDJuVBPKdmbbLjWGCCXpBQ2g', 123, true)
|
|
console.log(address)
|
|
```
|
|
|
|
```
|
|
T7oKJ3q7s94kDH6tpkBowhetT1JKfcfdSCmAXbS75iATyLD
|
|
```
|
|
|
|
## xAddressToClassicAddress
|
|
|
|
`xAddressToClassicAddress(xAddress: string): {classicAddress: string, tag: number | false, test: boolean}`
|
|
|
|
Convert an X-address to a classic address and tag.
|
|
|
|
Since `0` is a valid tag, use `if (tag !== false)` to you want to check for a tag.
|
|
|
|
If the address is intended for use on a test network, `test === true`. Otherwise, `test === false`.
|
|
|
|
### Example
|
|
|
|
```javascript
|
|
const RippleAPI = require('ripple-lib').RippleAPI
|
|
const address = RippleAPI.xAddressToClassicAddress('XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi')
|
|
console.log(address)
|
|
```
|
|
|
|
```
|
|
{
|
|
classicAddress: 'rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf',
|
|
tag: 4294967295,
|
|
test: false
|
|
}
|
|
```
|