當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。