当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript web3.setProvider函数代码示例

本文整理汇总了TypeScript中web3.setProvider函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setProvider函数的具体用法?TypeScript setProvider怎么用?TypeScript setProvider使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setProvider函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: compileAndDeploy

function compileAndDeploy(filename: string, callback: Function) {
  let web3: Web3 = new Web3()
  web3.setProvider(new Provider())
  let compilationData: object
  let accounts: string[]
  async.waterfall([
    function getAccountList(next: Function): void {
      web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => {
        accounts = _accounts
        next(_err)
      })
    },
    function compile(next: Function): void {
      compileFileOrFiles(filename, false, { accounts }, next)
    },
    function deployAllContracts(compilationResult: object, next: Function): void {
      try {
        compilationData = compilationResult
        deployAll(compilationResult, web3, next)
      } catch (e) {
        throw e
      }
    }
  ], function (_err: Error | null | undefined, contracts: any): void {
    callback(null, compilationData, contracts, accounts)
  })
}
开发者ID:0mkara,项目名称:remix,代码行数:27,代码来源:testRunner.ts

示例2: Web3

    .action((filename) => {
        // Console message
        console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
        // set logger verbosity
        if (commander.verbose) {
            logger.setVerbosity(commander.verbose)
            log.info('verbosity level set to ' + commander.verbose.blue)
        }
        let web3 = new Web3()
        // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
        web3.setProvider(new Provider())
        // web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546'))

        if (!fs.existsSync(filename)) {
            console.error(filename + ' not found')
            process.exit(1)
        }

        let isDirectory = fs.lstatSync(filename).isDirectory()
        runTestFiles(filename, isDirectory, web3)
    })
开发者ID:0mkara,项目名称:remix,代码行数:21,代码来源:run.ts

示例3: setProvider

 public setProvider(provider: Web3.Provider) {
     delete this.networkIdIfExists;
     this.web3.setProvider(provider);
 }
开发者ID:linki,项目名称:0x.js,代码行数:4,代码来源:web3_wrapper.ts

示例4: require

// HACK: web3 injects XMLHttpRequest into the global scope and ProviderEngine checks XMLHttpRequest
// to know whether it is running in a browser or node environment. We need it to be undefined since
// we are not running in a browser env.
// Filed issue: https://github.com/ethereum/web3.js/issues/844
(global as any).XMLHttpRequest = undefined;
import ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import * as Web3 from 'web3';
import {constants} from './constants';
import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider';

export const web3Factory = {
    create(hasAddresses: boolean = true): Web3 {
        const provider = this.getRpcProvider(hasAddresses);
        const web3 = new Web3();
        web3.setProvider(provider);
        return web3;
    },
    getRpcProvider(hasAddresses: boolean = true): Web3.Provider {
        const provider = new ProviderEngine();
        const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
        if (!hasAddresses) {
            provider.addProvider(new EmptyWalletSubProvider());
        }
        provider.addProvider(new RpcSubprovider({
            rpcUrl,
        }));
        provider.start();
        return provider;
    },
};
开发者ID:linki,项目名称:0x.js,代码行数:31,代码来源:web3_factory.ts

示例5: constructor

 constructor(provider: Web3.Provider, defaults: Partial<Web3.TxData>) {
     this.web3 = new Web3();
     this.web3.setProvider(provider);
     this.defaults = defaults;
 }
开发者ID:linki,项目名称:0x.js,代码行数:5,代码来源:web3_wrapper.ts


注:本文中的web3.setProvider函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。