import { Wallet, hexlify, randomBytes } from "ethers";
const wallet = new Wallet(process.env.SX_PRIVATE_KEY);
const orderHashes = [
"0x550128e997978495eeae503c13e2e30243d747e969c65e1a0b565c609e097506",
];
const salt = hexlify(randomBytes(32));
const timestamp = Math.floor(Date.now() / 1000);
const chainId = 4162; // Mainnet — use 79479957 for testnet
const domain = {
name: "CancelOrderV2SportX",
version: "1.0",
chainId,
salt,
};
const types = {
Details: [
{ name: "orderHashes", type: "string[]" },
{ name: "timestamp", type: "uint256" },
],
};
const signature = await wallet.signTypedData(domain, types, { orderHashes, timestamp });
const result = await fetch("https://api.sx.bet/orders/cancel/v2", { // Mainnet — use https://api.toronto.sx.bet for testnet
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
orderHashes,
signature,
salt,
maker: wallet.address,
timestamp,
}),
});
console.log(await result.json());