How to use the 0x.js.ZeroEx.generatePseudoRandomSalt 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 0xProject / 0x-starter-project / src / tutorials / order_actions / index.ts View on Github external
const ethAmount = new BigNumber(1);
    const ethToConvert = ZeroEx.toBaseUnitAmount(ethAmount, DECIMALS); // Number of ETH to convert to WETH

    const convertEthTxHash = await zeroEx.etherToken.depositAsync(WETH_ADDRESS, ethToConvert, takerAddress);
    await zeroEx.awaitTransactionMinedAsync(convertEthTxHash);
    console.log(`${ethAmount} ETH -> WETH conversion mined...`);

    // Generate order
    const order = {
        maker: makerAddress,
        taker: ZeroEx.NULL_ADDRESS,
        feeRecipient: ZeroEx.NULL_ADDRESS,
        makerTokenAddress: ZRX_ADDRESS,
        takerTokenAddress: WETH_ADDRESS,
        exchangeContractAddress: EXCHANGE_ADDRESS,
        salt: ZeroEx.generatePseudoRandomSalt(),
        makerFee: new BigNumber(0),
        takerFee: new BigNumber(0),
        makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.2), DECIMALS), // Base 18 decimals
        takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(0.3), DECIMALS), // Base 18 decimals
        expirationUnixTimestampSec: new BigNumber(Date.now() + 3600000), // Valid for up to an hour
    };

    // Create orderHash
    const orderHash = ZeroEx.getOrderHashHex(order);

    // Signing orderHash -> ecSignature
    const shouldAddPersonalMessagePrefix = false;
    const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress, shouldAddPersonalMessagePrefix);

    // Appending signature to order
    const signedOrder = {
github 0xchange / 0xchange / src / components / Order.vue View on Github external
setOrder () {
      if (!this.order) return

      this.tmpOrder.exchangeContractAddress = this.$store.state.EXCHANGE_ADDRESS

      if (this.newOrder) {
        this.$refs.form.reset()
        this.tmpOrder.maker = this.address
        this.tmpOrder.taker = this.$store.state.NULL_ADDRESS
        this.tmpOrder.feeRecipient = this.$store.state.NULL_ADDRESS
        this.tmpOrder.makerTokenAddress = this.order.makerTokenAddress
        this.tmpOrder.takerTokenAddress = this.order.takerTokenAddress
        this.tmpOrder.salt = ZeroEx.generatePseudoRandomSalt()
        this.tmpOrder.makerFee = 0
        this.tmpOrder.takerFee = 0
        // moment(this.tmpOrder.date + ' ' + this.tmpOrder.time, 'YYYY-MM-DD HH:mz')
        this.tmpOrder.time = moment().add(1, 'hours').format('HH:mz')
        this.tmpOrder.date = moment().add(1, 'days').format('YYYY-MM-DD')
      } else {
        this.tmpOrder.makerTokenAmount = this.order.makerTokenAmount
        this.tmpOrder.takerTokenAmount = this.order.takerTokenAmount
        this.tmpOrder.maker = this.order.maker
        this.tmpOrder.taker = this.order.taker
        this.tmpOrder.feeRecipient = this.order.feeRecipient
        this.tmpOrder.makerTokenAddress = this.order.makerTokenAddress
        this.tmpOrder.takerTokenAddress = this.order.takerTokenAddress
        this.tmpOrder.salt = this.order.salt
        this.tmpOrder.makerFee = this.order.makerFee
        this.tmpOrder.takerFee = this.order.takerFee
github 0xchange / 0xchange / src / components / Order.vue View on Github external
data () {
    return {
      dialog: false,
      timeMenu: false,
      dateMenu: false,
      tmpOrder: {
        maker: null,
        taker: null,
        feeRecipient: null,
        makerTokenAddress: null,
        takerTokenAddress: null,
        exchangeContractAddress: null,
        salt: ZeroEx.generatePseudoRandomSalt(),
        makerFee: null,
        takerFee: null,
        makerTokenAmount: null,
        takerTokenAmount: null,
        time: null,
        date: null,
        expirationUnixTimestampSec: null
      }
    }
  },
  watch: {