How to use the @0x/web3-wrapper.Web3Wrapper function in @0x/web3-wrapper

To help you get started, we’ve selected a few @0x/web3-wrapper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-starter-project / src / scenarios / match_orders.ts View on Github external
export async function scenarioAsync(): Promise {
    await runMigrationsOnceIfRequiredAsync();
    PrintUtils.printScenario('Match Orders');
    // Initialize the ContractWrappers, this provides helper functions around calling
    // 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
    const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
    // Initialize the Web3Wrapper, this provides helper functions around fetching
    // account information, balances, general contract logs
    const web3Wrapper = new Web3Wrapper(providerEngine);
    const [leftMaker, rightMaker, matcherAccount] = await web3Wrapper.getAvailableAddressesAsync();
    const zrxTokenAddress = contractAddresses.zrxToken;
    const etherTokenAddress = contractAddresses.etherToken;
    const printUtils = new PrintUtils(
        web3Wrapper,
        contractWrappers,
        { leftMaker, rightMaker, matcherAccount },
        { WETH: etherTokenAddress, ZRX: zrxTokenAddress },
    );
    printUtils.printAccounts();

    // the amount the maker is selling of maker asset
    const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(10), DECIMALS);
    // the amount the maker wants of taker asset
    const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.4), DECIMALS);
    // 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction_cancel_order.ts View on Github external
export async function scenarioAsync(): Promise {
    await runMigrationsOnceIfRequiredAsync();
    PrintUtils.printScenario('Execute Transaction cancelOrderOrder');
    // Initialize the ContractWrappers, this provides helper functions around calling
    // 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
    const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
    // Initialize the Web3Wrapper, this provides helper functions around fetching
    // account information, balances, general contract logs
    const web3Wrapper = new Web3Wrapper(providerEngine);
    const [maker, taker, sender] = await web3Wrapper.getAvailableAddressesAsync();
    const feeRecipientAddress = sender;
    const zrxTokenAddress = contractAddresses.zrxToken;
    const etherTokenAddress = contractAddresses.etherToken;
    const printUtils = new PrintUtils(
        web3Wrapper,
        contractWrappers,
        { maker, taker, sender },
        { WETH: etherTokenAddress, ZRX: zrxTokenAddress },
    );
    printUtils.printAccounts();

    // the amount the maker is selling of maker asset
    const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
    // the amount the maker wants of taker asset
    const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
github 0xProject / 0x-monorepo / packages / website / ts / blockchain.ts View on Github external
public async getUserAccountsAsync(): Promise {
        utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.');
        const provider = this._contractWrappers.getProvider();
        const web3Wrapper = new Web3Wrapper(provider);
        const userAccountsIfExists = await web3Wrapper.getAvailableAddressesAsync();
        return userAccountsIfExists;
    }
    // HACK: When a user is using a Ledger, we simply dispatch the selected userAddress, which
github 0xProject / 0x-starter-project / src / scenarios / fill_order_fees.ts View on Github external
export async function scenarioAsync(): Promise {
    await runMigrationsOnceIfRequiredAsync();
    PrintUtils.printScenario('Fill Order with Fees');
    // Initialize the ContractWrappers, this provides helper functions around calling
    // 0x contracts as well as ERC20/ERC721 token contracts on the blockchain
    const contractWrappers = new ContractWrappers(providerEngine, { networkId: NETWORK_CONFIGS.networkId });
    // Initialize the Web3Wrapper, this provides helper functions around fetching
    // account information, balances, general contract logs
    const web3Wrapper = new Web3Wrapper(providerEngine);
    const [maker, taker, feeRecipient] = await web3Wrapper.getAvailableAddressesAsync();
    const zrxTokenAddress = contractAddresses.zrxToken;
    const etherTokenAddress = contractAddresses.etherToken;
    const printUtils = new PrintUtils(
        web3Wrapper,
        contractWrappers,
        { maker, taker, feeRecipient },
        { WETH: etherTokenAddress, ZRX: zrxTokenAddress },
    );
    printUtils.printAccounts();

    // the amount the maker is selling in maker asset
    const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5), DECIMALS);
    // the amount the maker wants of taker asset
    const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.1), DECIMALS);
    // the amount of fees the maker pays in ZRX
github 0xProject / 0x-monorepo / packages / website / ts / blockchain.ts View on Github external
private async _showEtherScanLinkAndAwaitTransactionMinedAsync(
        txHash: string,
    ): Promise {
        const etherScanLinkIfExists = sharedUtils.getEtherScanLinkIfExists(
            txHash,
            this.networkId,
            EtherscanLinkSuffixes.Tx,
        );
        this._dispatcher.showFlashMessage(
            React.createElement(TransactionSubmitted, {
                etherScanLinkIfExists,
            }),
        );
        const provider = this._contractWrappers.getProvider();
        const web3Wrapper = new Web3Wrapper(provider);
        const exchangeAbi = this._contractWrappers.exchange.abi;
        web3Wrapper.abiDecoder.addABI(exchangeAbi);
        const receipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
        return receipt;
    }
    private _doesUserAddressExist(): boolean {
github 0xProject / 0x-starter-project / src / utils.ts View on Github external
export const runMigrationsOnceIfRequiredAsync = async (): Promise => {
    if (NETWORK_CONFIGS === GANACHE_CONFIGS) {
        PrintUtils.printScenario('Deploying Contracts');
        const web3Wrapper = new Web3Wrapper(providerEngine);
        const [owner] = await web3Wrapper.getAvailableAddressesAsync();
        await runMigrationsOnceAsync(providerEngine, { from: owner });
    }
};
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_exchange_transactions_from_etherscan.ts View on Github external
async function calculateEndBlockAsync(provider: Web3ProviderEngine): Promise {
    const web3Wrapper = new Web3Wrapper(provider);
    const currentBlock = await web3Wrapper.getBlockNumberAsync();
    return currentBlock - BLOCK_FINALITY_THRESHOLD;
}
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / contract_wrappers.ts View on Github external
constructor(supportedProvider: SupportedProvider, config: ContractWrappersConfig) {
        assert.doesConformToSchema('config', config, ContractWrappersConfigSchema);
        const txDefaults = {
            gasPrice: config.gasPrice,
        };
        this._web3Wrapper = new Web3Wrapper(supportedProvider, txDefaults);
        const contractsArray = [
            CoordinatorContract,
            DevUtilsContract,
            ERC20TokenContract,
            ERC721TokenContract,
            ExchangeContract,
            ForwarderContract,
            StakingContract,
            WETH9Contract,
        ];
        contractsArray.forEach(contract => {
            this._web3Wrapper.abiDecoder.addABI(contract.ABI(), contract.contractName);
        });
        const contractAddresses =
            config.contractAddresses === undefined
                ? _getDefaultContractAddresses(config.chainId)