mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
xrpl.js 2: update many mentions, more code
This commit is contained in:
@@ -11,7 +11,7 @@ labels:
|
||||
|
||||
The XRP Ledger is always online and entirely public. Anyone can access it **directly from a web browser** with source code like what's on this page.
|
||||
|
||||
The following example gets the latest [ledger version](ledgers.html) and a list of transactions that were newly-validated in that ledger version, using the [`getLedger()` method](rippleapi-reference.html#getledger). Try running it as-is, or change the code and see what happens.
|
||||
The following example gets the latest [ledger version](ledgers.html) and a list of transactions that were newly-validated in that ledger version, using the [ledger method][]. Try running it as-is, or change the code and see what happens.
|
||||
|
||||
**Tip:** If you can, open your browser's Developer Tools by pressing **F12**. The "Console" tab provides a native JavaScript console and can give insight into what code is running on any webpage. <!-- SPELLING_IGNORE: f12 -->
|
||||
|
||||
@@ -21,69 +21,69 @@ The following example gets the latest [ledger version](ledgers.html) and a list
|
||||
<!-- JS_EDITOR_START step2 -->
|
||||
|
||||
```js
|
||||
const mainnet = new ripple.RippleAPI({
|
||||
server: 'wss://s1.ripple.com'
|
||||
});
|
||||
|
||||
(async function(api) {
|
||||
async function main() {
|
||||
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||
await api.connect();
|
||||
|
||||
let response = await api.getLedger({
|
||||
includeTransactions: true
|
||||
let response = await api.request({
|
||||
"command": "ledger",
|
||||
"ledger_index": "validated"
|
||||
"transactions": true
|
||||
});
|
||||
console.log(response);
|
||||
|
||||
})(mainnet);
|
||||
}
|
||||
main()
|
||||
```
|
||||
|
||||
```js
|
||||
const mainnet = new ripple.RippleAPI({
|
||||
server: 'wss://s.altnet.rippletest.net/'
|
||||
});
|
||||
|
||||
(async function(api) {
|
||||
async function main() {
|
||||
const api = new xrpl.Client('wss://s.altnet.rippletest.net/');
|
||||
await api.connect();
|
||||
|
||||
let response = await api.getLedger({
|
||||
includeTransactions: true
|
||||
});
|
||||
let response = await api.request({
|
||||
"command": "ledger",
|
||||
"ledger_index": "validated"
|
||||
"transactions": true
|
||||
});
|
||||
console.log(response);
|
||||
|
||||
})(mainnet);
|
||||
}
|
||||
main()
|
||||
```
|
||||
|
||||
```js
|
||||
const mainnet = new ripple.RippleAPI({
|
||||
server: 'wss://s1.ripple.com'
|
||||
});
|
||||
|
||||
(async function(api) {
|
||||
async function main() {
|
||||
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||
await api.connect();
|
||||
|
||||
let response = await api.getLedger({
|
||||
includeTransactions: true
|
||||
});
|
||||
let tx_id = response.transactionHashes[0];
|
||||
let response2 = await api.getTransaction(tx_id);
|
||||
let response = await api.request({
|
||||
"command": "ledger",
|
||||
"ledger_index": "validated"
|
||||
"transactions": true
|
||||
});
|
||||
|
||||
let tx_id = response.result.transactions[0];
|
||||
let response2 = await api.request({
|
||||
"command": "tx",
|
||||
"transaction": tx_id
|
||||
});
|
||||
console.log(response2);
|
||||
|
||||
})(mainnet);
|
||||
}
|
||||
main()
|
||||
```
|
||||
|
||||
```js
|
||||
const mainnet = new ripple.RippleAPI({
|
||||
server: 'wss://s1.ripple.com'
|
||||
});
|
||||
|
||||
(async function(api) {
|
||||
async function main() {
|
||||
const api = new xrpl.Client('wss://xrplcluster.com');
|
||||
await api.connect();
|
||||
|
||||
let response = await api.getLedger({
|
||||
includeTransactions: true
|
||||
});
|
||||
console.log('Total XRP: '+api.dropsToXrp(response.totalDrops));
|
||||
|
||||
})(mainnet);
|
||||
let response = await api.request({
|
||||
"command": "ledger",
|
||||
"ledger_index": "validated"
|
||||
"transactions": true
|
||||
});
|
||||
console.log('Total XRP: '+xrpl.dropsToXrp(response.result.ledger.total_coins));
|
||||
}
|
||||
main()
|
||||
```
|
||||
|
||||
<!-- JS_EDITOR_END -->
|
||||
@@ -100,7 +100,7 @@ Try editing the code above to do something different:
|
||||
|
||||
## Setup Steps
|
||||
|
||||
This page has the necessary prerequisites already loaded, but you can access the XRP Ledger from **any webpage** if you load [RippleAPI for JavaScript (ripple-lib)](rippleapi-reference.html) in that page's HTML. For example:
|
||||
This page has the necessary prerequisites already loaded, but you can access the XRP Ledger from **any webpage** if you load [xrpl.js](https://github.com/XRPLF/xrpl.js/) in that page's HTML. For example:
|
||||
|
||||
```html
|
||||
<script src="https://unpkg.com/ripple-lib@1.10.0/build/ripple-latest-min.js"></script>
|
||||
@@ -115,3 +115,8 @@ When you're ready to move on, continue using the XRP Ledger with these resources
|
||||
- [Use the RippleAPI Reference](rippleapi-reference.html) to see what else you can do.
|
||||
- [Install `rippled`](install-rippled.html) to participate in the network.
|
||||
- [Get Testnet XRP](xrp-testnet-faucet.html) to try sending and receiving payments.
|
||||
|
||||
<!--{# common link defs #}-->
|
||||
{% include '_snippets/rippled-api-links.md' %}
|
||||
{% include '_snippets/tx-type-links.md' %}
|
||||
{% include '_snippets/rippled_versions.md' %}
|
||||
|
||||
Reference in New Issue
Block a user