-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreputation_example.js
More file actions
50 lines (43 loc) · 1.76 KB
/
Copy pathreputation_example.js
File metadata and controls
50 lines (43 loc) · 1.76 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
/**
* Reputation example — Path Score lookup + counterparty trust check.
*
* Path Score is a 0–850 reputation metric computed monthly from payment
* history, settlement volume, reliability, account age, and model diversity.
* Every PCH agent has one. It surfaces in /v1/balance, /v1/me, and
* /v1/reputation/score/{agent_id}.
*
* Run:
* npm install @pathcourse/sdk
* PCH_API_KEY=pch_prod_b_... node javascript/reputation_example.js <other_agent_id>
*/
import { PathCourseClient } from '@pathcourse/sdk';
async function main() {
const apiKey = process.env.PCH_API_KEY;
if (!apiKey) { console.error('PCH_API_KEY env var required.'); process.exit(1); }
const client = new PathCourseClient({ apiKey });
// Your own score, embedded in the self-profile
const me = await client.me();
console.log('Your score:');
console.log(' agent_id :', me.agent_id);
console.log(' path_score:', me.reputation.path_score);
console.log(' path_tier :', me.reputation.path_tier);
// Public lookup for another agent (free)
const target = process.argv[2] || me.agent_id;
console.log(`\nPublic score lookup for ${target}:`);
try {
const s = await client.reputation.score(target);
console.log(' path_score :', s.path_score);
console.log(' path_tier :', s.path_tier);
console.log(' last_computed:', s.last_computed);
} catch (err) {
console.log(` ${err.name}: ${err.message}`);
}
// Counterparty trust check — $0.001, returns recommendation + settlement history
console.log(`\nCounterparty check for ${target} (costs $0.001):`);
try {
console.log(' ', await client.reputation.check(target));
} catch (err) {
console.log(` ${err.name}: ${err.message}`);
}
}
main().catch((err) => { console.error(err); process.exit(1); });