How to use web3-eth - 10 common examples

To help you get started, we’ve selected a few web3-eth 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 RequestNetwork / requestNetwork / packages / ethereum-storage / src / smart-contract-manager.ts View on Github external
} = {
      maxConcurrency: Number.MAX_SAFE_INTEGER,
    },
  ) {
    this.maxConcurrency = maxConcurrency;
    this.logger = logger || new Utils.SimpleLogger();

    this.maxRetries = maxRetries;
    this.retryDelay = retryDelay;

    web3Connection = web3Connection || {};

    try {
      this.eth = new web3Eth(
        web3Connection.web3Provider ||
          new web3Eth.providers.HttpProvider(config.getDefaultEthereumProvider()),
      );
    } catch (error) {
      throw Error(`Can't initialize web3-eth ${error}`);
    }

    // Checks if networkId is defined
    // If not defined we use default value from config
    this.networkName =
      typeof web3Connection.networkId === 'undefined'
        ? config.getDefaultEthereumNetwork()
        : EthereumUtils.getEthereumNetworkNameFromId(web3Connection.networkId);

    // If networkName is undefined, it means the network doesn't exist
    if (typeof this.networkName === 'undefined') {
      throw Error(`The network id ${web3Connection.networkId} doesn't exist`);
    }
github melonproject / protocol / src / utils / scratchpad.ts View on Github external
import * as fs from 'fs';
import * as path from 'path';
import * as Eth from 'web3-eth';

// Websocket could be the problem
// HTTP is faster, but same error
const eth = new Eth(new Eth.providers.HttpProvider('http://localhost:8545'));

const rawABI = fs.readFileSync(
  path.join(process.cwd(), 'out', 'factory', 'FundFactory.abi'),
  { encoding: 'utf-8' },
);
const ABI = JSON.parse(rawABI);
const fundFactoryAddress = '0x801cd3BCa02ffB46Ee5cf43B023Aa3619089d16b';
const contract = new eth.Contract(ABI, fundFactoryAddress);

const args = [
  ['0x9a8D6f20b917eA9542EEE886c78fE41C638A3d45'],
  [],
  ['0x4b1a08B5DBcf3386f22DB1d694beF84d8EF4B340'],
  [
    '0xc0dd7a9D5470216eaf97DD2CEcAc259da1f7Af2E',
    '0x2B83156799AB55F5581263Cd544372B9af2c2Cfe',
github embark-framework / subspace / src / subspace.js View on Github external
constructor(provider, options = {}) {
    if (provider.constructor.name !== "WebsocketProvider") {
      console.warn("subspace: it's recommended to use a websocket provider to react to new events");
    }

    this.events = new Events();
    this.web3 = new Web3Eth(provider);

    this.options = {};
    this.options.refreshLastNBlocks = options.refreshLastNBlocks || 12;
    this.options.callInterval = options.callInterval || 0;
    this.options.dbFilename = options.dbFilename || 'subspace.db';
    this.latestBlockNumber = undefined;
    this.disableDatabase = options.disableDatabase;
    this.networkId = undefined;

    this.newBlocksSubscription = null;
    this.intervalTracker = null;
    this.callables = [];
  }
github sirin-labs / crowdsale-smart-contract / scripts / crowdsale_deployer.js View on Github external
//general:
const DAY = 86400;
const OWNER = "0xcbc7efe0bf2664198176defb7f2cfbc9675dc60e";

//SirinCrowdsale constructor params:
const startTime         = 1513080000; //(Tue, 12 Dec 2017 12:00:00 GMT)
const endTime           = startTime + 14 * DAY;
const wallet            = "0x0012A1A4619bFdC0535Ab50E7c51D64d5C768d79";
const walletFounder     = "0x0012A1A4619bFdC0535Ab50E7c51D64d5C768d79";
const walletOEM         = "0x0012A1A4619bFdC0535Ab50E7c51D64d5C768d79";
const walletBounties    = "0x0012A1A4619bFdC0535Ab50E7c51D64d5C768d79";
const walletReserve     = "0x0012A1A4619bFdC0535Ab50E7c51D64d5C768d79";


var eth = new Eth(Eth.givenProvider || 'http://127.0.0.1:8545');
var SirinCrowdsaleCompiled;

processContract(process.argv[2])
    .then(deployContract());

/*
*/
async function processContract(contractFilePAth) {

    console.log("\nProcessing " + "\n----------\n" + CONTRACT_NAME + " (" + contractFilePAth + ")\n");

    var copmiled = SOLC.compile(FS.readFileSync(contractFilePAth, 'utf8'), 1)
    SirinCrowdsaleCompiled = copmiled.contracts[":" + CONTRACT_NAME];
    var bytecode = SirinCrowdsaleCompiled.bytecode
    var abi = SirinCrowdsaleCompiled.interface;
    var ctorParamsEncoded = getCtorParams();
github adibas03 / online-ethereum-abi-encoder-decoder / src / pages / index.js View on Github external
constructor(props) {
    super(props);

    try {
      if (window.ethereum) {
        this.eth = new Eth(window.ethereum);
      } else {
        this.eth = new Eth(Eth.givenProvider || "http://localhost:8545");
      }
    } catch (e) {
      this.eth = new Eth("wss://mainnet.infura.io/ws");
    }

    //Hanle binds
    this.handleActionChange = this.handleActionChange.bind(this);
    this.handleChange = this.handleChange.bind(this);

    const history = createBrowserHistory();
    const hash = history.location.hash;
    const action = hash && hash.substring(hash.indexOf("/")+1, hash.length);

    if (hash !== "#/" && allowedActions.includes(action)) {
      this.state = {
          action
github aragon / radspec / src / helpers / lib / methodRegistry.js View on Github external
constructor (opts = {}) {
    this.eth = opts.eth || new Eth(DEFAULT_ETH_NODE)
    this.network = opts.network || '1'
  }
github aragon / radspec / src / helpers / lib / methodRegistry.js View on Github external
async initRegistry () {
    if (await this.eth.net.getId() !== '1') {
      this.eth = new Eth(DEFAULT_ETH_NODE)
    }

    const address = REGISTRY_MAP[this.network]

    if (!address) {
      throw new Error('No method registry found on the requested network.')
    }

    this.registry = new this.eth.Contract(REGISTRY_LOOKUP_ABI, address)
  }

web3-eth

Web3 module to interact with the Ethereum blockchain and smart contracts.

LGPL-3.0
Latest version published 18 days ago

Package Health Score

98 / 100
Full package analysis

Similar packages