How to use @zilliqa-js/zilliqa - 8 common examples

To help you get started, we’ve selected a few @zilliqa-js/zilliqa 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 Zilliqa / Zilliqa-JavaScript-Library / examples / newEventLogSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildEventLogSubscriptions(
    'ws://',
    {
      addresses: [
        '0x2ce491a0fd9e318b39172258101b7c836da7449b',
        '0x167e3980e04eab1e89ff84523ae8c77e008932dc',
      ],
    },
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_EVENT_LOG, (event) => {
    console.log('get SubscribeEventLog echo: ', event);
  });
  subscriber.emitter.on(MessageType.EVENT_LOG, (event) => {
    console.log('get new event log: ', JSON.stringify(event));
  });
  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
github Zilliqa / Zilliqa-JavaScript-Library / examples / newTxBlockSubscriptions.js View on Github external
async function test() {
  // first run `python websocket.py` to start websocket server locally
  const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');
  const subscriber = zilliqa.subscriptionBuilder.buildNewBlockSubscriptions(
    'ws://',
  );
  subscriber.emitter.on(StatusType.SUBSCRIBE_NEW_BLOCK, (event) => {
    console.log('get SubscribeNewBlock echo: ', event);
  });

  subscriber.emitter.on(MessageType.NEW_BLOCK, (event) => {
    console.log('get new block: ', event.value.TxBlock.header);
  });

  subscriber.emitter.on(MessageType.UNSUBSCRIBE, (event) => {
    console.log('get unsubscribe event: ', event);
  });

  subscriber.emitter.on(SocketConnect.CLOSE, (event) => {
github Zilliqa / Zilliqa-JavaScript-Library / examples / helloWord.js View on Github external
const { BN, Long, bytes, units } = require('@zilliqa-js/util');
const { Zilliqa } = require('@zilliqa-js/zilliqa');
const {
  toBech32Address,
  getAddressFromPrivateKey,
} = require('@zilliqa-js/crypto');

const zilliqa = new Zilliqa('https://dev-api.zilliqa.com');

// These are set by the core protocol, and may vary per-chain.
// You can manually pack the bytes according to chain id and msg version.
// For more information: https://apidocs.zilliqa.com/?shell#getnetworkid

const chainId = 333; // chainId of the developer testnet
const msgVersion = 1; // current msgVersion
const VERSION = bytes.pack(chainId, msgVersion);

// Populate the wallet with an account
const privateKey =
  '3375F915F3F9AE35E6B301B7670F53AD1A5BE15D8221EC7FD5E503F21D3450C8';

zilliqa.wallet.addByPrivateKey(privateKey);

const address = getAddressFromPrivateKey(privateKey);
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 +
      '&remoteip=' +
github zilpay / zil-pay / packages / background / services / ud / ud.js View on Github external
constructor() {
    this.zilliqa = new Zilliqa(PROVIDER)
    this.contract = this.zilliqa.contracts.at(UD_CONTRACT_ADDRESS)
  }
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,
  publicKey: undefined,
github zilpay / zil-pay / extension / controllers / services / ud / ud.js View on Github external
constructor() {
    this.zilliqa = new Zilliqa(PROVIDER);
    this.contract = this.zilliqa.contracts.at(UD_CONTRACT_ADDRESS);
  }
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 {
        ...state,

@zilliqa-js/zilliqa

Main entry point to the Zilliqa JS client.

GPL-3.0
Latest version published 4 months ago

Package Health Score

69 / 100
Full package analysis

Popular @zilliqa-js/zilliqa functions

Similar packages