How to use the @liskhq/lisk-client.APIClient function in @liskhq/lisk-client

To help you get started, we’ve selected a few @liskhq/lisk-client 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 LiskHQ / lisk-mobile / src / actions / peers.js View on Github external
(dispatch) => {
    const { network, serverAddress } = getNetwork(env);
    const config = { nethash: 'net' };
    if (network === 'customNode') {
      config.nodes = [serverAddress];
      const liskAPIClient = new Lisk.APIClient(config.nodes, { nethash: config.nethash });
      // loadingStarted('getConstants');
      liskAPIClient.node.getConstants().then((response) => {
        // loadingFinished('getConstants');
        config.nethash = response.data.nethash;
        dispatch(peerSet(config));
      }).catch(() => {
        // loadingFinished('getConstants');
        // dispatch(errorToastDisplayed({ label: i18next.t('Unable to connect to the node') }));
      });
    } else if (network === 'testnet') {
      config.nodes = Lisk.APIClient.constants.TESTNET_NODES;
      config.nethash = Lisk.APIClient.constants.TESTNET_NETHASH;
      dispatch(peerSet(config));
    } else if (network === 'mainnet') {
      config.nodes = Lisk.APIClient.constants.MAINNET_NODES;
      config.nethash = Lisk.APIClient.constants.MAINNET_NETHASH;
github LiskHQ / lisk-desktop / src / actions / peers.js View on Github external
config.nodes = [config.address];
    } else if (config.testnet) {
      config.nethash = Lisk.APIClient.constants.TESTNET_NETHASH;
      config.nodes = networks.testnet.nodes;
    } else {
      config.nethash = Lisk.APIClient.constants.MAINNET_NETHASH;
      config.nodes = networks.mainnet.nodes;
    }
    // TODO calling token-agnostic action inside LSK action is hacky, should be refactored
    dispatch(networkSet({
      ...data.network,
      nodeUrl: data.network.address,
    }));

    if (config.custom) {
      const liskAPIClient = new Lisk.APIClient(config.nodes, {});
      loadingStarted('getConstants');
      liskAPIClient.node.getConstants().then((response) => {
        dispatch(loadingFinished('getConstants'));
        config.nethash = response.data.nethash;
        dispatch(peerSet(data, config));
        if (data.passphrase || data.hwInfo) {
          login(data, config)(dispatch, getState);
        }
      }).catch((error) => {
        dispatch(loadingFinished('getConstants'));
        dispatch(errorToastDisplayed({
          label: getConnectionErrorMessage(error),
        }));
      });
    } else {
      dispatch(peerSet(data, config));
github LiskHQ / lisk-desktop / src / utils / api / lsk / network.js View on Github external
if (network.name && (!apiClients[network.name] || network.name === networks.customNode.name)) {
    const { nethash, nodes } = {
      [networks.testnet.name]: {
        nethash: Lisk.APIClient.constants.TESTNET_NETHASH,
        nodes: networks.testnet.nodes,
      },
      [networks.mainnet.name]: {
        nethash: Lisk.APIClient.constants.MAINNET_NETHASH,
        nodes: networks.mainnet.nodes,
      },
      [networks.customNode.name]: {
        nethash: network.networks[tokenMap.LSK.key] && network.networks[tokenMap.LSK.key].nethash,
        nodes: [network.networks[tokenMap.LSK.key] && network.networks[tokenMap.LSK.key].nodeUrl],
      },
    }[network.name] || {};
    apiClients[network.name] = new Lisk.APIClient(nodes, { nethash });
    apiClients[network.name].networkConfig = network;
  }
  return apiClients[network.name];
};
github LiskHQ / lisk-desktop / src / components / shared / header / signInHeader / signInHeader.js View on Github external
validateCorrectNode(network, address, nextPath) {
    const nodeURL = address !== '' ? addHttp(address) : '';
    const newNetwork = this.getNetwork(network);

    if (network === networks.customNode.code) {
      const liskAPIClient = new Lisk.APIClient([nodeURL], {});
      liskAPIClient.node.getConstants()
        .then((res) => {
          if (res.data) {
            this.props.networkSet({
              name: newNetwork.name,
              network: {
                ...newNetwork,
              },
            });

            this.props.history.push(nextPath);
            this.setState({ validationError: '', connected: true });
            this.childRef.toggleDropdown();
            this.changeNetwork(networks.customNode.code);
          } else {
            throw new Error();
github LiskHQ / lisk-mobile / src / actions / peers.js View on Github external
const peerSet = config => ({
  data: new Lisk.APIClient(config.nodes, { nethash: config.nethash }),
  type: actionTypes.activePeerSet,
});
github LiskHQ / lisk-desktop / src / actions / peers.js View on Github external
const peerSet = (data, config) => ({
  data: {
    passphrase: data.passphrase,
    publicKey: data.publicKey,
    liskAPIClient: new Lisk.APIClient(config.nodes, { nethash: config.nethash }),
    options: config,
    loginType: data.loginType,
  },
  type: actionTypes.liskAPIClientSet,
});
github LiskHQ / lisk-desktop / src / actions / network / lsk.js View on Github external
new Promise(async (resolve, reject) => {
    new Lisk.APIClient([nodeUrl], {}).node.getConstants().then((response) => {
      resolve(response.data.nethash);
    }).catch((error) => {
      reject(getConnectionErrorMessage(error));
    });
  })
);