How to use the @cityofzion/neon-js.rpc function in @cityofzion/neon-js

To help you get started, we’ve selected a few @cityofzion/neon-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CityOfZion / neo-js / examples / regression-test / validate-block.js View on Github external
dataAccessOptions: {
        connectOnInit: true,
        connectionString: DB_CONNECTION_STRING,
        collectionNames: {
          blocks: 'b_neo_t_blocks',
          transactions: 'b_neo_t_transactions',
          addresses: 'b_neo_t_addresses'
        }
      }
    }
  }
  const neo = new Neo(options)

  // Instantiate RPC via NeonJS
  const url = 'http://seed2.neo.org:20332'
  const rpc = Neon.rpc.default.create.rpcClient(url)

  // Keep looking and cherrypick blocks, and examine them
  setInterval(async () => {
    // Fetch local node height
    const localBlockHeight = await neo.storage.getBlockCount()

    // Generate random number in between
    const randomHeight = parseInt(Math.random() * localBlockHeight)
    // logger.info('localBlockHeight:', localBlockHeight, 'randomHeight:', randomHeight)

    // Fetch block from local node
    const localBlock = await neo.storage.getBlock(randomHeight)
    // logger.info('localBlock:', localBlock.hash)

    // Fetch block from remote node via NodeJs
    const remoteBlock = await rpc.getBlock(randomHeight)
github deanpress / neo-dapp-starter-kit / backend / blockchain.js View on Github external
return module.exports.getRPCEndpoint().then(rpcEndpoint => {
            return neon.rpc.Query.invokeScript(vmScript)
                .execute(rpcEndpoint)
                .then((res) => {
                    if (res.result.state === 'HALT, BREAK') {
                        //Execute the transaction
                        module.exports.executeTransaction(account, invoke, gasCost, intents).then(res => {
                            if (res !== undefined)
                                callback(res)
                            else
                                return
                        })
                    } else {
                        console.log('Error:', res)
                    }
                })
        })
    }
github CityOfZion / neo-js / dist / node / rpc.js View on Github external
const EventEmitter = require('events')
const axios = require('axios')
const Neon = require('@cityofzion/neon-js')
const Query = Neon.rpc.Query
const Logger = require('../common/logger')

/**
 * @class Rpc
 * @param {string} domain
 * @param {string} port
 * @param {Object} options
 * @param {Object} options.loggerOptions
 */
class Rpc extends EventEmitter {
  /**
   * @fires Rpc#constructor:complete
   */
  constructor (domain, port, options) {
    super()
github CityOfZion / neo-js / dist / node / rpc.js View on Github external
initNeonRpc () {
    this.neonRpc = Neon.rpc.default.create.rpcClient(this.getRpcUrl())
  }
github CityOfZion / neo-js / dist / delegates / rpc-delegate.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            rpc_validator_1.RpcValidator.validateUrl(url);
            rpc_validator_1.RpcValidator.validateMethod(method);
            rpc_validator_1.RpcValidator.validateId(id);
            const q = new neon_js_1.rpc.Query({ method, params, id });
            return yield q.execute(url, requestConfig);
        });
    }
github deanpress / neo-dapp-starter-kit / backend / blockchain.js View on Github external
return module.exports.getRPCEndpoint().then(rpcEndpoint => {
            return neon.rpc.queryRPC(rpcEndpoint, {
                method: method,
                params: params,
                id: id
            }).then(res => {
                return res
            }).catch(err => {
                return err
            })
        })
    },