Demo for code walkthrough functionality

This commit is contained in:
Maria Shodunke
2025-08-13 14:12:22 +01:00
parent 456b607615
commit 06b3c80ac7
4 changed files with 99 additions and 37 deletions

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>XRPL.js Base Example</title>
<!-- @chunk {"steps": ["import-web-tag"]} -->
<script src="https://unpkg.com/xrpl/build/xrpl-latest-min.js"></script>
<!-- @chunk-end -->
</head>
<body>
<h1>XRPL.js Example</h1>
<!-- @chunk {"steps": ["import-web-tag"]} -->
<script>
const xrpl = require("xrpl")
</script>
<!-- @chunk-end -->
</body>
</html>

View File

@@ -1,5 +1,5 @@
// In browsers, use a <script> tag. In Node.js, uncomment the following line:
// const xrpl = require('xrpl')
const xrpl = require('xrpl')
// Wrap code in an async function so we can use await
async function main() {

View File

@@ -1,19 +1,36 @@
// Import the library
// @chunk {"steps": ["import-node-tag"]}
const xrpl = require("xrpl")
// @chunk-end
// Wrap code in an async function so we can use await
async function main() {
// @chunk {"steps": ["connect-tag"]}
// Define the network client
const SERVER_URL = "wss://s.altnet.rippletest.net:51233/"
const client = new xrpl.Client(SERVER_URL)
await client.connect()
// @chunk-end
// @chunk {"steps": ["get-account-create-wallet-tag"]}
// Create a wallet and fund it with the Testnet faucet:
const fund_result = await client.fundWallet()
const test_wallet = fund_result.wallet
console.log(fund_result)
// @chunk-end
// To generate keys only, uncomment the code below
// @chunk {"steps": ["get-account-create-wallet-b-tag"]}
// const test_wallet = xrpl.Wallet.generate()
// @chunk-end
// To provide your own seed, replace the test_wallet value with the below
// @chunk {"steps": ["get-account-create-wallet-c-tag"], "inputs": ["wallet-input"]}
// const test_wallet = xrpl.Wallet.fromSeed({{wallet-input}})
// @chunk-end
// @chunk {"steps": ["query-xrpl-tag"]}
// Get info from the ledger about the address we just funded
const response = await client.request({
"command": "account_info",
@@ -21,7 +38,9 @@ async function main() {
"ledger_index": "validated"
})
console.log(response)
// @chunk-end
// @chunk {"steps": ["listen-for-events-tag"]}
// Listen to ledger close events
client.request({
"command": "subscribe",
@@ -30,9 +49,12 @@ async function main() {
client.on("ledgerClosed", async (ledger) => {
console.log(`Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions!`)
})
// @chunk-end
// @chunk {"steps": ["disconnect-tag"]}
// Disconnect when done so Node.js can end the process
await client.disconnect()
// @chunk-end
}
// call the async function