0

I'm trying to create an order in 0x but when I try to sign the order I get INVALID_SIGNATURE error?

I'm using 0x version 2

onSubmit = async (event) => {

    event.preventDefault();

    const { makerAmount, takerAmount, makerToken, takerToken, maker } = this.state;
    const contractAddresses = getContractAddressesForNetworkOrThrow(KOVAN_NETWORK_ID);
    const zrxTokenAddress = contractAddresses.zrxToken;
    const etherTokenAddress = contractAddresses.etherToken
    const contractWrappers = new ContractWrappers(web3Wrapper._provider, { networkId: KOVAN_NETWORK_ID });

    const makerZRXApprovalTxHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(
        zrxTokenAddress,
        maker,
    );

    const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(makerAmount), DECIMALS);

    // the amount the maker wants of taker asset
    const takerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(takerAmount), DECIMALS);

    // 0x v2 uses hex encoded asset data strings to encode all the information needed to identify an asset
    const makerAssetData = assetDataUtils.encodeERC20AssetData(zrxTokenAddress);
    const takerAssetData = assetDataUtils.encodeERC20AssetData(etherTokenAddress);

    // Set up the Order and fill it
    const randomExpiration = getRandomFutureDateInSeconds();
    const exchangeAddress = contractAddresses.exchange;

    // Create the order
    const order = {
        exchangeAddress,
        makerAddress: maker,
        takerAddress: NULL_ADDRESS,
        senderAddress: NULL_ADDRESS,
        feeRecipientAddress: NULL_ADDRESS,
        expirationTimeSeconds: randomExpiration,
        salt: generatePseudoRandomSalt(),
        makerAssetAmount,
        takerAssetAmount,
        makerAssetData,
        takerAssetData,
        makerFee: ZERO,
        takerFee: ZERO,
    };

    // Generate the order hash and sign it
    const orderHashHex = orderHashUtils.getOrderHashHex(order);

    console.log(orderHashHex);
    console.log(maker);
    console.log(web3Wrapper._provider);

    const signature = await signatureUtils.ecSignHashAsync(web3Wrapper._provider, orderHashHex, maker);
    const signedOrder = { ...order, signature };

    const uuidv1 = require('uuid/v1');
    const session = driver.session();
    await session.run(
        'CREATE (a:Order {id:$id, maker:$maker, makerAmount: $makerAmount, takerAmount:$takerAmount, makerToken:$makerToken, takerToken:$takerToken})',
        { id: uuidv1(), maker: maker, makerAmount: makerAmount, takerAmount: takerAmount, makerToken: makerToken, takerToken: takerToken, signedOrder: signedOrder }
    );
    session.close();
    this.setState({ errorMessage: '', makerAmount: 0, takerAmount: 0, makerToken: 'zrx', takerToken: 'weth' });
};
0
0

The problem was with 0x provider I should be used MetamaskSubprovider instead of signerprovider

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.