How to use web3-core-helpers - 10 common examples

To help you get started, we’ve selected a few web3-core-helpers 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 ubiq / shokku / test / jsonrpc.e2e-spec.ts View on Github external
async setupBlockchain() {
    // Connect to Ganache
    const domain = `${process.env.API_TESTS_GANACHE_HOST}:${process.env.API_TESTS_GANACHE_PORT}`
    this.web3 = new Web3(new Web3.providers.HttpProvider(domain))

    const accounts = this.opts.accounts

    // Generate fake transactions of money to create at least three blocks
    const tx1 = {
      from: accounts[0].address,
      to: accounts[1].address,
      value: formatters.toWei('1', 'ether')
    }
    await this.web3.eth.sendTransaction(tx1).catch(e => e)

    const tx2 = {
      from: accounts[2].address,
      to: accounts[1].address,
      value: formatters.toWei('50', 'ether')
    }
    await this.web3.eth.sendTransaction(tx2).catch(e => e)

    const tx3 = {
      from: accounts[2].address,
      to: accounts[0].address,
      value: formatters.toWei('200', 'ether')
    }
    await this.web3.eth.sendTransaction(tx3).catch(e => e)
github ubiq / shokku / test / jsonrpc.e2e-spec.ts View on Github external
this.web3 = new Web3(new Web3.providers.HttpProvider(domain))

    const accounts = this.opts.accounts

    // Generate fake transactions of money to create at least three blocks
    const tx1 = {
      from: accounts[0].address,
      to: accounts[1].address,
      value: formatters.toWei('1', 'ether')
    }
    await this.web3.eth.sendTransaction(tx1).catch(e => e)

    const tx2 = {
      from: accounts[2].address,
      to: accounts[1].address,
      value: formatters.toWei('50', 'ether')
    }
    await this.web3.eth.sendTransaction(tx2).catch(e => e)

    const tx3 = {
      from: accounts[2].address,
      to: accounts[0].address,
      value: formatters.toWei('200', 'ether')
    }
    await this.web3.eth.sendTransaction(tx3).catch(e => e)

    if (process.env.API_TESTS_GANACHE_COMPILE_SC === 'true') {
      // Compile BeerToken smart contract
      const inputs = {}
      const contracts = ['BeerToken.sol', 'SafeMath.sol', 'StandardToken.sol', 'ERC20.sol', 'ERC20Basic.sol', 'BasicToken.sol']
      contracts.forEach(contract => {
        inputs[contract] = fs.readFileSync(`${__dirname}/contracts/${contract}`, 'utf8')
github ubiq / shokku / test / jsonrpc.e2e-spec.ts View on Github external
to: accounts[1].address,
      value: formatters.toWei('1', 'ether')
    }
    await this.web3.eth.sendTransaction(tx1).catch(e => e)

    const tx2 = {
      from: accounts[2].address,
      to: accounts[1].address,
      value: formatters.toWei('50', 'ether')
    }
    await this.web3.eth.sendTransaction(tx2).catch(e => e)

    const tx3 = {
      from: accounts[2].address,
      to: accounts[0].address,
      value: formatters.toWei('200', 'ether')
    }
    await this.web3.eth.sendTransaction(tx3).catch(e => e)

    if (process.env.API_TESTS_GANACHE_COMPILE_SC === 'true') {
      // Compile BeerToken smart contract
      const inputs = {}
      const contracts = ['BeerToken.sol', 'SafeMath.sol', 'StandardToken.sol', 'ERC20.sol', 'ERC20Basic.sol', 'BasicToken.sol']
      contracts.forEach(contract => {
        inputs[contract] = fs.readFileSync(`${__dirname}/contracts/${contract}`, 'utf8')
      })
      const out = solc.compile({
        sources: inputs
      }, 1)

      const bytecode = out.contracts['BeerToken.sol:BeerToken'].bytecode
      const abi = JSON.parse(out.contracts['BeerToken.sol:BeerToken'].interface)
github ethereum / web3.js / packages / web3-eth-personal / src / index.js View on Github external
along with web3.js.  If not, see .
*/
/**
 * @file index.js
 * @author Fabian Vogelsteller 
 * @date 2017
 */

"use strict";

var core = require('web3-core');
var Method = require('web3-core-method');
var utils = require('web3-utils');
var Net = require('web3-net');

var formatters = require('web3-core-helpers').formatters;


var Personal = function Personal() {
    var _this = this;

    // sets _requestmanager
    core.packageInit(this, arguments);

    this.net = new Net(this.currentProvider);

    var defaultAccount = null;
    var defaultBlock = 'latest';

    Object.defineProperty(this, 'defaultAccount', {
        get: function () {
            return defaultAccount;
github citahub / cita-sdk-js / packages / cita-sdk / src / contract / index.ts View on Github external
// prevent the event "newListener" and "removeListener" from being overwritten
  this._checkListener('newListener', subOptions.event.name, subOptions.callback)
  this._checkListener(
    'removeListener',
    subOptions.event.name,
    subOptions.callback
  )

  // TODO check if listener already exists? and reuse subscription if options are the same.

  // create new subscription
  var subscription = new Subscription({
    subscription: {
      params: 1,
      inputFormatter: [formatters.inputLogFormatter],
      outputFormatter: this._decodeEventABI.bind(subOptions.event),
      // DUBLICATE, also in web3-eth
      subscriptionHandler: function(output: any) {
        if (output.removed) {
          ctx.emit('changed', output)
        } else {
          ctx.emit('data', output)
        }

        if (_.isFunction(ctx.callback)) {
          ctx.callback(null, output, this)
        }
      }
    },
    type: 'eth',
    requestManager: this._requestManager
github MCROEngineering / zoom / src / utils / HttpProvider.ts View on Github external
/*

 * source       https://github.com/MCROEngineering/zoom/
 * @name        HttpProvider
 * @package     ZoomDev
 * @author      Micky Socaci 
 * @license     MIT
 
 based on https://github.com/ethereum/web3.js/blob/develop/lib/web3/httpprovider.js
*/

import CryptoJS from "crypto-js";
const errors = require('web3-core-helpers').errors;
const XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line

export default class HttpProvider {

    public cache: any;
    public hits: number = 0;
    public requests: any = [];
    private host: string;
    private timeout: number;
    private headers: any;
    private connected: boolean = false;
    private usecache: boolean = false;

    constructor(host?: any, options?: any) {
        options = options || {};
        this.host = host || 'http://localhost:8545';
github MCROEngineering / zoom / dist / lib / utils / HttpProvider.js View on Github external
/*

 * source       https://github.com/MCROEngineering/zoom/
 * @name        HttpProvider
 * @package     ZoomDev
 * @author      Micky Socaci 
 * @license     MIT
 
 based on https://github.com/ethereum/web3.js/blob/develop/lib/web3/httpprovider.js
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var crypto_js_1 = __importDefault(require("crypto-js"));
var errors = require('web3-core-helpers').errors;
var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line
var HttpProvider = /** @class */ (function () {
    function HttpProvider(host, options) {
        this.hits = 0;
        this.requests = [];
        this.connected = false;
        this.usecache = false;
        options = options || {};
        this.host = host || 'http://localhost:8545';
        this.timeout = options.timeout || 0;
        this.headers = options.headers;
        this.cache = {};
    }
    /**
     * Create and return a new XMLHttpRequest
     *
github MCROEngineering / zoom / dist / lib / utils / WsProvider.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require('underscore');
var errors = require('web3-core-helpers').errors;
var Ws = null;
var parseURL = null;
var myBtoa = null;
// @ts-ignore: WebSocket
/*
if (typeof window !== 'undefined' && typeof window.WebSocket !== 'undefined') {
    // @ts-ignore: WebSocket
    Ws = window.WebSocket;
    myBtoa = btoa;
    parseURL = (iurl: any) => {
        return new URL(iurl);
    };
} else {
*/
Ws = require('websocket').w3cwebsocket;
myBtoa = function (str) {
github ethereum / web3.js / packages / web3-providers-http / src / index.js View on Github external
but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with web3.js.  If not, see .
*/
/** @file httpprovider.js
 * @authors:
 *   Marek Kotewicz 
 *   Marian Oancea
 *   Fabian Vogelsteller 
 * @date 2015
 */

var errors = require('web3-core-helpers').errors;
var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line
var http = require('http');
var https = require('https');


/**
 * HttpProvider should be used to send rpc calls over http
 */
var HttpProvider = function HttpProvider(host, options) {
    options = options || {};

    var keepAlive = (options.keepAlive === true || options.keepAlive !== false) ? true : false;
    this.host = host || 'http://localhost:8545';
    if (this.host.substring(0,5) === "https") {
        this.httpsAgent = new https.Agent({ keepAlive: keepAlive });
    } else {
github MCROEngineering / zoom / src / utils / WsProvider.ts View on Github external
const _ = require('underscore');
const errors = require('web3-core-helpers').errors;

let Ws: any = null;
let parseURL: any = null;
let myBtoa: any = null;

    // @ts-ignore: WebSocket
    /*
    if (typeof window !== 'undefined' && typeof window.WebSocket !== 'undefined') {
        // @ts-ignore: WebSocket
        Ws = window.WebSocket;
        myBtoa = btoa;
        parseURL = (iurl: any) => {
            return new URL(iurl);
        };
    } else {
    */