Need Help on implementing 0x protocol


#1

I’ve been trying to send a order to https://api.openrelay.xyz/v0
I’ve used ZeroEx api and @0xproject/connect to do this. And I’m using Ropstan Test Network.

Here is the flow and code I’ve used:

  1. firstly I’ve created an order object:
 var order = {
            maker: web3.eth.accounts[0],
            taker: "0x0000000000000000000000000000000000000000",
            makerTokenAddress: "0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d",
            takerTokenAddress: "0xc778417e063141139fce010982780140aa0cd5ab",
            makerTokenAmount: new BigNumber("1000000000000000000000"),
            takerTokenAmount: new BigNumber("700000000000000000"),
            expirationUnixTimestampSec: parseInt(
                (new Date().getTime()/1000) + duration
            ).toString(),
            salt: ZeroEx.generatePseudoRandomSalt()
        }
  1. Then add exchangeContractAddress property to order object:

order.exchangeContractAddress = zeroEx.exchange.getContractAddress();

  1. Add some other fees properties with getFeesAsync method:
    var feePr = httpClient.getFeesAsync(order).then(function(feeResponse) {
        order.makerFee = new BigNumber(feeResponse.makerFee || 0); 
        order.takerFee = new BigNumber(feeResponse.takerFee || 0); 
        order.taker = feeResponse.takerToSpecify;
        order.feeRecipient = feeResponse.feeRecipient || ZeroEx.NULL_ADDRESS;
    });
  1. Then Trying to sign the order so that I can send order to openrelay server:
    Promise.all([feePr]).then(() => {
		    var orderHash = ZeroEx.getOrderHashHex(order);
		    return zeroEx.signOrderHashAsync(orderHash, order.maker, false);
	    }).then((signature) => {
		    order.ecSignature = signature;
		    validSignature = zeroEx.exchange.validateOrderFillableOrThrowAsync(order);
		    return order;
	    });

Here is the problem I’m facing:
while trying to sign order from metamask popup, the “zeroEx.signOrderHashAsync” fucntion is returning false instead of returing a promise in which I should get the signature, rather than it is throwing an error of “INVALID SIGNATURE”. I’ve debugged the signOrderHashAsync function too where I found that the order hash and maker address sent to validated. In this function they try to get the maker address from orderhash and then check wheather it matches with the maker address that is passed as argument. but they dont match. From where I guesed that the order hash I’m generating is not right. But I’m using ZeroEx.getOrderHashHex function which is the api function. I’m confused where I’m doing wrong. Can you please help me guiding about where I’m doing wrong.

Btw The order object that I’m passing in getOrderHashHex function is :

{"maker":"0xe60c537190939913291db1296a8758b654519e46","taker":"0x0000000000000000000000000000000000000000","makerTokenAddress":"0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d","takerTokenAddress":"0xc778417e063141139fce010982780140aa0cd5ab","makerTokenAmount":"1000000000000000000000","takerTokenAmount":"700000000000000000","expirationUnixTimestampSec":"1524573824","salt":"26688534631002041508252861589623551425355865473398394026271856046218606941399","exchangeContractAddress":"0x479cc461fecd078f766ecc58533d6f69580cf3ac","makerFee":"500000000000000000","takerFee":"0","feeRecipient":"0xc22d5b2951db72b44cfb8089bb8cd374a3c354ea"}

Here I’m showing it by stringifying. but in code I’m sending it as object.
And the order hash I’m getting is:
"0x7795cee56f6167f6c50f177c08ecc1bffc778456f382b7664d40db42c07eac42"

Thank you in advance.
regards


#2

Can you try return zeroEx.signOrderHashAsync(orderHash, order.maker, true); ?

Also, it might be good to ask this question in the #dev channel on https://chat.0xproject.com if you haven’t already. You should get a much faster response!


#3

Thanks for your reply. Yeah I’ve tried your solutions and it works fine. Thanks a lot
regards

Mahbubul