Skip to content

Instantly share code, notes, and snippets.

@shortthefomo
Last active May 4, 2024 16:20
Show Gist options
  • Save shortthefomo/4f47d90200f87dc503e3f3f04494b918 to your computer and use it in GitHub Desktop.
Save shortthefomo/4f47d90200f87dc503e3f3f04494b918 to your computer and use it in GitHub Desktop.
Fetch USD price XRPL - DEVNET THREE ORACLE
const { XrplClient } = require('xrpl-client')
const xrpl = new XrplClient(['wss://s.devnet.rippletest.net:51233'])
// change this code to a different currency code one of others published, EUR/ZAR/MXN/JPY/BTC/USDT......
let code = 'USD'
if (code.length > 3) {
const characters = Buffer.from(code, 'utf8').toString('hex')
let s = '0'
for (let index = 1; index < 40 - characters.length; index++) {
s = s + '0'
}
code = (characters + s).toUpperCase()
}
const command = {
'command': 'get_aggregate_price',
'ledger_index': 'current',
'base_asset': 'XRP',
'quote_asset': code,
'trim': 20,
'oracles': [
{
'account': 'rMS69A6J39RmBg5yWDft5XAM8zTGbtMMZy',
'oracle_document_id': 1
},
{
'account': 'rMS69A6J39RmBg5yWDft5XAM8zTGbtMMZy',
'oracle_document_id': 2
},
{
'account': 'rMS69A6J39RmBg5yWDft5XAM8zTGbtMMZy',
'oracle_document_id': 3
},
{
'account': 'rMS69A6J39RmBg5yWDft5XAM8zTGbtMMZy',
'oracle_document_id': 4
},
{
'account': 'rMS69A6J39RmBg5yWDft5XAM8zTGbtMMZy',
'oracle_document_id': 5
}
]
}
const response = await xrpl.send(command)
if ('error' in response) { return }
console.log(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment