Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/create-order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import "dotenv/config";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dotenv dependency prevents example from running

The example imports dotenv/config to load environment variables, but dotenv is not listed in package.json as a dependency or devDependency. Running npm run example:create-order will fail with a "Cannot find module 'dotenv'" error because the package isn't installed.

Fix in Cursor Fix in Web


import { createLimitOrder, signOrder } from "../src"; // если нужно, изменим путь

function requireEnv(name: string): string {
const value = process.env[name];
if (!value) {
console.error(`[clob-order-utils] Missing required env var: ${name}`);
process.exit(1);
}
return value;
}

async function main() {
const privateKey = requireEnv("PRIVATE_KEY");
const exchangeAddress = requireEnv("EXCHANGE_ADDRESS");
const chainIdRaw = requireEnv("CHAIN_ID");

const chainId = Number(chainIdRaw);
if (!Number.isFinite(chainId)) {
console.error(
`[clob-order-utils] Invalid CHAIN_ID, expected number, got: ${chainIdRaw}`,
);
process.exit(1);
}

const order = createLimitOrder({
marketId: "MARKET_ID_HERE",
outcome: 0,
price: "0.5",
size: "1",
side: "buy",
maker: exchangeAddress,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong address used as order maker

The maker field is set to exchangeAddress, but according to the OrderData model, maker represents "the source of funds for the order" — which is the user's address derived from the private key, not the exchange contract address. The ExchangeOrderBuilder.buildOrder() method validates that the signer matches the maker address, so using the exchange contract address here would either cause signature validation to fail or produce an invalid order that cannot be executed on-chain.

Fix in Cursor Fix in Web

chainId,
});

const signed = await signOrder(order, privateKey);
console.log(JSON.stringify(signed, null, 2));
}

main().catch((err) => {
console.error("[clob-order-utils] Unexpected error:", err);
process.exit(1);
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"build": "make build",
"test": "make test",
"lint": "make lint",
"postbuild": "cp package.json dist && cp README.md dist"
"postbuild": "cp package.json dist && cp README.md dist",
"example:create-order": "ts-node examples/create-order.ts"
},
"dependencies": {
"@ethersproject/providers": "^5.7.2",
Expand Down