Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) => {
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) => {
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);
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=' +
constructor() {
this.zilliqa = new Zilliqa(PROVIDER)
this.contract = this.zilliqa.contracts.at(UD_CONTRACT_ADDRESS)
}
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,
constructor() {
this.zilliqa = new Zilliqa(PROVIDER);
this.contract = this.zilliqa.contracts.at(UD_CONTRACT_ADDRESS);
}
* 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,