How to use the @cityofzion/neon-js.rpc.RPCClient 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 / neon-wallet / app / actions / nodeStorageActions.js View on Github external
.map(data => {
        const url = buildNodeUrl(data)
        const client = new rpc.RPCClient(url)
        // eslint-disable-next-line
        data.client = client
        return data
      })
github CityOfZion / neon-js / examples / basic / multi.js View on Github external
.then(transaction => {
    const client = new rpc.RPCClient(rpcNodeUrl);
    return client.sendRawTransaction(transaction.serialize(true));
  })
  .then(res => {
github nos / client / src / renderer / shared / util / getBalances.js View on Github external
async function getAssetBalances(endpoint, address) {
  const client = new rpc.RPCClient(endpoint);
  const { balances } = await client.getAccountState(address);

  const neoBalance = get(find(balances, { asset: `0x${NEO}` }), 'value', '0');
  const gasBalance = get(find(balances, { asset: `0x${GAS}` }), 'value', '0');

  return {
    [NEO]: { ...ASSETS[NEO], scriptHash: NEO, balance: neoBalance },
    [GAS]: { ...ASSETS[GAS], scriptHash: GAS, balance: gasBalance }
  };
}
github CityOfZion / neon-wallet / app / components / Modals / ImportTransactionModal / ImportTransactionModal.jsx View on Github external
handleBroadcast = async (rawTransaction: string) => {
    this.setState({ loading: true })
    const { net } = this.props
    let url = await getNode(net)
    if (isEmpty(url)) {
      url = await getRPCEndpoint(net)
    }
    const RPC = new rpc.RPCClient(url)
    const response = await RPC.sendRawTransaction(rawTransaction).catch(e => {
      this.props.showErrorNotification({
        message: `There was an issue broadcasting the transaction to the network... ${
          e.message
        }`,
      })
      this.setState({ loading: false })
    })
    if (response) {
      this.props.showSuccessNotification({
        message:
          'Transaction pending! Wallet balances will automatically update when the blockchain has processed it.',
      })
      this.setState({ loading: false })
      this.props.hideModal()
    }
github nos / client / src / common / util / getRPCEndpoint.js View on Github external
const goodNodes = nodes.filter((n) => !isUnreliableNode(n.url, blacklist));

  if (goodNodes.length === 0) {
    throw new Error('No eligible nodes found!');
  }

  const heightThreshold = goodNodes[0].height - 1;
  const highestNodes = goodNodes.filter((n) => n.height >= heightThreshold);
  const urls = highestNodes.map((n) => n.url);

  if (urls.length === 0) {
    throw new Error('No eligible nodes found!');
  }

  if (urls.includes(cachedRPC)) {
    return new rpc.RPCClient(cachedRPC).ping().then((num) => {
      if (num <= settings.timeout.ping) return cachedRPC;
      cachedRPC = null;
      return getRPCEndpoint(net);
    });
  }

  const clients = urls.map((u) => new rpc.RPCClient(u));

  const fastestUrl = await raceToSuccess(clients.map((c) => c.ping().then(() => c.net)));
  cachedRPC = fastestUrl;
  return fastestUrl;
}
github CityOfZion / neon-wallet / app / actions / voteActions.js View on Github external
({ networkId, address }: Props = {}) => async (state: Object) => {
    const net = getNetworkById(networkId)
    const endpoint = await api.getRPCEndpointFrom({ net }, api.neoscan)
    const client = new rpc.RPCClient(endpoint)

    const validators = await client.getValidators()
    const accountState = await client.getAccountState(address)

    return {
      validators,
      votes: accountState.votes,
    }
  },
)
github nos / client / src / main / util / resolve.js View on Github external
async function resolveNameService(url) {
  const { host, pathname } = url;

  const endpoint = await getRPCEndpoint(NOS_TESTNET);
  const client = new rpc.RPCClient(endpoint);
  const storageKey = u.str2hexstring(`${host}.target`);
  const response = await client.getStorage(NS_SCRIPT_HASH, storageKey);

  if (!response) {
    throw new Error('Not found.');
  }

  const target = u.hexstring2str(response);

  return `${target}${pathname}`;
}
github CityOfZion / neon-wallet / app / actions / nodeNetworkActions.js View on Github external
new Promise(resolve => {
    const client = new rpc.RPCClient(url)
    client.ping().then(latency => {
      if (client.lastSeenHeight !== 0) {
        resolve({
          url,
          blockCount: client.lastSeenHeight,
          latency,
        })
      }
    })
  })
github nos / client / src / common / util / getRPCEndpoint.js View on Github external
  const clients = urls.map((u) => new rpc.RPCClient(u));
github nos / client / src / renderer / shared / actions / blockActions.js View on Github external
export default createActions(ID, ({ net }) => async () => {
  const endpoint = await getRPCEndpoint(net);
  const client = new rpc.RPCClient(endpoint);
  const height = await client.getBlockCount();
  return client.getBlock(height - 1);
});