How to use the 0x.js.transactionHashUtils.getTransactionHashHex 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 / scenarios / execute_transaction_cancel_order.ts View on Github external
let orderInfo = await contractWrappers.exchange.getOrderInfo.callAsync(signedOrder);
    printUtils.printOrderInfos({ order: orderInfo });

    // This is an ABI encoded function call that the taker wishes to perform
    // in this scenario it is a fillOrder
    const cancelData = contractWrappers.exchange.cancelOrder.getABIEncodedTransactionData(signedOrder);
    // Generate a random salt to mitigate replay attacks
    const makerCancelOrderTransactionSalt = generatePseudoRandomSalt();
    // The maker signs the operation data (cancelOrder) with the salt
    const zeroExTransaction = {
        data: cancelData,
        salt: makerCancelOrderTransactionSalt,
        signerAddress: maker,
        verifyingContractAddress: contractAddresses.exchange,
    };
    const executeTransactionHex = transactionHashUtils.getTransactionHashHex(zeroExTransaction);
    const makerCancelOrderSignatureHex = await signatureUtils.ecSignHashAsync(
        providerEngine,
        executeTransactionHex,
        maker,
    );
    // The sender submits this operation via executeTransaction passing in the signature from the taker
    txHash = await contractWrappers.exchange.executeTransaction.validateAndSendTransactionAsync(
        zeroExTransaction.salt,
        zeroExTransaction.signerAddress,
        zeroExTransaction.data,
        makerCancelOrderSignatureHex,
        {
            gas: TX_DEFAULTS.gas,
            from: sender,
        },
    );
github 0xProject / 0x-starter-project / src / scenarios / execute_transaction.ts View on Github external
// in this scenario it is a fillOrder
    const fillData = contractWrappers.exchange.fillOrder.getABIEncodedTransactionData(
        signedOrder,
        takerAssetAmount,
        signedOrder.signature,
    );
    // Generate a random salt to mitigate replay attacks
    const takerTransactionSalt = generatePseudoRandomSalt();
    // The taker signs the operation data (fillOrder) with the salt
    const zeroExTransaction = {
        data: fillData,
        salt: takerTransactionSalt,
        signerAddress: taker,
        verifyingContractAddress: contractAddresses.exchange,
    };
    const executeTransactionHex = transactionHashUtils.getTransactionHashHex(zeroExTransaction);
    const takerSignatureHex = await signatureUtils.ecSignHashAsync(providerEngine, executeTransactionHex, taker);
    // The sender submits this operation via executeTransaction passing in the signature from the taker
    txHash = await contractWrappers.exchange.executeTransaction.validateAndSendTransactionAsync(
        zeroExTransaction.salt,
        zeroExTransaction.signerAddress,
        zeroExTransaction.data,
        takerSignatureHex,
        {
            gas: TX_DEFAULTS.gas,
            from: sender,
        },
    );
    const txReceipt = await printUtils.awaitTransactionMinedSpinnerAsync('executeTransaction', txHash);
    printUtils.printTransaction('Execute Transaction fillOrder', txReceipt, [['orderHash', orderHashHex]]);

    // Print the Balances