當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Web3Wrapper.getProvider方法代碼示例

本文整理匯總了TypeScript中@0xproject/web3-wrapper.Web3Wrapper.getProvider方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Web3Wrapper.getProvider方法的具體用法?TypeScript Web3Wrapper.getProvider怎麽用?TypeScript Web3Wrapper.getProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@0xproject/web3-wrapper.Web3Wrapper的用法示例。


在下文中一共展示了Web3Wrapper.getProvider方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _instantiateContractIfExistsAsync

    private async _instantiateContractIfExistsAsync(artifact: any, address?: string): Promise<ContractInstance> {
        const c = await contract(artifact);
        const providerObj = this._web3Wrapper.getProvider();
        c.setProvider(providerObj);

        const artifactNetworkConfigs = artifact.networks[this.networkId];
        let contractAddress;
        if (!_.isUndefined(address)) {
            contractAddress = address;
        } else if (!_.isUndefined(artifactNetworkConfigs)) {
            contractAddress = artifactNetworkConfigs.address;
        }

        if (!_.isUndefined(contractAddress)) {
            const doesContractExist = await this.doesContractExistAtAddressAsync(contractAddress);
            if (!doesContractExist) {
                logUtils.log(`Contract does not exist: ${artifact.contract_name} at ${contractAddress}`);
                throw new Error(BlockchainCallErrs.ContractDoesNotExist);
            }
        }

        try {
            const contractInstance = _.isUndefined(address) ? await c.deployed() : await c.at(address);
            return contractInstance;
        } catch (err) {
            const errMsg = `${err}`;
            logUtils.log(`Notice: Error encountered: ${err} ${err.stack}`);
            if (_.includes(errMsg, 'not been deployed to detected network')) {
                throw new Error(BlockchainCallErrs.ContractDoesNotExist);
            } else {
                await errorReporter.reportAsync(err);
                throw new Error(BlockchainCallErrs.UnhandledError);
            }
        }
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:35,代碼來源:blockchain.ts

示例2: destroy

 public destroy() {
     this._stopEmittingNetworkConnectionAndUserBalanceStateAsync();
     // HACK: stop() is only available on providerEngine instances
     const provider = this._web3Wrapper.getProvider();
     if (!_.isUndefined((provider as any).stop)) {
         (provider as any).stop();
     }
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:8,代碼來源:blockchain_watcher.ts

示例3: updateProviderToLedgerAsync

    public async updateProviderToLedgerAsync(networkId: number) {
        utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');

        const isU2FSupported = await utils.isU2FSupportedAsync();
        if (!isU2FSupported) {
            throw new Error('Cannot update providerType to LEDGER without U2F support');
        }

        // Cache injected provider so that we can switch the user back to it easily
        if (_.isUndefined(this._cachedProvider)) {
            this._cachedProvider = this._web3Wrapper.getProvider();
            this._cachedProviderNetworkId = this.networkId;
        }

        this._blockchainWatcher.destroy();

        delete this._userAddressIfExists;
        this._dispatcher.updateUserAddress(undefined); // Clear old userAddress

        const provider = new ProviderEngine();
        const ledgerWalletConfigs = {
            networkId,
            ledgerEthereumClientFactoryAsync: ledgerEthereumBrowserClientFactoryAsync,
        };
        this._ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
        provider.addProvider(this._ledgerSubprovider);
        provider.addProvider(new FilterSubprovider());
        provider.addProvider(new RedundantRPCSubprovider(configs.PUBLIC_NODE_URLS_BY_NETWORK_ID[networkId]));
        provider.start();
        this.networkId = networkId;
        this._dispatcher.updateNetworkId(this.networkId);
        const shouldPollUserAddress = false;
        this._web3Wrapper = new Web3Wrapper(provider);
        this._blockchainWatcher = new BlockchainWatcher(
            this._dispatcher,
            this._web3Wrapper,
            this.networkId,
            shouldPollUserAddress,
        );
        this._zeroEx.setProvider(provider, this.networkId);
        this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
        this._dispatcher.updateProviderType(ProviderType.Ledger);
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:43,代碼來源:blockchain.ts


注:本文中的@0xproject/web3-wrapper.Web3Wrapper.getProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。