Check XRP account address validity

node v10.24.1
version: 4.0.0
endpointsharetweet
const xcodec = require('xrpl-tagged-address-codec') const rcodec = require('ripple-address-codec') const assert = require('assert') const xrplClient = require('rippled-ws-client') /* Locally, check account checksum */ const addressValid = address => { assert(typeof address === 'string', 'Invalid account address, should be string') const accountAddress = address.trim() if (accountAddress.match(/^X/)) { return (() => { try { const decoded = xcodec.Decode(accountAddress) return true } catch (e) { return false } })() } else { return rcodec.isValidAddress(accountAddress) } } /* Server side, check account activation */ const addressActivated = async address => { return new Promise((resolve, reject) => { const client = new xrplClient('wss://rippled.xrptipbot.com') client.then(connection => { connection.send({ command: 'account_info', account: address }).then(response => { if (typeof response.account_data !== 'undefined') { return resolve(response.account_data) } else { resolve(false) } connection.close() }) }).catch(reject) }) } [ 'r39wNbXPK25UJPfQiqkeeh2BRSceYHUo2C', 'XV5sbjUmgPpvXv4ixFWZ5ptAYZ6PD28Sq49uo34VyjnmK5H', 'XV5sbjUixFWZ5ptAYZ6PD28Sq49uomgPpvXv434VyjnmK5H' ].forEach(address => { console.log(`Address [ ${address} ] valid? ${addressValid(address) ? 'YES' : 'NO'}`) }); [ 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY', 'r39wNbXPK25UJPfQiqkeeh2BRSceYHUo2C' ].forEach(address => { addressActivated(address).then(activated => { console.log(`Account [ ${address} ] activated? ${activated ? 'YES' : 'NO'}`) }) });
Loading…

no comments

    sign in to comment