本文整理汇总了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: 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
示例3: 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
示例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;未经允许,请勿转载。 |
请发表评论