Placing order programatically from c# or different language instead of js

#1

Hi,

I’m trying to develop a trading bot for exchanges using 0x protocol and I’ve stumbled upon a problem of order creating. If I understood it correctly, for order hashing, if I’m using some other programming language instead of javascript, I should write this code for hashing:

  EIP191_HEADER = "\x19\x01";
  EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH=keccak256(abi.encodePacked("EIP712Domain)",string name, ", "string version,", address verifiyingContract",")"));

 byte[] EIP712_DOMAIN_HASH =keccak256(abi.encodePacked(EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH, keccak256(bytes("0x     Protocol")), keccak256(bytes("2")), bytes32(address(this))))

 bytes32 constant EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(
    "Order(",
    "address makerAddress,",
    "address takerAddress,",
    "address feeRecipientAddress,",
    "address senderAddress,",
    "uint256 makerAssetAmount,",
    "uint256 takerAssetAmount,",
    "uint256 makerFee,",
    "uint256 takerFee,",
    "uint256 expirationTimeSeconds,",
    "uint256 salt,",
    "bytes makerAssetData,",
    "bytes takerAssetData",
    ")"));
bytes32 orderHash = keccak256(abi.encodePacked(
    EIP191_HEADER,
    EIP712_DOMAIN_HASH,
    keccak256(abi.encodePacked(
        EIP712_ORDER_SCHEMA_HASH,
        bytes32(order.makerAddress),
        bytes32(order.takerAddress),
        bytes32(order.feeRecipientAddress),
        bytes32(order.senderAddress),
        order.makerAssetAmount,
        order.takerAssetAmount,
        order.makerFee,
        order.takerFee,
        order.expirationTimeSeconds,
        order.salt,
        keccak256(order.makerAssetData),
        keccak256(order.takerAssetData)))));

and then sign it. Didn’t find any instructions for signing. Can order be signed with something similar to ethereumjs ecsign using wallets private key or I have to add some other things?

1 Like
#2

Yep, you can use ecsign with a private key to sign the hash of the order. You then append a byte that represents the type of signature you are using (most likely the EIP712 type).

1 Like
#3

Okay, so after few days of struggle, I’ve managed to generate EC signature, here is the working solution:0xOrderSigning. Maybe it would be of help for someone…

1 Like
#4

This may not be quite what you’re looking for, but at OpenRelay we created massive, which allows for signing orders (and most other order manipulation) on the command line. It wouldn’t let you sign orders in raw C#, but you could call out to execute the command line tool and get the signature back. It’s also designed to work in a unix pipeline fashion, so you could write pipe stages in any language you like, so long as it takes the JSON input / output that it expects.