How to use the @0x/dev-utils.web3Factory.getRpcProvider function in @0x/dev-utils

To help you get started, we’ve selected a few @0x/dev-utils 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-monorepo / contracts / test-utils / src / web3_wrapper.ts View on Github external
providerConfigs = {
        ...providerConfigs,
        fork: process.env.FORK_RPC_URL,
        blockTime: 0,
        unlocked_accounts: [
            // ZeroExGovernor signer addresses
            '0x257619b7155d247e43c8b6d90c8c17278ae481f0',
            '0x5ee2a00f8f01d099451844af7f894f26a57fcbf2',
            '0x894d623e0e0e8ed12c4a73dada999e275684a37d',
            // ERC20BridgeProxy
            '0x8ed95d1746bf1e4dab58d8ed4724f1ef95b20db0',
        ],
    };
}

export const provider: Web3ProviderEngine = web3Factory.getRpcProvider(providerConfigs);
provider.stop();
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
const isProfilerEnabled = env.parseBoolean(EnvVars.SolidityProfiler);
const isRevertTraceEnabled = env.parseBoolean(EnvVars.SolidityRevertTrace);
const enabledSubproviderCount = _.filter(
    [isCoverageEnabled, isProfilerEnabled, isRevertTraceEnabled],
    _.identity.bind(_),
).length;
if (enabledSubproviderCount > 1) {
    throw new Error(`Only one of coverage, profiler, or revert trace subproviders can be enabled at a time`);
}
if (isCoverageEnabled) {
    const coverageSubprovider = coverage.getCoverageSubproviderSingleton();
    prependSubprovider(provider, coverageSubprovider);
}
if (isProfilerEnabled) {
github 0xProject / 0x-monorepo / packages / migrations / src / migrate_with_test_defaults.ts View on Github external
export async function migrateOnceAsync(): Promise {
    const txDefaults = {
        gas: devConstants.GAS_LIMIT,
        from: devConstants.TESTRPC_FIRST_ADDRESS,
    };
    const provider: Web3ProviderEngine = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
    return runMigrationsOnceAsync(provider, txDefaults);
}
github 0xProject / 0x-monorepo / packages / migrations / src / migrate_snapshot.ts View on Github external
(async () => {
    let providerConfigs;
    let provider: Web3ProviderEngine;
    let txDefaults;
    const packageJsonPath = path.join(__dirname, '../..', 'package.json');
    const packageJsonString = fs.readFileSync(packageJsonPath, 'utf8');
    const packageJson = JSON.parse(packageJsonString);
    if (packageJson.config === undefined || packageJson.config.snapshot_name === undefined) {
        throw new Error(`Did not find 'snapshot_name' key in package.json config`);
    }

    providerConfigs = { shouldUseInProcessGanache: true, ganacheDatabasePath: packageJson.config.snapshot_name };
    provider = web3Factory.getRpcProvider(providerConfigs);
    txDefaults = {
        from: devConstants.TESTRPC_FIRST_ADDRESS,
    };
    await runMigrationsAsync(provider, txDefaults);
    process.exit(0);
})().catch(err => {
    logUtils.log(err);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_erc20_events.ts View on Github external
(async () => {
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: INFURA_ROOT_URL,
    });
    const endBlock = await calculateEndBlockAsync(provider);
    for (const token of tokensToGetApprovalEvents) {
        await getAndSaveApprovalEventsAsync(provider, token, endBlock);
    }
    process.exit(0);
})().catch(handleError);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_exchange_events.ts View on Github external
(async () => {
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: INFURA_ROOT_URL,
    });
    const endBlock = await calculateEndBlockAsync(provider);
    const eventsSource = new ExchangeEventsSource(provider, 1);
    await getFillEventsAsync(eventsSource, endBlock);
    await getCancelEventsAsync(eventsSource, endBlock);
    await getCancelUpToEventsAsync(eventsSource, endBlock);
    process.exit(0);
})().catch(handleError);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_missing_blocks.ts View on Github external
(async () => {
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: `${INFURA_ROOT_URL}/${process.env.INFURA_API_KEY}`,
    });
    const web3Source = new Web3Source(provider);
    await getAllMissingBlocks(web3Source);
    process.exit(0);
})().catch(handleError);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / merge_v2_events.ts View on Github external
async function getExchangeEventsAsync(): Promise {
    console.log('Getting event logs...');
    const provider = web3Factory.getRpcProvider({
        rpcUrl: 'https://mainnet.infura.io',
    });
    const eventsRepository = connection.getRepository(ExchangeFillEvent);
    const exchangeEvents = new ExchangeEventsSource(provider, 1);
    const eventLogs = await exchangeEvents.getFillEventsAsync();
    console.log('Parsing events...');
    const events = parseExchangeEvents(eventLogs);
    console.log(`Retrieved and parsed ${events.length} total events.`);
    console.log('Saving events...');
    for (const event of events) {
        await eventsRepository.save(event);
    }
    await eventsRepository.save(events);
    console.log('Saved events.');
}
github 0xProject / 0x-monorepo / packages / migrations / src / migrate.ts View on Github external
(async () => {
    let providerConfigs;
    let provider: Web3ProviderEngine;
    let txDefaults;

    providerConfigs = { shouldUseInProcessGanache: false };
    provider = web3Factory.getRpcProvider(providerConfigs);
    txDefaults = {
        from: devConstants.TESTRPC_FIRST_ADDRESS,
    };
    await runMigrationsAsync(provider, txDefaults);
    process.exit(0);
})().catch(err => {
    logUtils.log(err);
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_exchange_transactions_from_etherscan.ts View on Github external
(async () => {
    const apiKey = process.env.ETHERSCAN_API_KEY;
    if (apiKey === undefined) {
        throw new Error('Missing required env var: ETHERSCAN_API_KEY');
    }
    connection = await createConnection(ormConfig as ConnectionOptions);
    const provider = web3Factory.getRpcProvider({
        rpcUrl: INFURA_ROOT_URL,
    });
    const EtherscanTransactionRepository = connection.getRepository(EtherscanTransaction);
    const startBlock = await getStartBlockAsync(EtherscanTransactionRepository);
    logUtils.log(`Start block: ${startBlock}`);
    const endBlock = await calculateEndBlockAsync(provider);
    logUtils.log(`End block: ${endBlock}`);
    const etherscanSource = new EtherscanSource(apiKey, startBlock, endBlock);
    const exchangeContractAddress = getContractAddressesForNetworkOrThrow(NetworkId.Mainnet).exchange;
    logUtils.log('Fetching exchange transactions from Etherscan...');
    const rawTransactions = await etherscanSource.getEtherscanTransactionsForAddressAsync(exchangeContractAddress);
    const transactions = parseEtherscanTransactions(rawTransactions);
    logUtils.log(`Saving ${transactions.length} records to database`);
    await EtherscanTransactionRepository.save(transactions, {
        chunk: Math.ceil(transactions.length / BATCH_SAVE_SIZE),
    });