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


TypeScript web3-wrapper.Web3Wrapper類代碼示例

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


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

示例1: onDeployCommandAsync

/**
 * Deploys a single contract with provided name and args.
 * @param argv Instance of process.argv provided by yargs.
 */
async function onDeployCommandAsync(argv: CliOptions): Promise<void> {
    const url = argv.jsonrpcUrl;
    const web3Provider = new Web3.providers.HttpProvider(url);
    const web3Wrapper = new Web3Wrapper(web3Provider);
    const networkId = await web3Wrapper.getNetworkIdAsync();
    const compilerOpts: CompilerOptions = {
        contractsDir: argv.contractsDir,
        networkId,
        optimizerEnabled: argv.shouldOptimize,
        artifactsDir: argv.artifactsDir,
        specifiedContracts: getContractsSetFromList(argv.contracts),
    };
    await commands.compileAsync(compilerOpts);

    const defaults = {
        gasPrice: new BigNumber(argv.gasPrice),
        from: argv.account,
    };
    const deployerOpts: DeployerOptions = {
        artifactsDir: argv.artifactsDir,
        jsonrpcUrl: argv.jsonrpcUrl,
        networkId,
        defaults,
    };
    const deployerArgsString = argv.args as string;
    const deployerArgs = deployerArgsString.split(',');
    await commands.deployAsync(argv.contract as string, deployerArgs, deployerOpts);
}
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:32,代碼來源:cli.ts

示例2: updateProviderToInjectedAsync

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

        if (_.isUndefined(this._cachedProvider)) {
            return; // Going from injected to injected, so we noop
        }

        this._blockchainWatcher.destroy();

        const provider = this._cachedProvider;
        this.networkId = this._cachedProviderNetworkId;

        const shouldPollUserAddress = true;
        this._web3Wrapper = new Web3Wrapper(provider);
        this._blockchainWatcher = new BlockchainWatcher(
            this._dispatcher,
            this._web3Wrapper,
            this.networkId,
            shouldPollUserAddress,
        );

        const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
        this._userAddressIfExists = userAddresses[0];

        this._zeroEx.setProvider(provider, this.networkId);

        await this.fetchTokenInformationAsync();
        this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
        this._dispatcher.updateProviderType(ProviderType.Injected);
        delete this._ledgerSubprovider;
        delete this._cachedProvider;
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:32,代碼來源:blockchain.ts

示例3: describe

describe('RPC tests', () => {
    const web3Provider = web3Factory.getRpcProvider();
    const web3Wrapper = new Web3Wrapper(web3Provider);
    describe('#mineBlockAsync', () => {
        it('increases block number when called', async () => {
            const blockNumberBefore = await web3Wrapper.getBlockNumberAsync();
            await web3Wrapper.mineBlockAsync();
            const blockNumberAfter = await web3Wrapper.getBlockNumberAsync();
            expect(blockNumberAfter).to.be.equal(blockNumberBefore + 1);
        });
    });
    describe('#increaseTimeAsync', () => {
        it('increases time when called', async () => {
            const TIME_DELTA = 1000;
            const blockTimestampBefore = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest);
            await web3Wrapper.increaseTimeAsync(TIME_DELTA);
            await web3Wrapper.mineBlockAsync();
            const blockTimestampAfter = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest);
            expect(blockTimestampAfter).to.be.at.least(blockTimestampBefore + TIME_DELTA);
        });
    });
    describe('#takeSnapshotAsync/revertSnapshotAsync', () => {
        it('reverts changes in between', async () => {
            const blockNumberBefore = await web3Wrapper.getBlockNumberAsync();
            const snapshotId = await web3Wrapper.takeSnapshotAsync();
            await web3Wrapper.mineBlockAsync();
            await web3Wrapper.revertSnapshotAsync(snapshotId);
            const blockNumberAfter = await web3Wrapper.getBlockNumberAsync();
            expect(blockNumberAfter).to.be.equal(blockNumberBefore);
        });
    });
});
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:32,代碼來源:rpc_test.ts

示例4: it

 it('reverts changes in between', async () => {
     const blockNumberBefore = await web3Wrapper.getBlockNumberAsync();
     const snapshotId = await web3Wrapper.takeSnapshotAsync();
     await web3Wrapper.mineBlockAsync();
     await web3Wrapper.revertSnapshotAsync(snapshotId);
     const blockNumberAfter = await web3Wrapper.getBlockNumberAsync();
     expect(blockNumberAfter).to.be.equal(blockNumberBefore);
 });
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:8,代碼來源:rpc_test.ts

示例5: it

 it('reverts changes in between', async () => {
     const blockNumberBefore = await web3Wrapper.getBlockNumberAsync();
     await blockchainLifecycle.startAsync();
     await web3Wrapper.mineBlockAsync();
     const blockNumberAfter = await web3Wrapper.getBlockNumberAsync();
     expect(blockNumberAfter).to.be.equal(blockNumberBefore + 1);
     await blockchainLifecycle.revertAsync();
     const blockNumberAfterRevert = await web3Wrapper.getBlockNumberAsync();
     expect(blockNumberAfterRevert).to.be.equal(blockNumberBefore);
 });
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:10,代碼來源:blockchain_lifecycle_test.ts

示例6: _getAllowableGasEstimateAsync

 /**
  * Estimates the gas required for a transaction.
  * If gas would be over the block gas limit, the max allowable gas is returned instead.
  * @param data Bytecode to estimate gas for.
  * @return Gas estimate for transaction data.
  */
 private async _getAllowableGasEstimateAsync(data: string): Promise<number> {
     const block = await this.web3Wrapper.getBlockAsync('latest');
     let gas: number;
     try {
         const gasEstimate: number = await this.web3Wrapper.estimateGasAsync({ data });
         gas = Math.min(gasEstimate + EXTRA_GAS, block.gasLimit);
     } catch (err) {
         gas = block.gasLimit;
     }
     return gas;
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:17,代碼來源:deployer.ts

示例7: _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

示例8: _updateUserWeiBalanceAsync

 private async _updateUserWeiBalanceAsync(userAddress: string) {
     const balanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(userAddress);
     if (!balanceInWei.eq(this._prevUserEtherBalanceInWei)) {
         this._prevUserEtherBalanceInWei = balanceInWei;
         this._dispatcher.updateUserWeiBalance(balanceInWei);
     }
 }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:7,代碼來源:blockchain_watcher.ts

示例9: signOrderHashAsync

    public async signOrderHashAsync(orderHash: string): Promise<ECSignature> {
        utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
        const makerAddress = this._userAddressIfExists;
        // If makerAddress is undefined, this means they have a web3 instance injected into their browser
        // but no account addresses associated with it.
        if (_.isUndefined(makerAddress)) {
            throw new Error('Tried to send a sign request but user has no associated addresses');
        }

        this._showFlashMessageIfLedger();
        const nodeVersion = await this._web3Wrapper.getNodeVersionAsync();
        const isParityNode = utils.isParityNode(nodeVersion);
        const isTestRpc = utils.isTestRpc(nodeVersion);
        const isLedgerSigner = !_.isUndefined(this._ledgerSubprovider);
        let shouldAddPersonalMessagePrefix = true;
        if ((isParityNode && !isLedgerSigner) || isTestRpc || isLedgerSigner) {
            shouldAddPersonalMessagePrefix = false;
        }
        const ecSignature = await this._zeroEx.signOrderHashAsync(
            orderHash,
            makerAddress,
            shouldAddPersonalMessagePrefix,
        );
        this._dispatcher.updateECSignature(ecSignature);
        return ecSignature;
    }
開發者ID:ewingrj,項目名稱:0x-monorepo,代碼行數:26,代碼來源:blockchain.ts


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