import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(privateKey);
const orderRequest = {
side: 'BUY',
tokenID: '902348896171994436737091508776752646...',
orderType: 'FOK',
amount: 2,
tickSize: '0.01',
negRisk: true,
slippage: 100,
};
const expiration = Math.floor(Date.now() / 1000) + 60; // 60s in the future
const signatureByEvmEoa = await account.signTypedData({
domain: {
name: 'BoxPolymarketPlaceOrder',
version: '1',
chainId: 137,
},
types: {
PlaceOrder: [
{ name: 'tokenID', type: 'string' },
{ name: 'side', type: 'string' },
{ name: 'orderType', type: 'string' },
{ name: 'amount', type: 'uint256' },
{ name: 'tickSize', type: 'string' },
{ name: 'negRisk', type: 'bool' },
{ name: 'slippage', type: 'uint256' },
{ name: 'expiration', type: 'uint256' },
],
},
primaryType: 'PlaceOrder',
message: {
tokenID: orderRequest.tokenID,
side: orderRequest.side,
orderType: orderRequest.orderType,
amount: BigInt(Math.floor(orderRequest.amount * 1_000_000)),
tickSize: orderRequest.tickSize,
negRisk: orderRequest.negRisk,
slippage: BigInt(orderRequest.slippage),
expiration: BigInt(expiration),
},
});
await fetch('https://api-v2.swaps.xyz/api/workflows/polymarket/placeOrder', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY,
},
body: JSON.stringify({
evmEoa: account.address,
orderRequest,
expiration,
signatureByEvmEoa,
}),
});