I used this code to fill an order, but it did not work. Can anyone help?

import { BigNumber, providerUtils } from '@0x/utils';
async function fill() {
  const utils = require("@0x/protocol-utils");
  const order = new utils.LimitOrder({
                  sender: "0x0000000000000000000000000000000000000000",
                  maker: "0x55c18a6d97e738d27b29ecd7018e04ef2da8ff0a",
                  taker: "0x0000000000000000000000000000000000000000",
                  takerTokenFeeAmount: "0",
                  makerAmount: "2600",
                  takerAmount: "2600",
                  makerToken: "0xad6d458402f60fd3bd25163575031acdce07538d",
                  takerToken: "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
                  salt: "0",
                  verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
                  feeRecipient: "0x0000000000000000000000000000000000000000",
                  expiry: "2014956256",
                  chainId: 3,
                  pool: "0x0000000000000000000000000000000000000000000000000000000000000000"
  const signature2 = await order.getSignatureWithKey(<my private key>,  utils.SignatureType.EIP712);
  const wrappers = require("@0x/contract-wrappers");
  var Web3 = require('web3');
  var web3 = new Web3(Web3.givenProvider || 'http://localhost:8545/');
  const supportedProvider = providerUtils.standardizeOrThrow(web3.currentProvider)
  const exchange = new wrappers.IZeroExContract("0xdef1c0ded9bec7f1a1670819833240f027b25eff", supportedProvider);
  const amount = new BigNumber(1);
  const res = await exchange.fillLimitOrder(order, signature2, amount);
fill().catch((err) => console.error(err));



1 Answer 1


So here you are filling an order that you created yourself. I guess this is only for testing purposes, as usually orders are taken from the open orderbook available on the 0x API https://0x.org/docs/api#get-srav4orderbook

In order to fill an existing order, you need to pay the 0x protocol fee (in ETH) and so the submitted transaction needs to contain a value field where the amount is equal to gasPrice * feeMultiplier

the feeMultiplier value can queried from the exchange contract by calling getProtocolFeeMultiplier()

  • Can you give me an example of code? I have never done it before.
    – notooth
    Commented Sep 2, 2021 at 5:28
  • yeah will take me sometime as there is no available tutorial I can share at the moment. sorry for that
    – 0xSHA
    Commented Sep 8, 2021 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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