Get started: consolidate, start updating Node.js

This commit is contained in:
mDuo13
2021-10-05 17:22:15 -07:00
parent d04a12fc0d
commit 6fc9afbd7e
12 changed files with 141 additions and 591 deletions

View File

@@ -0,0 +1,39 @@
// 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 test_wallet = new xrpl.Wallet() // TODO: change to define based on fundWallet result
const fund_result = await client.fundWallet(test_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()