我一直在尝试向https://api.openrelay.xyz/v0发送订单 我使用ZeroEx api和@ 0xproject / connect来做到这一点。我正在使用Ropstan测试网络。
以下是我使用的流程和代码:
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; });
这是我面临的问题: 在试图从metamask popup签署订单时,
“zeroEx.signOrderHashAsync”
fucntion返回false而不是返回我应该获取签名的promise,而不是抛出“INVALID SIGNATURE”错误。我也调试了 signOrderHashAsync 函数,我发现订单散列和制造商地址已发送到验证。在这个函数中,他们尝试从orderhash获取制造商地址,然后检查它是否与作为参数传递的制造商地址匹配。但他们不匹配。从我猜测我生成的订单哈希是不对的。但是我使用的是 ZeroEx.getOrderHashHex 函数,它是api函数。我很困惑,我做错了。能帮我指导一下我做错了吗?
Btw我在getOrderHashHex函数中传递的订单对象是:
{"maker":"0xe60c537190939913291db1296a8758b654519e46","taker":"0x0000000000000000000000000000000000000000","makerTokenAddress":"0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d","takerTokenAddress":"0xc778417e063141139fce010982780140aa0cd5ab","makerTokenAmount":"1000000000000000000000","takerTokenAmount":"700000000000000000","expirationUnixTimestampSec":"1524573824","salt":"26688534631002041508252861589623551425355865473398394026271856046218606941399","exchangeContractAddress":"0x479cc461fecd078f766ecc58533d6f69580cf3ac","makerFee":"500000000000000000","takerFee":"0","feeRecipient":"0xc22d5b2951db72b44cfb8089bb8cd374a3c354ea"}
我在这里通过字符串显示它。但在代码中我将它作为对象发送。 我得到的订单哈希是:
“0x7795cee56f6167f6c50f177c08ecc1bffc778456f382b7664d40db42c07eac42”
提前谢谢你。 问候
答案 0 :(得分:1)
我已经解决了。在打电话的时候
zeroEx.signOrderHashAsync(orderHash, order.maker, false);
我发送了第三个参数false。但是当我使用元掩码进行签名时,元掩码正在进行签名。所以我不得不传递第三个参数真值。只需更改代码:
zeroEx.signOrderHashAsync(orderHash, order.maker, true);
这解决了我的问题。 :)