How to use the 0x.js.ZeroEx function in 0x

To help you get started, we’ve selected a few 0x 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 0xchange / 0xchange / src / store / actions.js View on Github external
connect ({dispatch, commit, getters, state}) {
    let providerEngine = null
    if (window.web3) {
      providerEngine = window.web3.currentProvider
    } else {
      const ROPSTEN_ENDPOINT = 'https://infura.io'

      providerEngine = new ProviderEngine()
      providerEngine.addProvider(new FilterSubprovider())
      providerEngine.addProvider(new RpcSubprovider({rpcUrl: ROPSTEN_ENDPOINT}))
      providerEngine.start()
    }

    zeroEx = new ZeroEx(providerEngine)
    zeroEx._web3Wrapper.web3.version.getNetwork((error, response) => {
      if (error) console.error(error)
      if (parseInt(response) === 42 && window.location.hostname !== 'kovan.0xchange.me') {
        window.location.href = 'https://kovan.0xchange.me'
      } else if (parseInt(response) === 1 && window.location.hostname === 'kovan.0xchange.me') {
        window.location.href = 'https://0xchange.me'
      }
    })
    // commit('SET_ZERO_EX', zeroEx)
    // 3117574 kovan
    // 4145578 mainnet
    // zeroEx.exchange.getLogsAsync('LogFill', {fromBlock: 4219261, toBlock: 'latest'}, {}).then((logs) => {
    //   console.log(logs)
    //   commit('ADD_LOGS', logs)
    //   console.log(logs[0])
    //   let data = logs[0].data
github 0xProject / 0x-monorepo / packages / contract-scripts / src / token_registry / add_tokens.ts View on Github external
const mainAsync = async () => {
    // const tokens = transformToTokens(tokensToAddJSON);
    const tokens = TOKENS_TO_ADD;
    const provider = providerFactory.getLedgerProvider();
    const zeroEx = new ZeroEx(provider, ZERO_EX_CONFIG);
    const accounts = await zeroEx.getAvailableAddressesAsync();
    const primaryAccount = _.head(accounts);
    console.log(`Primary account address: ${primaryAccount}`);

    const existingTokens = await zeroEx.tokenRegistry.getTokensAsync();
    const existingTokenAddresses = _.map(existingTokens, token => token.address);
    for (const token of tokens) {
        if (!_.includes(existingTokenAddresses, token.address)) {
            console.log(`Attempting to add token symbol: ${token.symbol} address: ${token.address}`);
            const txHash = await zeroEx.tokenRegistry.addTokenAsync(token, primaryAccount || ZeroEx.NULL_ADDRESS);
            console.log(`Awaiting txHash: ${txHash}`);
            opn(`https://etherscan.io/tx/${txHash}`);
            const txReceipt = await zeroEx.awaitTransactionMinedAsync(txHash);
            console.log(`Added receipt: ${JSON.stringify(txReceipt)}`);
        }
    }
github 0xProject / 0x-starter-project / src / tutorials / order_actions / index.ts View on Github external
import { DecodedLogEvent, ZeroEx } from '0x.js';
import { BigNumber } from '@0xproject/utils';
import * as Web3 from 'web3';

const TESTRPC_NETWORK_ID = 50;

// Provider pointing to local TestRPC on default port 8545
const provider = new Web3.providers.HttpProvider('http://localhost:8545');

// Instantiate 0x.js instance
const configs = {
    networkId: TESTRPC_NETWORK_ID,
};
const zeroEx = new ZeroEx(provider, configs);

// Number of decimals to use (for ETH and ZRX)
const DECIMALS = 18;

const mainAsync = async () => {
    // Addresses
    const WETH_ADDRESS = zeroEx.etherToken.getContractAddressIfExists() as string; // The wrapped ETH token contract
    const ZRX_ADDRESS = zeroEx.exchange.getZRXTokenAddress(); // The ZRX token contract
    // The Exchange.sol address (0x exchange smart contract)
    const EXCHANGE_ADDRESS = zeroEx.exchange.getContractAddress();

    // Getting list of accounts
    const accounts = await zeroEx.getAvailableAddressesAsync();
    console.log('accounts: ', accounts);

    // Set our addresses
github johnrjj / conduit / src / app.ts View on Github external
const isProduction = config.NODE_ENV === 'production' ? true : false;
  const logger: Logger = ConsoleLoggerFactory({ level: config.LOG_LEVEL });
  const BLOCKCHAIN_NETWORK_ENDPOINT = config.BLOCKCHAIN_NETWORK_ENDPOINT;
  const BLOCKCHAIN_STARTING_BLOCK = config.BLOCKCHAIN_STARTING_BLOCK;
  const ZEROEX_EXCHANGE_SOL_ADDRESS = config.ZERO_EX_EXCHANGE_SOL_ADDRESS;

  logger.log('info', 'Conduit starting...');
  // Set up Web3
  const providerEngine = new ProviderEngine();
  providerEngine.addProvider(new FilterSubprovider());
  providerEngine.addProvider(new RpcSubprovider({ rpcUrl: BLOCKCHAIN_NETWORK_ENDPOINT }));
  providerEngine.start();
  logger.log('verbose', 'Connected to Web3 Provider Engine');

  // Set up ZeroEx
  const zeroEx = new ZeroEx(providerEngine, {
    // todo: figure out how to get this dynamically...
    networkId: 42,
    orderWatcherConfig: { eventPollingIntervalMs: 1000 },
  });
  logger.log('verbose', 'ZeroEx client set up');

  // Set up Redis
  const redisPublisher = config.REDIS_URL ? createClient(config.REDIS_URL) : createClient();
  const publisher = new RedisPublisher({ redisPublisher, logger });
  logger.log('verbose', 'Redis Publisher setup');
  const redisSubscriber = config.REDIS_URL ? createClient(config.REDIS_URL) : createClient();
  const subscriber = new RedisSubscriber({ redisSubscriber, logger });
  logger.log('verbose', 'Redis Subscriber setup');
  logger.log('debug', 'Connected to Redis instance');

  // Set up Relay Client (Postgres flavor)
github 0xProject / 0x-monorepo / packages / testnet-faucets / src / ts / zrx_request_queue.ts View on Github external
constructor(web3: Web3, networkId: number) {
        super(web3);
        this._queueIntervalMs = QUEUE_INTERVAL_MS;
        const zeroExConfig = {
            networkId,
        };
        this._zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig);
    }
    protected async _processNextRequestFireAndForgetAsync(recipientAddress: string) {
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / scrape-data.ts View on Github external
import { ExchangeEvents, ZeroEx } from '0x.js';
import * as commandLineArgs from 'command-line-args';
import * as queue from 'queue';
import * as Web3 from 'web3';
import { typeConverters } from '../utils.js';
import { insertDataScripts } from './tables.js';

const optionDefinitions = [{ name: 'from', alias: 'f', type: Number }, { name: 'to', alias: 't', type: Number }];
const cli = commandLineArgs(optionDefinitions);

const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io/Rd44ElIrWp05rUczoKps');

const q = queue({ concurrency: 4, autostart: true });

const MAINNET = 1;
const zrx = new ZeroEx(provider, {
    networkId: MAINNET,
});

const BLOCK_INCREMENTS = 1000;

export const scrapeDataScripts = {
    getAllEvents(fromBlockNumber: number, toBlockNumber: number): any {
        return new Promise((resolve, reject) => {
            const getLogsPromises: any[] = [];
            getLogsPromises.push(
                zrx.exchange.getLogsAsync(
                    ExchangeEvents.LogFill,
                    { fromBlock: fromBlockNumber, toBlock: toBlockNumber },
                    {},
                ),
                zrx.exchange.getLogsAsync(
github 0xTracker / 0x-event-extractor / src / util / ethereum / 0x.js View on Github external
const configure = ({ networkId }) => {
  client = new ZeroEx(getProviderEngine(), { networkId });
};