3. Signing the order
We will resume the example from above, setting the validity (Unix timestamp) to August 4th 2021. We use `keccak(GPv2 Place Order Tutorial)` as appData (you can use your individual 32 bytes to identify the “source” of your orders).
Our typescript library provides a convenient way to create valid signatures for your order.
1
import {
2
domain,
3
Order,
4
SigningScheme,
5
signOrder,
6
} from "@gnosis.pm/gp-v2-contracts"
7
8
const [trader] = await ethers.getSigners();
9
const order = {
10
sellToken: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,
11
buyToken: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,
12
sellAmount: 10000000000,
13
buyAmount: 4959721654652700610,
14
validTo: 1628035200,
15
appData: 0xf785fae7a7c5abc49f3cd6a61f6df1ff26433392b066ee9ff2240ff1eb7ab6e4,
16
feeAmount: 14075734,
17
kind: OrderKind.SELL,
18
partiallyFillable: false,
19
receiver: ethers.constants.AddressZero,
20
}
21
const raw_signature = await signOrder(
22
domain(1,0x9008D19f58AAbD9eD0D60971565AA8510560ab41),
23
order,
24
trader,
25
SigningScheme.ETHSIGN
26
);
27
// Needed to turn the three part object into a single bytestring
28
const signature = ethers.utils.joinSignature(rawSignature.data);
Copied!
If you are using a different programming language you may have to write your own signing logic. Here are some pointers:
The ultimate source of truth for signature verification is the smart contract’s implementation of the order digest and how it gets verified given different signing schemes.
Copy link