How to use the @zilliqa-js/core.HTTPProvider function in @zilliqa-js/core

To help you get started, we’ve selected a few @zilliqa-js/core 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 zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
reject('User denied access!');
          result.unsubscribe();
        }
        // Close stream by time.
        setTimeout(() => {
          result.unsubscribe();
          reject(new Error('waiting time may have problems ZilPay'));
        }, 15000);
      });
    });
  }

}


window.zilPay = new ZilPay(new HTTPProvider(PROVIDER));

if (typeof window.Zilliqa !== 'undefined') {
  console.error('window.Zilliqa already exists');
}

window.Zilliqa = Zilliqa;


export default function run() {
  // Create instance in page. //
  
  const type = MTypesSecure.PAY_OBJECT_INIT;
  const recipient = MTypesSecure.CONTENT;

  observableStream(
    MTypesSecure.INJECTED,
github Zilliqa / nucleus-wallet / functions / src / index.ts View on Github external
const RECAPTCHA_SECRET = functions.config().faucet.recaptcha_secret;
const PRIVATE_KEY = functions.config().faucet.private_key;
const PUBLIC_KEY = getPubKeyFromPrivateKey(PRIVATE_KEY);
const ADDRESS = getAddressFromPrivateKey(PRIVATE_KEY);

const CHAIN_ID: number =
  process.env.REACT_APP_CHAIN_ID !== undefined ? parseInt(process.env.REACT_APP_CHAIN_ID, 10) : 0;
const MSG_VERSION: number =
  process.env.REACT_APP_MSG_VERSION !== undefined
    ? parseInt(process.env.REACT_APP_MSG_VERSION, 10)
    : 0;
const VERSION = bytes.pack(CHAIN_ID, MSG_VERSION);
const NODE_URL: string = process.env.REACT_APP_NODE_URL || '';

const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);

zilliqa.wallet.addByPrivateKey(PRIVATE_KEY);

app.post('/run', async (req, res) => {
  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  console.log(`IP address: ${ip}`);
  console.log(`${NODE_URL}, ${CHAIN_ID}, ${MSG_VERSION}`);

  const { token, address } = req.body;
  try {
    const verificationUrl =
      'https://www.google.com/recaptcha/api/siteverify?secret=' +
      RECAPTCHA_SECRET +
      '&response=' +
      token +
github Zilliqa / nucleus-wallet / src / redux / zil / reducer.ts View on Github external
*
 * nucleus-wallet is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * nucleus-wallet.  If not, see .
 */

import { Zilliqa } from '@zilliqa-js/zilliqa';
import { HTTPProvider } from '@zilliqa-js/core';

import * as consts from './actions';
import { requestStatus, NODE_URL, NETWORK } from '../../constants';

const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);

const initialState: any = { zilliqa, provider, network: NETWORK };

export default function zil(state = initialState, action) {
  switch (action.type) {
    case consts.ACCESS_WALLET:
      return {
        ...state,
        address: undefined,
        publicKey: undefined,
        privateKey: undefined,
        authStatus: requestStatus.PENDING
      };
    case consts.ACCESS_WALLET_SUCCEEDED:
      return {
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
constructor(node=PROVIDER, provider=new HTTPProvider(PROVIDER)) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = window.zilPay;
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.utils = zilUtils;
    this.crypto = {
      decodeBase58, encodeBase58,
      fromBech32Address, toBech32Address,
      isValidChecksumAddress, toChecksumAddress
    }
  }
}
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa / src / index.ts View on Github external
constructor(node: string, websocket: string, provider?: Provider) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = new Wallet(this.provider);
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.network = new Network(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.newTxBlockSubscription = new NewTxBlockSubscription(websocket);
  }
}
github Zilliqa / nucleus-wallet / src / contexts / zil-context / index.tsx View on Github external
*/

import React from 'react';
import {
  getAddressFromPrivateKey,
  getPubKeyFromPrivateKey,
  fromBech32Address
} from '@zilliqa-js/crypto';
import { Long, bytes, units, BN } from '@zilliqa-js/util';
import { Transaction } from '@zilliqa-js/account';

import { Zilliqa } from '@zilliqa-js/zilliqa';
import { HTTPProvider, RPCMethod } from '@zilliqa-js/core';
import { NODE_URL, CHAIN_ID, MSG_VERSION } from '../../constants';

const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);
const version = bytes.pack(CHAIN_ID, MSG_VERSION);

const getHost = (host: string) => {
  switch (host) {
    default:
      return 'https://us-central1-nucleus-wallet.cloudfunctions.net';
  }
};

const isOk = (code) => code < 400;

const initialState: any = {
  wallet: zilliqa.wallet,
  isAuth: undefined,
  address: undefined,
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
setProvider(provider) {
    if (!provider || typeof provider !== 'string') {
      return null;
    }
    this.provider = new HTTPProvider(provider);
  }
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
  constructor(node=PROVIDER, provider=new HTTPProvider(PROVIDER)) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = window.zilPay;
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.utils = zilUtils;
    this.crypto = {
      decodeBase58, encodeBase58,
      fromBech32Address, toBech32Address,
      isValidChecksumAddress, toChecksumAddress
    }
  }
}