How to use the web3.providers function in web3

To help you get started, we’ve selected a few web3 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 dharmaprotocol / dharma.js / __test__ / integration / adapters / collateralized_simple_interest_loan_adapter / collateralized_simple_interest_loan_adapter.spec.ts View on Github external
import { SUCCESSFUL_RETURN_COLLATERAL_SCENARIOS } from "./scenarios/successful_return_collateral_scenarios";

import { SUCCESSFUL_SEIZE_COLLATERAL_SCENARIOS } from "./scenarios/successful_seize_collateral_scenarios";

import { UNSUCCESSFUL_SEIZE_COLLATERAL_SCENARIOS } from "./scenarios/unsuccessful_seize_collateral_scenarios";

// Runners
import { ReturnCollateralRunner, SeizeCollateralRunner } from "./runners";

import { CollateralizedSimpleInterestLoanAdapter } from "src/adapters/collateralized_simple_interest_loan_adapter";

import { ServicingAPI } from "src/apis/servicing_api";

import { TokenAPI } from "../../../../src/apis/token_api";

const provider = new Web3.providers.HttpProvider("http://localhost:8545");
const web3 = new Web3(provider);

// Given that this is an integration test, we unmock the Dharma
// smart contracts artifacts package to pull the most recently
// deployed contracts on the current network.
jest.unmock("@dharmaprotocol/contracts");

describe("Collateralized Simple Interest Loan Adapter (Integration Tests)", () => {
    const contractsApi = new ContractsAPI(web3);

    const adaptersApi = new AdaptersAPI(web3, contractsApi);

    const servicingApi = new ServicingAPI(web3, contractsApi);

    const adapter = new CollateralizedSimpleInterestLoanAdapter(web3, contractsApi);
github kleros / kleros-api-DEPRECATED / script / postDataToStore.js View on Github external
let postDataToStore = async (contractsJson = '{}', disputesJson = '{}') => {
  // use testRPC
  const ethProvider = await new Web3.providers.HttpProvider(LOCALHOST_ETH_PROVIDER)
  const storeProvider = LOCALHOST_STORE_PROVIDER

  let KlerosInstance = await new Kleros(ethProvider, storeProvider)
  const userAccount = KlerosInstance._web3Wrapper.getAccount(0)

  const httpResponse = await KlerosInstance.store.newUserProfile(userAccount, JSON.parse(contractsJson), JSON.parse(disputesJson))
  console.log(httpResponse)
}
github IoTChainCode / tokenAirdrop / Airdrop / function / airdrop.js View on Github external
/**
 * Created by zhaoyiyu on 2018/1/17.
 */

const Config = require('./../config/config.js');

Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider(Config.transaction.url));

//init
const Tx = require('ethereumjs-tx');
const ethjsaccount = require('ethjs-account');
const fs = require('fs');
const solc = require('solc');

// compile the code
const input = fs.readFileSync('./contract/airdrop.sol');
const output = solc.compile(input.toString());
const abi = JSON.parse(output.contracts[':TokenAirDrop'].interface);


const tokenInput = fs.readFileSync('./contract/erc20Token.sol');
const tokenOutput = solc.compile(tokenInput.toString());
const tokenAbi = JSON.parse(tokenOutput.contracts[':TokenERC20'].interface);
github gnosis / dx-react / src / api / initialization.ts View on Github external
async setWeb3Provider(provider: any) {
    if (provider == null) {
      // Prefer Web3 injected by the browser (Mist/MetaMask)
      // Window must be loaded first so that there isn't a race condition for resolving injected Web3 instance
      await windowLoaded

      // if (typeof window.web3 !== 'undefined') {
      if (Object.keys(window.web3).length !== 0) {
        this.web3 = new Web3(window.web3.currentProvider)
      } else {
        this.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
      }
    } else if (typeof provider === 'string') {
      this.web3 = new Web3(new Web3.providers.HttpProvider(provider))
    } else if (typeof provider === 'object' && provider.constructor.name.endsWith('Provider')) {
      this.web3 = new Web3(provider)
    } else {
      throw new TypeError(`provider of type '${typeof provider}' not supported`)
    }

    // Set providers for all Contracts
    _.forOwn(this.contracts, (c: any) => { c.setProvider(this.web3.currentProvider) })

    // Attempt to attach all CONTRACT INSTANCES to Class
    await Promise.all([
      this.setupContractInstances('DutchExchange', this.contracts.DutchExchange),
      this.setupContractInstances('DutchExchangeFactory', this.contracts.DutchExchangeFactory),
github austintgriffith / minimum-viable-payment-channel / tests / clevis.js View on Github external
const colors = require('colors')
const chai = require("chai")
const HDWalletProvider = require("truffle-hdwallet-provider")
const assert = chai.assert
const expect = chai.expect;
const should = chai.should();

const fs = require('fs')
const Web3 = require('web3')
const clevisConfig = JSON.parse(fs.readFileSync("clevis.json").toString().trim())
const web3 = new Web3(
  clevisConfig.USE_INFURA ?
    new HDWalletProvider(
      process.env.mnemonic,
      clevisConfig.provider) :
    new Web3.providers.HttpProvider(clevisConfig.provider)
);

//console.log('clevisConfig.provider', clevisConfig.provider);

function localContractAddress(contract){
  return fs.readFileSync(clevisConfig.CONTRACTS_FOLDER+"/"+contract+ "/" + contract + ".address").toString().trim()
}
function localContractAbi(contract){
  return JSON.parse(fs.readFileSync(clevisConfig.CONTRACTS_FOLDER+"/"+contract+ "/"+ contract +".abi").toString().trim())
}
function printTxResult(result){
  if(!result||!result.transactionHash){
    console.log("ERROR".red,"MISSING TX HASH".yellow)
  }else{
    console.log(tab,result.transactionHash.gray,(""+result.gasUsed).yellow)
  }
github loomnetwork / dashboard / src / store / ethereum / index.ts View on Github external
async function setToExploreMode(context: ActionContext, address: string) {
  const endpoint = context.state.endpoint
  const web3Provider = /^ws/.test(endpoint) ?
    new Web3.providers.WebsocketProvider(endpoint) :
    new Web3.providers.HttpProvider(endpoint)

  web3 = new Web3(web3Provider)
  context.state.signer = null
  context.state.address = address
}
github trustwallet / trust-web3-provider / JS / src / index.js View on Github external
constructor(options, syncOptions) {
    super();
    const engine = this
    const web3 = new Web3(this)
    const { rpcUrl } = options

    context.web3 = web3
    globalSyncOptions = syncOptions

    engine.addProvider(new CacheSubprovider())
    engine.addProvider(new SubscriptionsSubprovider())
    engine.addProvider(new FilterSubprovider())
    engine.addProvider(hookedSubProvider = new HookedWalletSubprovider(options))
    engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl)))
    engine.on('error', err => console.error(err.stack))
    engine.isTrust = true
    engine.start()
  }
github ConsenSys / truffle-solidity-loader / index.js View on Github external
temp.mkdir('webpack-truffle', function(err, dirPath){
    if(!err) {
      var compilerOpts = {};
      compilerOpts.contracts_directory       = contractPath
      compilerOpts.contracts_build_directory = dirPath
      compilerOpts.network                   = buildOpts.network
      compilerOpts.network_id                = buildOpts.network_id
      compilerOpts.logger                    = Logger

      var provisionOpts = {}
      provisionOpts.provider                  = new Web3.providers.HttpProvider(buildOpts.web3_rpc_uri)
      provisionOpts.contracts_build_directory = dirPath

      TruffleContractCompiler.compile( compilerOpts, function(err, contracts){
        var migrationOpts = {}
        migrationOpts.migrations_directory      = buildOpts.migrations_directory
        migrationOpts.contracts_build_directory = dirPath
        migrationOpts.provider                  = provisionOpts.provider
        migrationOpts.network                   = compilerOpts.network
        migrationOpts.network_id                = compilerOpts.network_id
        migrationOpts.logger                    = Logger

        TruffleContractMigrator.run( migrationOpts, function( err, result ) {
          if(err) {
            Logger.error(err);
            return compilationFinished(err, null);
          }
github HAECHI-LABS / vvisp / packages / vvisp-utils / src / getWeb3.js View on Github external
module.exports = function() {
  const Web3 = require('web3');

  let url;

  if (process.env.NETWORK === 'local') {
    url = `http://localhost:${process.env.PORT}`;
  } else if (process.env.NETWORK === 'custom') {
    url = process.env.URL;
  } else {
    url = `https://${process.env.NETWORK}.infura.io/${
      process.env.INFURA_API_KEY
    }`;
  }
  const web3 = new Web3(new Web3.providers.HttpProvider(url));

  return web3;
};
github raiden-network / microraiden / microraiden / microraiden / webui / js / microraiden.js View on Github external
constructor(
    web3url,
    contractAddr,
    contractABI,
    tokenAddr,
    tokenABI,
  ) {
    if (!web3url) {
      web3url = "http://localhost:8545";
    }
    if (web3url.currentProvider) {
      this.web3 = new Web3(web3.currentProvider);
    }
    else if (typeof web3url === 'string') {
      this.web3 = new Web3(new Web3.providers.HttpProvider(web3url));
    }

    contractAddr = contractAddr || window["RDNcontractAddr"];
    contractABI = contractABI || window["RDNcontractABI"];
    this.contract = this.web3.eth.contract(contractABI).at(contractAddr);

    tokenAddr = tokenAddr || window["RDNtokenAddr"];
    tokenABI = tokenABI || window["RDNtokenABI"];
    this.token = this.web3.eth.contract(tokenABI).at(tokenAddr);
  }