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:
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() }
order.exchangeContractAddress = zeroEx.exchange.getContractAddress();
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; });
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 returning 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 whether it matches with the maker address that is passed as argument. but they don't match. From where I guessed 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
I've solved it. while calling
zeroEx.signOrderHashAsync(orderHash, order.maker, false);
I was sending the third parameter false. But as I'm using metamask for signing, metamask is putting thier signature. so I had to pass third parameter true value. Just change the code with:
zeroEx.signOrderHashAsync(orderHash, order.maker, true);
This solved my problem. :)