{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["code-walkthrough","step","code-snippet","admonition","source-link"]},"type":"markdown"},"seo":{"title":"Get Started Using TypeScript Library","siteUrl":"https://xrpl.org/","llmstxt":{"hide":false,"title":"XRPL Developer Portal & Documentation","description":"Explore XRP Ledger documentation, blogs, and other blockchain developer resources needed to start building and integrating with the ledger.","details":{"content":"XRP Ledger concepts, use cases, tutorials, references, and other blockchain developer resources. Also, stay up to date with release announcements and more through the XRPL Blog."},"sections":[{"title":"Introduction","description":"A high-level introduction to the XRP Ledger.","includeFiles":["docs/introduction/**/*.*","about/faq.md"],"excludeFiles":["docs/introduction/index.md"]},{"title":"Use Cases","description":"Real-world applications and business scenarios for the XRP Ledger.","includeFiles":["docs/use-cases/**/*.*"],"excludeFiles":["docs/use-cases/index.md","docs/use-cases/defi/index.md"]},{"title":"Agentic Transactions","description":"XRPL AI Starter Kit to help autonomous agents discover, set up, and execute agentic transactions on the XRP Ledger.","includeFiles":["docs/agents/**/*.*"],"excludeFiles":[]},{"title":"Concepts","description":"Core concepts including accounts, tokens, transactions, consensus, and more.","includeFiles":["docs/concepts/**/*.*"],"excludeFiles":["docs/concepts/index.md","docs/concepts/decentralized-storage/index.md","docs/concepts/payment-types/index.md"]},{"title":"Tutorials","description":"Step-by-step guides for building on the XRP Ledger in JavaScript, Python, Go, and more.","includeFiles":["docs/tutorials/**/*.*"],"excludeFiles":[]},{"title":"References","description":"Protocol specification, transaction types, ledger entries, and API methods.","includeFiles":["docs/references/**/*.*"],"excludeFiles":["docs/references/xrp-api.md","docs/references/data-api.md","docs/references/protocol/index.md","docs/references/protocol/ledger-data/ledger-entry-types/index.md","docs/references/protocol/transactions/index.md","docs/references/protocol/transactions/types/index.md","docs/references/http-websocket-apis/api-conventions/index.md","docs/references/http-websocket-apis/public-api-methods/*/index.md","docs/references/http-websocket-apis/admin-api-methods/*/index.md"]},{"title":"Infrastructure","description":"Install, configure, and troubleshoot xrpld and Clio servers.","includeFiles":["docs/infrastructure/**/*.*"],"excludeFiles":["docs/infrastructure/index.md","docs/infrastructure/*/index.md","docs/infrastructure/installation/build-run-xrpld-in-reporting-mode.md","docs/infrastructure/configuration/data-retention/index.md","docs/infrastructure/configuration/server-modes/index.md"]},{"title":"Blog (2023+)","description":"Recent XRPL Blog posts (showing 2023 and newer).","includeFiles":["blog/2023/**/*.*","blog/2024/**/*.*","blog/2025/**/*.*","blog/2026/**/*.*"],"excludeFiles":[]},{"title":"Resources","description":"Developer resources and contribution guidelines.","includeFiles":["resources/**/*.*"],"excludeFiles":["resources/index.md"]}],"excludeFiles":[]},"description":"Build an entry-level TypeScript application for querying the XRP Ledger."},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"CodeWalkthrough","attributes":{"__idx":1,"filters":{"environment":{"label":"Environment","items":[{"value":"Node"},{"value":"Web"}]}},"filesets":[{"files":[{"path":"_code-samples/get-started/ts/get-acct-info.ts","content":[{"start":0,"condition":{"steps":["import-node-tag"]},"children":["// Import the library along with the TypeScript types you use below.","import {","  Client,","  Wallet,","  Payment,","  AccountInfoRequest,","  AccountInfoResponse,","  xrpToDrops,","  validate","} from 'xrpl'"]},"",{"start":13,"condition":{"steps":["connect-tag"]},"children":["// Define the network client. The Client type is inferred from the constructor.","const SERVER_URL = 'wss://s.altnet.rippletest.net:51233/'","const client = new Client(SERVER_URL)","await client.connect()","console.log('Connected to Testnet')"]},"",{"start":21,"condition":{"steps":["get-account-create-wallet-tag"]},"children":["// Create a wallet and fund it with the Testnet faucet.","console.log('\\nCreating a new wallet and funding it with Testnet XRP...')","const fundResult = await client.fundWallet()","// Annotating with the Wallet type lets TypeScript check every field you touch.","const testWallet: Wallet = fundResult.wallet","console.log(`Wallet: ${testWallet.address}`)","console.log(`Balance: ${fundResult.balance}`)","console.log('Account Testnet Explorer URL:')","console.log(`  https://testnet.xrpl.org/accounts/${testWallet.address}`)"]},"","// To generate a wallet without funding it, uncomment the code below.",{"start":34,"condition":{"steps":["get-account-create-wallet-b-tag"]},"children":["// const testWallet: Wallet = Wallet.generate()"]},"","// To provide your own seed, replace the testWallet value with the below.",{"start":39,"condition":{"steps":["get-account-create-wallet-c-tag"]},"children":["// const testWallet: Wallet = Wallet.fromSeed('your-seed-key')"]},"",{"start":43,"condition":{"steps":["query-xrpl-tag"]},"children":["// Build the request as an AccountInfoRequest. TypeScript verifies the command","// name and fields, and infers the matching AccountInfoResponse for the result.","console.log('\\nGetting account info...')","const request: AccountInfoRequest = {","  command: 'account_info',","  account: testWallet.address,","  ledger_index: 'validated'","}","const response: AccountInfoResponse = await client.request(request)","console.log(JSON.stringify(response, null, 2))"]},"",{"start":56,"condition":{"steps":["build-tx-tag"]},"children":["// Turn your own input values into a valid transaction. Typing the object as a","// Payment makes the compiler require every field and reject the wrong ones.","const xrpToSend = 22 // a value you might read from user input","const payment: Payment = {","  TransactionType: 'Payment',","  Account: testWallet.address,","  // xrpToDrops converts the XRP amount into the drops string the ledger expects.","  Amount: xrpToDrops(xrpToSend),","  Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe' // example destination","}","","// validate() runs the same structural checks the server does, at runtime. It","// takes a generic transaction object, so pass the typed value through to it.","validate(payment as unknown as Record<string, unknown>)","console.log('\\nBuilt and validated a Payment transaction:')","console.log(JSON.stringify(payment, null, 2))","// To send it, sign and submit in one call:","const submitResponse = await client.submitAndWait(payment, { wallet: testWallet })","console.log(JSON.stringify(submitResponse.result, null, 2))"]},"",{"start":78,"condition":{"steps":["listen-for-events-tag"]},"children":["// Listen to ledger close events. The ledger argument is typed for you, so","// ledger.ledger_index and ledger.txn_count are checked at compile time.","console.log('\\nListening for ledger close events...')","client.request({","  command: 'subscribe',","  streams: ['ledger']","})","client.on('ledgerClosed', (ledger) => {","  console.log(`Ledger #${ledger.ledger_index} validated ` +","              `with ${ledger.txn_count} transactions!`)","})"]},"",{"start":92,"condition":{"steps":["disconnect-node-tag"]},"children":["// Disconnect when done so Node.js can end the process.","// Delay this by 10 seconds to give the ledger event listener time to receive","// and display some ledger events.","setTimeout(async () => {","  await client.disconnect()","  console.log('\\nDisconnected')","}, 10000)"]},""],"metadata":{"steps":["import-node-tag","connect-tag","get-account-create-wallet-tag","get-account-create-wallet-b-tag","get-account-create-wallet-c-tag","query-xrpl-tag","build-tx-tag","listen-for-events-tag","disconnect-node-tag"]},"basename":"get-acct-info.ts","language":"typescript"}],"downloadAssociatedFiles":[{"path":"_code-samples/get-started/ts/package.json","content":["{","  \"name\": \"get-started-typescript\",","  \"description\": \"Example code for the Get Started Using TypeScript tutorial.\",","  \"dependencies\": {","    \"xrpl\": \"^4.4.0\"","  },","  \"devDependencies\": {","    \"typescript\": \"^5.5.0\",","    \"@types/node\": \"^22.0.0\"","  },","  \"type\": \"module\"","}",""],"metadata":{"steps":[]},"basename":"package.json","language":"text"},{"path":"_code-samples/get-started/ts/tsconfig.json","content":["{","  \"compilerOptions\": {","    \"target\": \"ES2020\",","    \"module\": \"NodeNext\",","    \"moduleResolution\": \"NodeNext\",","    \"lib\": [\"ES2020\", \"DOM\"],","    \"outDir\": \"dist\",","    \"strict\": true,","    \"esModuleInterop\": true,","    \"skipLibCheck\": true,","    \"forceConsistentCasingInFileNames\": true","  },","  \"include\": [\"*.ts\"]","}",""],"metadata":{"steps":[]},"basename":"tsconfig.json","language":"text"},{"path":"_code-samples/get-started/ts/get-acct-info.ts","content":[{"start":0,"condition":{"steps":["import-node-tag"]},"children":["// Import the library along with the TypeScript types you use below.","import {","  Client,","  Wallet,","  Payment,","  AccountInfoRequest,","  AccountInfoResponse,","  xrpToDrops,","  validate","} from 'xrpl'"]},"",{"start":13,"condition":{"steps":["connect-tag"]},"children":["// Define the network client. The Client type is inferred from the constructor.","const SERVER_URL = 'wss://s.altnet.rippletest.net:51233/'","const client = new Client(SERVER_URL)","await client.connect()","console.log('Connected to Testnet')"]},"",{"start":21,"condition":{"steps":["get-account-create-wallet-tag"]},"children":["// Create a wallet and fund it with the Testnet faucet.","console.log('\\nCreating a new wallet and funding it with Testnet XRP...')","const fundResult = await client.fundWallet()","// Annotating with the Wallet type lets TypeScript check every field you touch.","const testWallet: Wallet = fundResult.wallet","console.log(`Wallet: ${testWallet.address}`)","console.log(`Balance: ${fundResult.balance}`)","console.log('Account Testnet Explorer URL:')","console.log(`  https://testnet.xrpl.org/accounts/${testWallet.address}`)"]},"","// To generate a wallet without funding it, uncomment the code below.",{"start":34,"condition":{"steps":["get-account-create-wallet-b-tag"]},"children":["// const testWallet: Wallet = Wallet.generate()"]},"","// To provide your own seed, replace the testWallet value with the below.",{"start":39,"condition":{"steps":["get-account-create-wallet-c-tag"]},"children":["// const testWallet: Wallet = Wallet.fromSeed('your-seed-key')"]},"",{"start":43,"condition":{"steps":["query-xrpl-tag"]},"children":["// Build the request as an AccountInfoRequest. TypeScript verifies the command","// name and fields, and infers the matching AccountInfoResponse for the result.","console.log('\\nGetting account info...')","const request: AccountInfoRequest = {","  command: 'account_info',","  account: testWallet.address,","  ledger_index: 'validated'","}","const response: AccountInfoResponse = await client.request(request)","console.log(JSON.stringify(response, null, 2))"]},"",{"start":56,"condition":{"steps":["build-tx-tag"]},"children":["// Turn your own input values into a valid transaction. Typing the object as a","// Payment makes the compiler require every field and reject the wrong ones.","const xrpToSend = 22 // a value you might read from user input","const payment: Payment = {","  TransactionType: 'Payment',","  Account: testWallet.address,","  // xrpToDrops converts the XRP amount into the drops string the ledger expects.","  Amount: xrpToDrops(xrpToSend),","  Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe' // example destination","}","","// validate() runs the same structural checks the server does, at runtime. It","// takes a generic transaction object, so pass the typed value through to it.","validate(payment as unknown as Record<string, unknown>)","console.log('\\nBuilt and validated a Payment transaction:')","console.log(JSON.stringify(payment, null, 2))","// To send it, sign and submit in one call:","const submitResponse = await client.submitAndWait(payment, { wallet: testWallet })","console.log(JSON.stringify(submitResponse.result, null, 2))"]},"",{"start":78,"condition":{"steps":["listen-for-events-tag"]},"children":["// Listen to ledger close events. The ledger argument is typed for you, so","// ledger.ledger_index and ledger.txn_count are checked at compile time.","console.log('\\nListening for ledger close events...')","client.request({","  command: 'subscribe',","  streams: ['ledger']","})","client.on('ledgerClosed', (ledger) => {","  console.log(`Ledger #${ledger.ledger_index} validated ` +","              `with ${ledger.txn_count} transactions!`)","})"]},"",{"start":92,"condition":{"steps":["disconnect-node-tag"]},"children":["// Disconnect when done so Node.js can end the process.","// Delay this by 10 seconds to give the ledger event listener time to receive","// and display some ledger events.","setTimeout(async () => {","  await client.disconnect()","  console.log('\\nDisconnected')","}, 10000)"]},""],"metadata":{"steps":["import-node-tag","connect-tag","get-account-create-wallet-tag","get-account-create-wallet-b-tag","get-account-create-wallet-c-tag","query-xrpl-tag","build-tx-tag","listen-for-events-tag","disconnect-node-tag"]},"basename":"get-acct-info.ts","language":"typescript"},{"path":"_code-samples/get-started/ts/README.md","content":["# Get Started Using TypeScript Library","","Connects to the XRP Ledger, gets account information, builds and validates a typed transaction, and subscribes to ledger events using TypeScript and `xrpl.js`.","","To download the source code, see the [Get Started Using TypeScript tutorial](https://xrpl.org/docs/tutorials/get-started/get-started-typescript) on xrpl.org.","","## Setup","","Install the runtime and development dependencies (`xrpl`, `typescript`, and `@types/node`):","","```sh","npm install","```","","## Run the Code","","**Node.js**","","Compile the TypeScript to JavaScript, then run it:","","```sh","npx tsc","node ./dist/get-acct-info.js","```","","You should see output similar to the following:","","```sh","Connected to Testnet","","Creating a new wallet and funding it with Testnet XRP...","Wallet: rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i","Balance: 100","Account Testnet Explorer URL:","  https://testnet.xrpl.org/accounts/rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i","","Getting account info...","{","  \"api_version\": 2,","  \"id\": 4,","  \"result\": {","    \"account_data\": {","      \"Account\": \"rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i\",","      \"Balance\": \"10000000\",","      \"Flags\": 0,","      \"LedgerEntryType\": \"AccountRoot\",","      \"OwnerCount\": 0,","      \"PreviousTxnID\": \"0FF9DB2FE141DD0DF82566A171B6AF70BB2C6EB6A53D496E65D42FC062C91A78\",","      \"PreviousTxnLgrSeq\": 9949268,","      \"Sequence\": 9949268,","      \"index\": \"4A9C9220AE778DC38C004B2B17A08E218416D90E01456AFCF844C18838B36D01\"","    },","    \"ledger_hash\": \"304C7CC2A33B712BE43EB398B399E290C191A71FCB71784F584544DFB7C441B0\",","    \"ledger_index\": 9949268,","    \"validated\": true","  },","  \"type\": \"response\"","}","","Built and validated a Payment transaction:","{","  \"TransactionType\": \"Payment\",","  \"Account\": \"rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i\",","  \"Amount\": \"22000000\",","  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"","}","","Listening for ledger close events...","Ledger #9949269 validated with 0 transactions!","Ledger #9949270 validated with 0 transactions!","Ledger #9949271 validated with 0 transactions!","","Disconnected","```","","**Web**","","Compile the TypeScript, then open `index.html` in a web browser and wait for the results to appear on the page:","","```sh","npx tsc","```","","The page loads `xrpl.js` through an import map and runs the compiled `dist/browser.js`. You should see output similar to the following:","","```text","Connected to Testnet","Creating a new wallet and funding it with Testnet XRP...","Wallet: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S","Balance: 100","View account on XRPL Testnet Explorer: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S","","Getting account info...","{ ...account_info response... }","","Built and validated a Payment transaction:","{","  \"TransactionType\": \"Payment\",","  \"Account\": \"rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\",","  \"Amount\": \"22000000\",","  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"","}","","Listening for ledger close events...","Ledger #9949611 validated with 0 transactions","Ledger #9949612 validated with 1 transactions","Ledger #9949613 validated with 0 transactions","","Disconnected","```",""],"metadata":{"steps":[]},"basename":"README.md","language":"markdoc"}],"when":{"environment":"Node"}},{"files":[{"path":"_code-samples/get-started/ts/browser.ts","content":[{"start":0,"condition":{"steps":["import-web-tag"]},"children":["// Import the library along with the TypeScript types you use below. The import","// map in index.html resolves 'xrpl' to a browser build at runtime.","import {","  Client,","  Wallet,","  Payment,","  AccountInfoRequest,","  AccountInfoResponse,","  xrpToDrops,","  validate","} from 'xrpl'","","const output = document.getElementById('output') as HTMLElement"]},"",{"start":16,"condition":{"steps":["connect-tag"]},"children":["// Define the network client. The Client type is inferred from the constructor.","const SERVER_URL = 'wss://s.altnet.rippletest.net:51233/'","const client = new Client(SERVER_URL)","await client.connect()","output.innerHTML = '<p>Connected to Testnet</p>'"]},"",{"start":24,"condition":{"steps":["get-account-create-wallet-tag"]},"children":["// Create a wallet and fund it with the Testnet faucet.","output.innerHTML += '<p>Creating a new wallet and funding it with Testnet XRP...</p>'","const fundResult = await client.fundWallet()","// Annotating with the Wallet type lets TypeScript check every field you touch.","const testWallet: Wallet = fundResult.wallet","output.innerHTML += `<p>Wallet: ${testWallet.address}</p>`","output.innerHTML += `<p>Balance: ${fundResult.balance}</p>`","output.innerHTML += `<p>View account on XRPL Testnet Explorer: <a href=\"https://testnet.xrpl.org/accounts/${testWallet.address}\" target=\"_blank\">${testWallet.address}</a></p>`"]},"","// To generate a wallet without funding it, uncomment the code below.",{"start":36,"condition":{"steps":["get-account-create-wallet-b-tag"]},"children":["// const testWallet: Wallet = Wallet.generate()"]},"","// To provide your own seed, replace the testWallet value with the below.",{"start":41,"condition":{"steps":["get-account-create-wallet-c-tag"]},"children":["// const testWallet: Wallet = Wallet.fromSeed('your-seed-key')"]},"",{"start":45,"condition":{"steps":["query-xrpl-tag"]},"children":["// Build the request as an AccountInfoRequest. TypeScript verifies the command","// name and fields, and infers the matching AccountInfoResponse for the result.","output.innerHTML += '<p>Getting account info...</p>'","const request: AccountInfoRequest = {","  command: 'account_info',","  account: testWallet.address,","  ledger_index: 'validated'","}","const response: AccountInfoResponse = await client.request(request)","output.innerHTML += `<pre>${JSON.stringify(response, null, 2)}</pre>`"]},"",{"start":58,"condition":{"steps":["build-tx-tag"]},"children":["// Turn your own input values into a valid transaction. Typing the object as a","// Payment makes the compiler require every field and reject the wrong ones.","const xrpToSend = 22 // a value you might read from user input","const payment: Payment = {","  TransactionType: 'Payment',","  Account: testWallet.address,","  // xrpToDrops converts the XRP amount into the drops string the ledger expects.","  Amount: xrpToDrops(xrpToSend),","  Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe' // example destination","}","","// validate() runs the same structural checks the server does, at runtime. It","// takes a generic transaction object, so pass the typed value through to it.","validate(payment as unknown as Record<string, unknown>)","output.innerHTML += '<p>Built and validated a Payment transaction:</p>'","output.innerHTML += `<pre>${JSON.stringify(payment, null, 2)}</pre>`","// To send it, sign and submit in one call:","//   await client.submitAndWait(payment, { wallet: testWallet })"]},"",{"start":79,"condition":{"steps":["listen-for-events-tag"]},"children":["// Listen to ledger close events. The ledger argument is typed for you, so","// ledger.ledger_index and ledger.txn_count are checked at compile time.","output.innerHTML += '<p>Listening for ledger close events...</p>'","client.request({","  command: 'subscribe',","  streams: ['ledger']","})","client.on('ledgerClosed', (ledger) => {","  output.innerHTML += `<p>Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions</p>`","})"]},"",{"start":92,"condition":{"steps":["disconnect-web-tag"]},"children":["// Disconnect from the ledger when done. Delay this by 10 seconds to give the","// ledger event listener time to receive and display some ledger events.","setTimeout(async () => {","  await client.disconnect()","  output.innerHTML += '<p>Disconnected</p>'","}, 10000)"]},""],"metadata":{"steps":["import-web-tag","connect-tag","get-account-create-wallet-tag","get-account-create-wallet-b-tag","get-account-create-wallet-c-tag","query-xrpl-tag","build-tx-tag","listen-for-events-tag","disconnect-web-tag"]},"basename":"browser.ts","language":"typescript"}],"downloadAssociatedFiles":[{"path":"_code-samples/get-started/ts/index.html","content":["<!DOCTYPE html>","<html>","  <head>","    <title>xrpl.js TypeScript Base Example</title>",{"start":4,"condition":{"steps":["import-web-tag"]},"children":["    <!-- The import map resolves the bare 'xrpl' specifier used in browser.ts","         to a browser-ready ES module build served from a CDN. -->","    <script type=\"importmap\">","      { \"imports\": { \"xrpl\": \"https://esm.sh/xrpl@4\" } }","    </script>","    <!-- Load the compiled output of browser.ts (created by `npx tsc`). -->","    <script type=\"module\" src=\"./dist/browser.js\"></script>"]},"  </head>","  <body>","    <h1>xrpl.js TypeScript Get Started</h1>","    <div id=\"output\"></div>","  </body>","</html>",""],"metadata":{"steps":["import-web-tag"]},"basename":"index.html","language":"html"},{"path":"_code-samples/get-started/ts/browser.ts","content":[{"start":0,"condition":{"steps":["import-web-tag"]},"children":["// Import the library along with the TypeScript types you use below. The import","// map in index.html resolves 'xrpl' to a browser build at runtime.","import {","  Client,","  Wallet,","  Payment,","  AccountInfoRequest,","  AccountInfoResponse,","  xrpToDrops,","  validate","} from 'xrpl'","","const output = document.getElementById('output') as HTMLElement"]},"",{"start":16,"condition":{"steps":["connect-tag"]},"children":["// Define the network client. The Client type is inferred from the constructor.","const SERVER_URL = 'wss://s.altnet.rippletest.net:51233/'","const client = new Client(SERVER_URL)","await client.connect()","output.innerHTML = '<p>Connected to Testnet</p>'"]},"",{"start":24,"condition":{"steps":["get-account-create-wallet-tag"]},"children":["// Create a wallet and fund it with the Testnet faucet.","output.innerHTML += '<p>Creating a new wallet and funding it with Testnet XRP...</p>'","const fundResult = await client.fundWallet()","// Annotating with the Wallet type lets TypeScript check every field you touch.","const testWallet: Wallet = fundResult.wallet","output.innerHTML += `<p>Wallet: ${testWallet.address}</p>`","output.innerHTML += `<p>Balance: ${fundResult.balance}</p>`","output.innerHTML += `<p>View account on XRPL Testnet Explorer: <a href=\"https://testnet.xrpl.org/accounts/${testWallet.address}\" target=\"_blank\">${testWallet.address}</a></p>`"]},"","// To generate a wallet without funding it, uncomment the code below.",{"start":36,"condition":{"steps":["get-account-create-wallet-b-tag"]},"children":["// const testWallet: Wallet = Wallet.generate()"]},"","// To provide your own seed, replace the testWallet value with the below.",{"start":41,"condition":{"steps":["get-account-create-wallet-c-tag"]},"children":["// const testWallet: Wallet = Wallet.fromSeed('your-seed-key')"]},"",{"start":45,"condition":{"steps":["query-xrpl-tag"]},"children":["// Build the request as an AccountInfoRequest. TypeScript verifies the command","// name and fields, and infers the matching AccountInfoResponse for the result.","output.innerHTML += '<p>Getting account info...</p>'","const request: AccountInfoRequest = {","  command: 'account_info',","  account: testWallet.address,","  ledger_index: 'validated'","}","const response: AccountInfoResponse = await client.request(request)","output.innerHTML += `<pre>${JSON.stringify(response, null, 2)}</pre>`"]},"",{"start":58,"condition":{"steps":["build-tx-tag"]},"children":["// Turn your own input values into a valid transaction. Typing the object as a","// Payment makes the compiler require every field and reject the wrong ones.","const xrpToSend = 22 // a value you might read from user input","const payment: Payment = {","  TransactionType: 'Payment',","  Account: testWallet.address,","  // xrpToDrops converts the XRP amount into the drops string the ledger expects.","  Amount: xrpToDrops(xrpToSend),","  Destination: 'rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe' // example destination","}","","// validate() runs the same structural checks the server does, at runtime. It","// takes a generic transaction object, so pass the typed value through to it.","validate(payment as unknown as Record<string, unknown>)","output.innerHTML += '<p>Built and validated a Payment transaction:</p>'","output.innerHTML += `<pre>${JSON.stringify(payment, null, 2)}</pre>`","// To send it, sign and submit in one call:","//   await client.submitAndWait(payment, { wallet: testWallet })"]},"",{"start":79,"condition":{"steps":["listen-for-events-tag"]},"children":["// Listen to ledger close events. The ledger argument is typed for you, so","// ledger.ledger_index and ledger.txn_count are checked at compile time.","output.innerHTML += '<p>Listening for ledger close events...</p>'","client.request({","  command: 'subscribe',","  streams: ['ledger']","})","client.on('ledgerClosed', (ledger) => {","  output.innerHTML += `<p>Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions</p>`","})"]},"",{"start":92,"condition":{"steps":["disconnect-web-tag"]},"children":["// Disconnect from the ledger when done. Delay this by 10 seconds to give the","// ledger event listener time to receive and display some ledger events.","setTimeout(async () => {","  await client.disconnect()","  output.innerHTML += '<p>Disconnected</p>'","}, 10000)"]},""],"metadata":{"steps":["import-web-tag","connect-tag","get-account-create-wallet-tag","get-account-create-wallet-b-tag","get-account-create-wallet-c-tag","query-xrpl-tag","build-tx-tag","listen-for-events-tag","disconnect-web-tag"]},"basename":"browser.ts","language":"typescript"},{"path":"_code-samples/get-started/ts/package.json","content":["{","  \"name\": \"get-started-typescript\",","  \"description\": \"Example code for the Get Started Using TypeScript tutorial.\",","  \"dependencies\": {","    \"xrpl\": \"^4.4.0\"","  },","  \"devDependencies\": {","    \"typescript\": \"^5.5.0\",","    \"@types/node\": \"^22.0.0\"","  },","  \"type\": \"module\"","}",""],"metadata":{"steps":[]},"basename":"package.json","language":"text"},{"path":"_code-samples/get-started/ts/tsconfig.json","content":["{","  \"compilerOptions\": {","    \"target\": \"ES2020\",","    \"module\": \"NodeNext\",","    \"moduleResolution\": \"NodeNext\",","    \"lib\": [\"ES2020\", \"DOM\"],","    \"outDir\": \"dist\",","    \"strict\": true,","    \"esModuleInterop\": true,","    \"skipLibCheck\": true,","    \"forceConsistentCasingInFileNames\": true","  },","  \"include\": [\"*.ts\"]","}",""],"metadata":{"steps":[]},"basename":"tsconfig.json","language":"text"},{"path":"_code-samples/get-started/ts/README.md","content":["# Get Started Using TypeScript Library","","Connects to the XRP Ledger, gets account information, builds and validates a typed transaction, and subscribes to ledger events using TypeScript and `xrpl.js`.","","To download the source code, see the [Get Started Using TypeScript tutorial](https://xrpl.org/docs/tutorials/get-started/get-started-typescript) on xrpl.org.","","## Setup","","Install the runtime and development dependencies (`xrpl`, `typescript`, and `@types/node`):","","```sh","npm install","```","","## Run the Code","","**Node.js**","","Compile the TypeScript to JavaScript, then run it:","","```sh","npx tsc","node ./dist/get-acct-info.js","```","","You should see output similar to the following:","","```sh","Connected to Testnet","","Creating a new wallet and funding it with Testnet XRP...","Wallet: rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i","Balance: 100","Account Testnet Explorer URL:","  https://testnet.xrpl.org/accounts/rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i","","Getting account info...","{","  \"api_version\": 2,","  \"id\": 4,","  \"result\": {","    \"account_data\": {","      \"Account\": \"rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i\",","      \"Balance\": \"10000000\",","      \"Flags\": 0,","      \"LedgerEntryType\": \"AccountRoot\",","      \"OwnerCount\": 0,","      \"PreviousTxnID\": \"0FF9DB2FE141DD0DF82566A171B6AF70BB2C6EB6A53D496E65D42FC062C91A78\",","      \"PreviousTxnLgrSeq\": 9949268,","      \"Sequence\": 9949268,","      \"index\": \"4A9C9220AE778DC38C004B2B17A08E218416D90E01456AFCF844C18838B36D01\"","    },","    \"ledger_hash\": \"304C7CC2A33B712BE43EB398B399E290C191A71FCB71784F584544DFB7C441B0\",","    \"ledger_index\": 9949268,","    \"validated\": true","  },","  \"type\": \"response\"","}","","Built and validated a Payment transaction:","{","  \"TransactionType\": \"Payment\",","  \"Account\": \"rMnXR9p2sZT9iZ6ew3iEqvBMyPts1ADc4i\",","  \"Amount\": \"22000000\",","  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"","}","","Listening for ledger close events...","Ledger #9949269 validated with 0 transactions!","Ledger #9949270 validated with 0 transactions!","Ledger #9949271 validated with 0 transactions!","","Disconnected","```","","**Web**","","Compile the TypeScript, then open `index.html` in a web browser and wait for the results to appear on the page:","","```sh","npx tsc","```","","The page loads `xrpl.js` through an import map and runs the compiled `dist/browser.js`. You should see output similar to the following:","","```text","Connected to Testnet","Creating a new wallet and funding it with Testnet XRP...","Wallet: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S","Balance: 100","View account on XRPL Testnet Explorer: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S","","Getting account info...","{ ...account_info response... }","","Built and validated a Payment transaction:","{","  \"TransactionType\": \"Payment\",","  \"Account\": \"rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\",","  \"Amount\": \"22000000\",","  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"","}","","Listening for ledger close events...","Ledger #9949611 validated with 0 transactions","Ledger #9949612 validated with 1 transactions","Ledger #9949613 validated with 0 transactions","","Disconnected","```",""],"metadata":{"steps":[]},"basename":"README.md","language":"markdoc"}],"when":{"environment":"Web"}}],"steps":[{"id":"import-web-tag","when":{"environment":"Web"}},{"id":"import-node-tag","when":{"environment":"Node"}},{"id":"configure-ts-tag"},{"id":"connect-tag"},{"id":"connect-mainnet-tag"},{"id":"get-account-create-wallet-tag"},{"id":"get-account-create-wallet-b-tag"},{"id":"get-account-create-wallet-c-tag"},{"id":"query-xrpl-tag"},{"id":"build-tx-tag"},{"id":"listen-for-events-tag"},{"id":"disconnect-node-tag","when":{"environment":"Node"}},{"id":"disconnect-web-tag","when":{"environment":"Web"}},{"id":"run-app-node-tag","when":{"environment":"Node"}},{"id":"run-app-web-tag","when":{"environment":"Web"}}],"inputs":{},"toggles":{}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"get-started-using-typescript-library","__idx":0},"children":["Get Started Using TypeScript Library"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This tutorial guides you through the basics of building an XRP Ledger-connected application in TypeScript using the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/XRPLF/xrpl.js/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}]}," client library in either Node.js or web browsers. Because ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," ships its own type definitions, you get compile-time checking of your requests and transactions with no extra setup."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"goals","__idx":1},"children":["Goals"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In this tutorial, you'll learn:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The basic building blocks of XRP Ledger-based applications."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to set up a TypeScript project that compiles and runs against the XRP Ledger."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to connect to the XRP Ledger using ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to get an account on the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/resources/dev-tools/xrp-faucets"},"children":["Testnet"]}," using ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to use the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," library to look up information about an account on the XRP Ledger."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to use the library's built-in types to build and validate a transaction from your own input values."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["How to put these steps together to create a TypeScript app or web-app."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":2},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To complete this tutorial, you should meet the following guidelines:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Have some familiarity with writing code in TypeScript."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Have installed Node.js ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["version 20"]}," or later in your development environment."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If you want to build a web application, any modern web browser with JavaScript support should work fine."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You don't need to install the TypeScript compiler globally; the steps below add it as a project dependency."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"source-code","__idx":3},"children":["Source Code"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Click ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Download"]}," on the top right of the code preview panel to download the source code."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"steps","__idx":4},"children":["Steps"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Follow the steps to create a simple application with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," and TypeScript."]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"import-web-tag","when":{"environment":"Web"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"1-install-dependencies","__idx":5},"children":["1. Install Dependencies"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For a web app, you load ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," at runtime and use the TypeScript compiler as a build tool. Create an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["index.html"]}," file that loads the library through an ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap"},"children":["import map"]}," and runs your compiled script:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/_code-samples/get-started/ts/index.html","language":"html","header":{"controls":{"copy":{}}},"lang":"html","source":"<!DOCTYPE html>\n<html>\n  <head>\n    <title>xrpl.js TypeScript Base Example</title>\n    <!-- @chunk {\"steps\": [\"import-web-tag\"]} -->\n    <!-- The import map resolves the bare 'xrpl' specifier used in browser.ts\n         to a browser-ready ES module build served from a CDN. -->\n    <script type=\"importmap\">\n      { \"imports\": { \"xrpl\": \"https://esm.sh/xrpl@4\" } }\n    </script>\n    <!-- Load the compiled output of browser.ts (created by `npx tsc`). -->\n    <script type=\"module\" src=\"./dist/browser.js\"></script>\n    <!-- @chunk-end -->\n  </head>\n  <body>\n    <h1>xrpl.js TypeScript Get Started</h1>\n    <div id=\"output\"></div>\n  </body>\n</html>\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To get the type definitions and the compiler, install ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["typescript"]}," with ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.npmjs.com/"},"children":["NPM"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"npm install xrpl\nnpm install --save-dev typescript\n","lang":"sh"},"children":[]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"import-node-tag","when":{"environment":"Node"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"1-install-dependencies-1","__idx":6},"children":["1. Install Dependencies"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Start a new project by creating an empty folder, then move into that folder and use ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.npmjs.com/"},"children":["NPM"]}," to install the latest version of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," along with the TypeScript compiler and the Node.js type definitions:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"npm install xrpl\nnpm install --save-dev typescript @types/node\n","lang":"sh"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This updates your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["package.json"]}," file, or creates a new one if it didn't already exist."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["package.json"]}," file should look something like this:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/_code-samples/get-started/ts/package.json","language":"json","header":{"controls":{"copy":{}}},"lang":"json","source":"{\n  \"name\": \"get-started-typescript\",\n  \"description\": \"Example code for the Get Started Using TypeScript tutorial.\",\n  \"dependencies\": {\n    \"xrpl\": \"^4.4.0\"\n  },\n  \"devDependencies\": {\n    \"typescript\": \"^5.5.0\",\n    \"@types/node\": \"^22.0.0\"\n  },\n  \"type\": \"module\"\n}\n"},"children":[]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"configure-ts-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"2-configure-typescript","__idx":7},"children":["2. Configure TypeScript"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["tsconfig.json"]}," file to tell the compiler how to build your project. The settings below target modern JavaScript, enable ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["strict"]}," type checking, and write the compiled output to a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["dist"]}," folder."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"file":"/_code-samples/get-started/ts/tsconfig.json","language":"json","header":{"controls":{"copy":{}}},"lang":"json","source":"{\n  \"compilerOptions\": {\n    \"target\": \"ES2020\",\n    \"module\": \"NodeNext\",\n    \"moduleResolution\": \"NodeNext\",\n    \"lib\": [\"ES2020\", \"DOM\"],\n    \"outDir\": \"dist\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true\n  },\n  \"include\": [\"*.ts\"]\n}\n"},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"3-connect-to-the-xrp-ledger","__idx":8},"children":["3. Connect to the XRP Ledger"]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"connect-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"connect-to-the-xrp-ledger-testnet","__idx":9},"children":["Connect to the XRP Ledger Testnet"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To make queries and submit transactions, you need to connect to the XRP Ledger. To do this with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]},", you create an instance of the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Client"]}]}," class and use the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#connect"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["connect()"]}]}," method. Because you import the class directly, TypeScript infers the correct type for your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"success","name":"Tip"},"children":["Many network functions in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," use ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"},"children":["Promises"]}," to return values asynchronously. The code samples here use the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["async/await"]}," pattern"]}," to wait for the actual result of the Promises."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The sample code shows you how to connect to the Testnet, which is one of the available ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/networks-and-servers/parallel-networks"},"children":["parallel networks"]},"."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"connect-mainnet-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"connect-to-the-xrp-ledger-mainnet","__idx":10},"children":["Connect to the XRP Ledger Mainnet"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When you're ready to move to production, you'll need to connect to the XRP Ledger Mainnet. You can do that in two ways:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["By ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/infrastructure/installation"},"children":["installing the core server"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpld"]},") and running a node yourself. The core server connects to the Mainnet by default, but you can ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/infrastructure/configuration/connect-your-xrpld-to-the-xrp-test-net"},"children":["change the configuration to use Testnet or Devnet"]},". ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/networks-and-servers#reasons-to-run-your-own-server"},"children":["There are good reasons to run your own core server"]},". If you run your own server, you can connect to it like so:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"const MY_SERVER = 'ws://localhost:6006/'\nconst client = new Client(MY_SERVER)\nawait client.connect()\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["See the example ",{"$$mdtype":"Tag","name":"SourceLink","attributes":{"path":"cfg/xrpld-example.cfg#L1469","name":"core server config file","xrpld_release":"release/3.2.x"},"children":[]}," for more information about default values."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["By using one of the available ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/tutorials/public-servers"},"children":["public servers"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"const PUBLIC_SERVER = 'wss://xrplcluster.com/'\nconst client = new Client(PUBLIC_SERVER)\nawait client.connect()\n","lang":"typescript"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"4-get-account","__idx":11},"children":["4. Get Account"]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"get-account-create-wallet-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"create-and-fund-a-wallet","__idx":12},"children":["Create and Fund a Wallet"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," library has a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Wallet.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Wallet"]}]}," class for handling the keys and address of an XRP Ledger account. On Testnet, you can fund a new account as shown in the example. Annotating the result with the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Wallet"]}," type lets the compiler check every property you access."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"get-account-create-wallet-b-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"optional-generate-a-wallet-only","__idx":13},"children":["(Optional) Generate a Wallet Only"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you want to generate a wallet without funding it, you can create a new ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Wallet.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Wallet"]}]}," instance. Keep in mind that you need to send XRP to the wallet for it to be a valid account on the ledger."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"get-account-create-wallet-c-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":4,"id":"optional-use-your-own-wallet-seed","__idx":14},"children":["(Optional) Use Your Own Wallet Seed"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To use an existing wallet seed encoded in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/references/protocol/data-types/base58-encodings"},"children":["base58"]},", you can create a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Wallet.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Wallet"]}]}," instance from it."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"query-xrpl-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"5-query-the-xrp-ledger","__idx":15},"children":["5. Query the XRP Ledger"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use the Client's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#request"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["request()"]}]}," method to access the XRP Ledger's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/http-websocket-apis/api-conventions/request-formatting"},"children":["WebSocket API"]},". Typing the request as an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AccountInfoRequest"]}," verifies the command name and its fields, and the library infers the matching ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AccountInfoResponse"]}," for the result so you get autocomplete on the response too."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"build-tx-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"6-build-and-validate-a-transaction","__idx":16},"children":["6. Build and Validate a Transaction"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["One of the biggest advantages of TypeScript is turning your own input into a well-formed transaction. Typing an object as a ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/protocol/transactions/types/payment"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Payment"]}]}," makes the compiler require every field and reject values of the wrong type ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["before"]}," you run the code. The ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/functions/xrpToDrops.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpToDrops()"]}]}," helper converts an XRP amount into the drops string the ledger expects, and ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/functions/validate.html"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["validate()"]}]}," runs the same structural checks the server does at runtime."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This example builds and validates the transaction without submitting it. To send it, sign and submit in one call with ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#submitAndWait"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submitAndWait()"]}]},". Before submitting real transactions, read ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/transactions/secure-signing"},"children":["Set up Secure Signing"]},"."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"listen-for-events-tag"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"7-listen-for-events","__idx":17},"children":["7. Listen for Events"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can set up handlers for various types of events in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]},", such as whenever the XRP Ledger's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/consensus-protocol"},"children":["consensus process"]}," produces a new ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/ledgers"},"children":["ledger version"]},". To do that, first call the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/docs/references/http-websocket-apis/public-api-methods/subscription-methods/subscribe"},"children":["subscribe method"]}," to get the type of events you want, then attach an event handler using the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#on"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["on(eventType, callback)"]}]}," method of the client. The callback's ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ledger"]}," argument is typed for you, so fields like ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ledger_index"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["txn_count"]}," are checked as you use them."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"disconnect-node-tag","when":{"environment":"Node"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"8-disconnect","__idx":18},"children":["8. Disconnect"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Call the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#disconnect"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["disconnect()"]}]}," function so Node.js can end the process. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"disconnect-web-tag","when":{"environment":"Web"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"8-disconnect-1","__idx":19},"children":["8. Disconnect"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Call the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/classes/Client.html#disconnect"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["disconnect()"]}]}," function to disconnect from the ledger when done. The example code waits 10 seconds before disconnecting to allow time for the ledger event listener to receive and display events."]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"run-app-node-tag","when":{"environment":"Node"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"9-compile-and-run-the-application","__idx":20},"children":["9. Compile and Run the Application"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Finally, in your terminal, compile the TypeScript to JavaScript and run the result:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"npx tsc\nnode dist/get-acct-info.js\n","lang":"sh"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You should see output similar to the following:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"Connected to Testnet\n\nCreating a new wallet and funding it with Testnet XRP...\nWallet: rKTfqsMZTPWNYWrzFjUwDNLa8XTeA45wvB\nBalance: 100\nAccount Testnet Explorer URL:\n  https://testnet.xrpl.org/accounts/rKTfqsMZTPWNYWrzFjUwDNLa8XTeA45wvB\n\nGetting account info...\n{\n  \"api_version\": 2,\n  \"id\": 4,\n  \"result\": {\n    \"account_data\": {\n      \"Account\": \"rKTfqsMZTPWNYWrzFjUwDNLa8XTeA45wvB\",\n      \"Balance\": \"100000000\",\n      \"Flags\": 0,\n      \"LedgerEntryType\": \"AccountRoot\",\n      \"OwnerCount\": 0,\n      \"PreviousTxnID\": \"C791975AB1FA811DD7C2A958F71629C3EB830545B25C11F488249D0AEADAA04C\",\n      \"PreviousTxnLgrSeq\": 18910118,\n      \"Sequence\": 18910118,\n      \"index\": \"0553BF36D48179C15297E1087002B6D33E076D71CAFEA7F0BB1362B9502C851D\"\n    },\n    \"ledger_hash\": \"CC057AE6CF43485107EA0E4184DE48D73DC4C8A742577964462AB49EDA8EC84E\",\n    \"ledger_index\": 18910118,\n    \"validated\": true\n  },\n  \"type\": \"response\"\n}\n\nBuilt and validated a Payment transaction:\n{\n  \"TransactionType\": \"Payment\",\n  \"Account\": \"rKTfqsMZTPWNYWrzFjUwDNLa8XTeA45wvB\",\n  \"Amount\": \"22000000\",\n  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"\n}\n\nListening for ledger close events...\nLedger #18910119 validated with 0 transactions!\nLedger #18910120 validated with 1 transactions!\nLedger #18910121 validated with 1 transactions!\n\nDisconnected\n","lang":"sh"},"children":[]}]},{"$$mdtype":"Tag","name":"CodeStep","attributes":{"id":"run-app-web-tag","when":{"environment":"Web"}},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"9-compile-and-run-the-application-1","__idx":21},"children":["9. Compile and Run the Application"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Compile the TypeScript to JavaScript, then open the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["index.html"]}," file in a web browser:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sh","header":{"controls":{"copy":{}}},"source":"npx tsc\n","lang":"sh"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You should see output similar to the following:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"Connected to Testnet\nCreating a new wallet and funding it with Testnet XRP...\nWallet: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\nBalance: 100\nView account on XRPL Testnet Explorer: rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\n\nGetting account info...\n{\n  \"api_version\": 2,\n  \"id\": 5,\n  \"result\": {\n    \"account_data\": {\n      \"Account\": \"rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\",\n      \"Balance\": \"100000000\",\n      \"Flags\": 0,\n      \"LedgerEntryType\": \"AccountRoot\",\n      \"OwnerCount\": 0,\n      \"PreviousTxnID\": \"96E4B44F93EC0399B7ADD75489630C6A8DCFC922F20F6810D25490CC0D3AA12E\",\n      \"PreviousTxnLgrSeq\": 9949610,\n      \"Sequence\": 9949610,\n      \"index\": \"B5D2865DD4BF8EEDFEE2FD95DE37FC28D624548E9BBC42F9FBF61B618E98FAC8\"\n    },\n    \"ledger_hash\": \"7692673B8091899C3EEE6807F66B65851D3563F483A49A5F03A83608658473D6\",\n    \"ledger_index\": 9949610,\n    \"validated\": true\n  },\n  \"type\": \"response\"\n}\n\nBuilt and validated a Payment transaction:\n{\n  \"TransactionType\": \"Payment\",\n  \"Account\": \"rf7CWJdNssSzQk2GtypYLVhyvGe8oHS3S\",\n  \"Amount\": \"22000000\",\n  \"Destination\": \"rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe\"\n}\n\nListening for ledger close events...\nLedger #9949611 validated with 0 transactions\nLedger #9949612 validated with 1 transactions\nLedger #9949613 validated with 0 transactions\n\nDisconnected\n","lang":"text"},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"see-also","__idx":22},"children":["See Also"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Concepts:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/about/"},"children":["XRP Ledger Overview"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/client-libraries"},"children":["Client Libraries"]}]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Tutorials:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/tutorials/get-started/get-started-javascript"},"children":["Get Started Using JavaScript"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/tutorials/payments/send-xrp"},"children":["Send XRP"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/tutorials/tokens/fungible-tokens/issue-a-fungible-token"},"children":["Issue a Fungible Token"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/concepts/transactions/secure-signing"},"children":["Set up Secure Signing"]}]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["References:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://js.xrpl.org/"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["xrpl.js"]}," Reference"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/http-websocket-apis/public-api-methods"},"children":["Public API Methods"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/http-websocket-apis/api-conventions"},"children":["API Conventions"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/protocol/data-types/base58-encodings"},"children":["base58 Encodings"]}]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/docs/references/protocol/transactions"},"children":["Transaction Formats"]}]}]}]}]}]}]},"headings":[{"value":"Get Started Using TypeScript Library","id":"get-started-using-typescript-library","depth":1},{"value":"Goals","id":"goals","depth":2},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Source Code","id":"source-code","depth":2},{"value":"Steps","id":"steps","depth":2},{"value":"1. Install Dependencies","id":"1-install-dependencies","depth":3},{"value":"1. Install Dependencies","id":"1-install-dependencies-1","depth":3},{"value":"2. Configure TypeScript","id":"2-configure-typescript","depth":3},{"value":"3. Connect to the XRP Ledger","id":"3-connect-to-the-xrp-ledger","depth":3},{"value":"Connect to the XRP Ledger Testnet","id":"connect-to-the-xrp-ledger-testnet","depth":4},{"value":"Connect to the XRP Ledger Mainnet","id":"connect-to-the-xrp-ledger-mainnet","depth":4},{"value":"4. Get Account","id":"4-get-account","depth":3},{"value":"Create and Fund a Wallet","id":"create-and-fund-a-wallet","depth":4},{"value":"(Optional) Generate a Wallet Only","id":"optional-generate-a-wallet-only","depth":4},{"value":"(Optional) Use Your Own Wallet Seed","id":"optional-use-your-own-wallet-seed","depth":4},{"value":"5. Query the XRP Ledger","id":"5-query-the-xrp-ledger","depth":3},{"value":"6. Build and Validate a Transaction","id":"6-build-and-validate-a-transaction","depth":3},{"value":"7. Listen for Events","id":"7-listen-for-events","depth":3},{"value":"8. Disconnect","id":"8-disconnect","depth":3},{"value":"8. Disconnect","id":"8-disconnect-1","depth":3},{"value":"9. Compile and Run the Application","id":"9-compile-and-run-the-application","depth":3},{"value":"9. Compile and Run the Application","id":"9-compile-and-run-the-application-1","depth":3},{"value":"See Also","id":"see-also","depth":2}],"frontmatter":{"seo":{"description":"Build an entry-level TypeScript application for querying the XRP Ledger.","title":"Get Started Using TypeScript Library"},"top_nav_name":"TypeScript","top_nav_grouping":"Get Started","labels":["Development"],"showcase_icon":"assets/img/logos/typescript.svg","markdown":{"toc":{"hide":true}},"footer":{"hide":true}},"editPage":{"to":"https://github.com/XRPLF/xrpl-dev-portal/tree/master/docs/tutorials/get-started/get-started-typescript.md"},"lastModified":"2026-07-10T19:15:14.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/docs/tutorials/get-started/get-started-typescript","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}