4. Placing the order
Order creation is happening via a POST request to the following endpoint:
https://api.cow.fi/mainnet/api/v1/orders
The payload needs to be a json encoded object. Our example order would look like this:
1
{
2
"sellToken": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
3
"buyToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
4
"sellAmount": "10000000000",
5
"buyAmount": "4959721654652700610",
6
"receiver": "0x0000000000000000000000000000000000000000",
7
"validTo": 1628035200,
8
"appData": "0xf785fae7a7c5abc49f3cd6a61f6df1ff26433392b066ee9ff2240ff1eb7ab6e4",
9
"feeAmount": "14075734",
10
"kind": "sell",
11
"partiallyFillable": false,
12
"sellTokenBalance": "erc20",
13
"buyTokenBalance": "erc20",
14
"signingScheme": "ethsign",
15
"signature": <0x encoded signature from step 4>
16
"from": "0x55fe002aeff02f77364de339a1292923a15844b8"
17
}
Copied!
Note, that uint256 fields need to be encoded as long decimal strings instead of numbers (validTo however as an integer).
Receiver is optional. If funds are intended to be sent to another account, zero address indicates receiver is same as signer.
The trader address is automatically derived from the signature and thus also optional. Since creating a signature can be prone to errors, we advise you specify the address you intended to use for signing nonetheless so that our API can give you a better error message in case the signature doesn't recover to the expected owner.
By default, funds will be taken from your account via the Vault Relayer and proceeds will be sent to your receiving account. For sell token balance, you can also chose to use your existing Balancer v2 vault's allowance ("external") or internal Balancer v2 balance ("internal"). In this case you don't need to set the VaultRelayer approval from step 1. The buy token can also be transferred into your internal Balancer v2 Vault balance by specifying "buyTokenBalance": "internal".
In case of success the API should return the order UID which you can use to track the status of your order either in the Cow Explorer, or programmatically below:
Copy link