Files
xrpl-dev-portal/content/_code-samples/get-started/js/get-acct-info.js
Jyri Hovila 6cab63408e Update get-acct-info.js
The call to initiate a new wallet (through fundWallet) must not include parameters.
The previous version of the code gives error: ReferenceError: Cannot access 'test_wallet' before initialization
2021-11-14 20:22:47 +02:00

40 lines
1.1 KiB
JavaScript

// Import the library
const xrpl = require("xrpl")
// Wrap code in an async function so we can use await
async function main() {
// Define the network client
const SERVER_URL = "https://s.altnet.rippletest.net:51234/"
const client = new xrpl.Client(SERVER_URL)
await client.connect()
// 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)
// Get info from the ledger about the address we just funded
const response = await client.request({
"command": "account_info",
"account": test_wallet.address,
"ledger_index": "validated"
})
console.log(response)
// Listen to ledger close events
client.request({
"command": "subscribe",
"streams": ["ledger"]
})
client.on("ledgerClosed", async (ledger) => {
console.log(`Ledger #${ledger.ledger_index} validated with ${ledger.txn_count} transactions!`)
})
// Disconnect when done so Node.js can end the process
client.disconnect()
}
// call the async function
main()