🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more
Socket
Book a DemoInstallSign in
Socket

@bandprotocol/bandchain.js

Package Overview
Dependencies
Maintainers
3
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bandprotocol/bandchain.js

Library for interacting with BandChain in browser and Node.js environments

Source
npmnpm
Version
1.0.24
Version published
Weekly downloads
47
-33.8%
Maintainers
3
Weekly downloads
 
Created
Source

BandChain.js

Library for interacting with BandChain in browser and Node.js environments

⭐️ Features

  • Requesting Data from BandChain
  • Reading Data Request Status from BandChain

📦 Installation

npm install --save @bandprotocol/bandchain.js

Use in Node.js

const BandChain = require('@bandprotocol/bandchain.js')

const endpoint = 'http://guanyu-devnet.bandchain.org/rest'

const bandchain = new BandChain(endpoint)
...

🔍 Test

npm run test

💎 Example Usages

const BandChain = require('@bandprotocol/bandchain.js')
const endpoint = 'http://guanyu-devnet.bandchain.org/rest'

// Instantiating BandChain with REST endpoint
const bandchain = new BandChain(endpoint)

// Create an instance of OracleScript with the script ID
const oracleScript = await bandchain.getOracleScript(1)

// Get script info
const schema = oracleScript.schema
const description = oracleScript.description

// Read latest script result
const result = await bandchain.getLatestRequestResult(oracleScript, {
  symbol: 'BTC',
  multiplier: 10000,
})

// Create a new request, which will block into the tx is confirmed
try {
  const minCount = 5
  const askCount = 7
  const mnemonic =
    'dumb spot lyrics car infant round rate famous inhale tennis text current'
  const requestId = await bandchain.submitRequestTx(
    oracleScript,
    { symbol: 'BTC', multiplier: 10000 },
    { minCount, askCount },
    mnemonic,
  )

  // Get request proof
  const requestProof = await bandchain.getRequestProof(requestID)
  // Get final result (blocking until the reports & aggregations are finished)
  const finalResult = await bandchain.getRequestResult(requestID)
  // Get the result of the most recent request that match the specified parameters
  const minCount = 2
  const askCount = 4
  const inputParameters = { symbol: 'BTC', multiplier: BigInt('1000000000') }
  const lastMatchResult = await bandchain.getLastMatchingRequestResult(
    oracleScript,
    inputParameters,
    { minCount, askCount },
  )
} catch {
  // Something went wrong
  console.error('Data request failed')
}

Keywords

oracle

FAQs

Package last updated on 20 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts