Web3js
ecSignHashAsync() 給出 INVALID_SIGNATURE 錯誤
我正在嘗試在 0x 中創建訂單,但是當我嘗試簽署訂單時
INVALID_SIGNATURE
出現錯誤?我正在使用 0x 版本 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' }); };
問題出在 0x 提供程序上,我應該使用 MetamaskSubprovider 而不是 signerprovider