-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_credentials.cpp
More file actions
61 lines (50 loc) · 2.1 KB
/
06_credentials.cpp
File metadata and controls
61 lines (50 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Derive Polymarket API credentials from your private key.
//
// Only needs your private key — derives the API key, secret, and passphrase
// that you can then use in authenticated endpoints (order placement, etc.).
//
// Run:
// export POLY_PRIVATE_KEY="0x..."
// ./demo
//
// Output will be ready-to-paste export commands.
#include <polymarket/clob/clob_client.hpp>
#include <polymarket/crypto/signer.hpp>
#include <polymarket/auth/l2_auth.hpp>
#include <cstdio>
#include <cstdlib>
using namespace polymarket;
int main() {
const char* pk = std::getenv("POLY_PRIVATE_KEY");
if (!pk || *pk == '\0') {
fprintf(stderr, "Set POLY_PRIVATE_KEY first:\n");
fprintf(stderr, " export POLY_PRIVATE_KEY=\"0x...\"\n");
return 1;
}
Signer signer(pk);
printf("EOA address: %s\n", signer.address_hex().c_str());
ClobClient clob;
// ── Try to derive existing credentials ───────────────────────────────────
// If you already ran this once, derive returns the same deterministic key.
printf("\nDeriving API credentials...\n");
auto r = clob.derive_api_key(signer);
if (!r) {
// First time — no key exists yet, create one.
printf("Not found, creating new credentials...\n");
r = clob.create_api_key(signer);
}
if (!r) {
fprintf(stderr, "Failed: %s\n", r.error().message().c_str());
return 1;
}
Credentials creds = *r;
// ── Print ready-to-use export commands ───────────────────────────────────
printf("\n=== Copy-paste these into your shell ===\n\n");
printf("export POLY_PRIVATE_KEY=\"%s\"\n", pk);
printf("export POLY_API_KEY=\"%s\"\n", creds.apiKey.c_str());
printf("export POLY_SECRET=\"%s\"\n", creds.secret.c_str());
printf("export POLY_PASSPHRASE=\"%s\"\n", creds.passphrase.c_str());
printf("\n# (set POLY_PROXY_WALLET separately — find it on polymarket.com → Profile)\n");
cleanse_credentials(creds);
return 0;
}