I found out how to sign an approval into Metamask,in conformity with EIP712:

const domain = [
   { name: "name", type: "string" },
   { name: "version", type: "string" },
   { name: "chainId", type: "uint256" },
   { name: "verifyingContract", type: "address" },
   { name: "salt", type: "bytes32" },
const bid = [

   { name: "makerToken", type: "address" },
   { name: "takerToken", type: "address" },
   { name: "makerAmount", type: "uint256" },
   { name: "takerAmount", type: "uint256" },
   { name: "takerTokenFeeAmount", type: "uint256" },
   { name: "maker", type: "address" },
   {name: "taker", type: "address" },
   {name: "sender", type: "address" },
   {name: "feeRecipient", type: "address" },
   {name: "pool", type: "bytes32" },
   { name: "expiry", type: "uint64" },
   { name: "salt", type: "uint256" },
   {name: "verifyingContract", type: "address" },
   { name: "chainId", type: "uint256" },


const domainData = {
   name: "myDomain",
   version: "1",
   chainId: 56,
   verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
   salt: '0x1656319140'
var message = {
makerToken: '0x55d398326f99059ff775485246999027b3197955',
takerToken: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
makerAmount: '1000000000000000000',
takerAmount: '990000000000000000',
takerTokenFeeAmount: '990000000000000',
maker: '0x1111111111111111111111111111111111111111',  //my address
taker: '0x0000000000000000000000000000000000000000',
sender: '0x0000000000000000000000000000000000000000',
feeRecipient: '0x1111111111111111111111111111111111111111',
pool: '0x0000000000000000000000000000000000000000000000000000000000000037',
expiry: '1656319140',
salt: '0x1656319140',
verifyingContract: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
chainId: '56'

const data = JSON.stringify({
   types: {
       EIP712Domain: domain,
       Bid: bid
   domain: domainData,
   primaryType: "Bid",
   message: message

await web3.currentProvider.sendAsync(
   method: "eth_signTypedData_v3",
   params: [fromAddress, data],
   from: fromAddress
function(err, result) {
   if (err) {
       return console.error(err);

   const signature = result.result.substring(2);
   const r = "0x" + signature.substring(0, 64);
   const s = "0x" + signature.substring(64, 128);
   const v = parseInt(signature.substring(128, 130), 16);
   // The signature is now comprised of r, s, and v.

Then I wrap a JSON and request 0x API for this limit order, with the newly created signature:

json = [
    "makerToken": "0x55d398326f99059ff775485246999027b3197955",
    "takerToken": "0xe9e7cea3dedca5984780bafc599bd69add087d56",
    "makerAmount": "100000000000000000",
    "takerAmount": "99000000000000000",
    "maker": "0x1111111111111111111111111111111111111111",
    "taker": "0x0000000000000000000000000000000000000000",
    "chainId": 56,
    "verifyingContract": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
    "takerTokenFeeAmount": "99000000000000",
    "sender": "0x0000000000000000000000000000000000000000",
    "feeRecipient": "0x1111111111111111111111111111111111111111",
    "pool": "0x0000000000000000000000000000000000000000000000000000000000000037",
    "salt": "0x1656319140",
    "expiry": "1656319140",
    "signature": {
      "r": r,
      "s": s,
      "v": v,
      "signatureType": 2

axios.post('https://bsc.api.0x.org/orderbook/v1/orders', json);

The format of signature is valid (r, s, and v), However, 0x API's answers that the signature is not valid:

{"code":100,"reason":"Validation Failed","validationErrors":[{"code":1005,"field":"signedOrder[0]","reason":"InvalidSignature"}]}

What am I missing ? Should I change the approval's message to fit exactly the JSON request ? (Yet there are extra fields, so i'm not sure...)

Thanks in advance :-)

2 Answers 2


were you able to solve your issue? I see a few orders on https://bsc.api.0x.org/orderbook/v1/orders

(it's the first time I see a few orders there)

Not sure if helpful, but have you checked the docs here? https://docs.0x.org/market-makers/guides/generating-0x-order-hashes


(I have switched to main ETH network)

Yes it's part of the answer but i would need the full signature architecture (what to send and how to send it). Unfortunately there is no way to MITM working signatures through Metamask on other websites, to reverse engeneer that protocole/architecture.

It's actually easier to reverse engineer the 20MB JS file generated by Node.JS on those websites than to browse through your Docs lol

(Not to mention all these 0x github projects, supposed to setup a DEX in a few clicks, but outdated since 2020 lol)

(I am fully aware that i could do it with node.js myself, transpiling a 20MB file but i want my website to be on Apache.)

It's a shame because what you do with a 20MB Node project could be done with a 200KB full JS project.

IMO it's like making things complicated while trying to keep it simple.

Anyhow, at the moment i've got it working, thanks to my reverse engineering skills lol A New DEX is coming soon ;-)

But as soon as I can, i'll update that nasty heavy code to make it lighter.

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.