gem-pluck-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wurlelham531-svg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # gem-pluck-sdk
2
+
3
+ TypeScript SDK for interacting with the **Gem Pluck** smart contract on Stacks blockchain.
4
+
5
+ Gem Pluck is an on-chain pluck-a-gem dApp with 6 gems (Ruby, Sapphire, Emerald, Topaz, Amethyst, Onyx). Each pluck is recorded on Stacks mainnet (Clarity 4).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install gem-pluck-sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { GemPluckClient } from "gem-pluck-sdk";
17
+
18
+ const client = new GemPluckClient({
19
+ contractAddress: "SP16F6839630K5XX06KE7KVNSNMYBK89912NH6N4C",
20
+ contractName: "gem-pluck",
21
+ });
22
+
23
+ // Get count for gem #1 (Ruby)
24
+ const ruby = await client.getGemCount(1);
25
+ console.log(`Ruby: ${ruby.count}`);
26
+
27
+ // Get all 6 gem counts in parallel
28
+ const all = await client.getAllGemCounts();
29
+
30
+ // Total plucks across all gems
31
+ const total = await client.getTotalPlucks();
32
+
33
+ // Per-user stats
34
+ const me = await client.getUserStats("SP...");
35
+
36
+ // Leaderboard, sorted by count desc
37
+ const board = await client.getLeaderboard();
38
+
39
+ // Build pluck transaction args (use with @stacks/connect)
40
+ const args = client.getPluckArgs(3); // pluck Emerald
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### `new GemPluckClient(config)`
46
+
47
+ | Param | Type | Description |
48
+ |-------|------|-------------|
49
+ | `contractAddress` | `string` | Deployer's Stacks address |
50
+ | `contractName` | `string` | Contract name |
51
+ | `network` | `"mainnet" \| "testnet"` | Network (default: `"mainnet"`) |
52
+
53
+ ### Methods
54
+
55
+ | Method | Returns |
56
+ |--------|---------|
57
+ | `getGemCount(gemId)` | `Promise<GemCount>` |
58
+ | `getAllGemCounts()` | `Promise<GemCount[]>` |
59
+ | `getTotalPlucks()` | `Promise<number>` |
60
+ | `getUserStats(address)` | `Promise<UserStats>` |
61
+ | `getLeaderboard()` | `Promise<(GemCount & { name: string })[]>` |
62
+ | `getPluckArgs(gemId)` | Args for `openContractCall` |
63
+
64
+ ### Constants
65
+
66
+ ```typescript
67
+ import { GEMS } from "gem-pluck-sdk";
68
+ // [{ id: 1, name: "Ruby", color: "#e02060" }, ...]
69
+ ```
70
+
71
+ ## License
72
+
73
+ MIT
@@ -0,0 +1,39 @@
1
+ import { GemCount, UserStats, GemPluckConfig } from "./types";
2
+ export declare class GemPluckClient {
3
+ private contractAddress;
4
+ private contractName;
5
+ private network;
6
+ constructor(config: GemPluckConfig);
7
+ /**
8
+ * Get the pluck count for a specific gem (1-6).
9
+ */
10
+ getGemCount(gemId: number): Promise<GemCount>;
11
+ /**
12
+ * Get counts for all six gems in parallel.
13
+ */
14
+ getAllGemCounts(): Promise<GemCount[]>;
15
+ /**
16
+ * Get total plucks across all gems.
17
+ */
18
+ getTotalPlucks(): Promise<number>;
19
+ /**
20
+ * Get a user's pluck history (total + last gem).
21
+ */
22
+ getUserStats(address: string): Promise<UserStats>;
23
+ /**
24
+ * Leaderboard — gems sorted by pluck count (descending), with names.
25
+ */
26
+ getLeaderboard(): Promise<(GemCount & {
27
+ name: string;
28
+ })[]>;
29
+ /**
30
+ * Build the function args needed for a pluck transaction.
31
+ * Use with @stacks/connect openContractCall().
32
+ */
33
+ getPluckArgs(gemId: number): {
34
+ contractAddress: string;
35
+ contractName: string;
36
+ functionName: string;
37
+ functionArgs: import("@stacks/transactions").UIntCV[];
38
+ };
39
+ }
package/dist/client.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GemPluckClient = void 0;
4
+ const transactions_1 = require("@stacks/transactions");
5
+ const network_1 = require("@stacks/network");
6
+ const types_1 = require("./types");
7
+ class GemPluckClient {
8
+ constructor(config) {
9
+ this.contractAddress = config.contractAddress;
10
+ this.contractName = config.contractName;
11
+ this.network =
12
+ config.network === "testnet" ? new network_1.StacksTestnet() : new network_1.StacksMainnet();
13
+ }
14
+ /**
15
+ * Get the pluck count for a specific gem (1-6).
16
+ */
17
+ async getGemCount(gemId) {
18
+ var _a, _b;
19
+ if (gemId < 1 || gemId > 6) {
20
+ throw new Error("Gem ID must be between 1 and 6");
21
+ }
22
+ try {
23
+ const result = await (0, transactions_1.callReadOnlyFunction)({
24
+ network: this.network,
25
+ contractAddress: this.contractAddress,
26
+ contractName: this.contractName,
27
+ functionName: "get-gem-count",
28
+ functionArgs: [(0, transactions_1.uintCV)(gemId)],
29
+ senderAddress: this.contractAddress,
30
+ });
31
+ const json = (0, transactions_1.cvToJSON)(result);
32
+ const count = parseInt((_b = (_a = json.value) !== null && _a !== void 0 ? _a : json) !== null && _b !== void 0 ? _b : "0");
33
+ return { gemId, count };
34
+ }
35
+ catch (_c) {
36
+ return { gemId, count: 0 };
37
+ }
38
+ }
39
+ /**
40
+ * Get counts for all six gems in parallel.
41
+ */
42
+ async getAllGemCounts() {
43
+ const promises = Array.from({ length: 6 }, (_, i) => this.getGemCount(i + 1));
44
+ return Promise.all(promises);
45
+ }
46
+ /**
47
+ * Get total plucks across all gems.
48
+ */
49
+ async getTotalPlucks() {
50
+ var _a, _b;
51
+ try {
52
+ const result = await (0, transactions_1.callReadOnlyFunction)({
53
+ network: this.network,
54
+ contractAddress: this.contractAddress,
55
+ contractName: this.contractName,
56
+ functionName: "total",
57
+ functionArgs: [],
58
+ senderAddress: this.contractAddress,
59
+ });
60
+ const json = (0, transactions_1.cvToJSON)(result);
61
+ return parseInt((_b = (_a = json.value) !== null && _a !== void 0 ? _a : json) !== null && _b !== void 0 ? _b : "0");
62
+ }
63
+ catch (_c) {
64
+ return 0;
65
+ }
66
+ }
67
+ /**
68
+ * Get a user's pluck history (total + last gem).
69
+ */
70
+ async getUserStats(address) {
71
+ var _a, _b, _c, _d;
72
+ try {
73
+ const [pluckRes, lastRes] = await Promise.all([
74
+ (0, transactions_1.callReadOnlyFunction)({
75
+ network: this.network,
76
+ contractAddress: this.contractAddress,
77
+ contractName: this.contractName,
78
+ functionName: "get-user-plucks",
79
+ functionArgs: [(0, transactions_1.principalCV)(address)],
80
+ senderAddress: this.contractAddress,
81
+ }),
82
+ (0, transactions_1.callReadOnlyFunction)({
83
+ network: this.network,
84
+ contractAddress: this.contractAddress,
85
+ contractName: this.contractName,
86
+ functionName: "get-user-last-gem",
87
+ functionArgs: [(0, transactions_1.principalCV)(address)],
88
+ senderAddress: this.contractAddress,
89
+ }),
90
+ ]);
91
+ const pluckJson = (0, transactions_1.cvToJSON)(pluckRes);
92
+ const lastJson = (0, transactions_1.cvToJSON)(lastRes);
93
+ const totalPlucks = parseInt((_b = (_a = pluckJson.value) !== null && _a !== void 0 ? _a : pluckJson) !== null && _b !== void 0 ? _b : "0");
94
+ const lastRaw = (_d = (_c = lastJson === null || lastJson === void 0 ? void 0 : lastJson.value) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : lastJson === null || lastJson === void 0 ? void 0 : lastJson.value;
95
+ const lastGem = lastRaw && lastRaw !== null && lastRaw !== undefined
96
+ ? parseInt(lastRaw)
97
+ : null;
98
+ return { totalPlucks, lastGem: isNaN(lastGem) ? null : lastGem };
99
+ }
100
+ catch (_e) {
101
+ return { totalPlucks: 0, lastGem: null };
102
+ }
103
+ }
104
+ /**
105
+ * Leaderboard — gems sorted by pluck count (descending), with names.
106
+ */
107
+ async getLeaderboard() {
108
+ const counts = await this.getAllGemCounts();
109
+ return counts
110
+ .map((c) => {
111
+ var _a, _b;
112
+ return (Object.assign(Object.assign({}, c), { name: (_b = (_a = types_1.GEMS.find((g) => g.id === c.gemId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : `Gem ${c.gemId}` }));
113
+ })
114
+ .sort((a, b) => b.count - a.count);
115
+ }
116
+ /**
117
+ * Build the function args needed for a pluck transaction.
118
+ * Use with @stacks/connect openContractCall().
119
+ */
120
+ getPluckArgs(gemId) {
121
+ if (gemId < 1 || gemId > 6) {
122
+ throw new Error("Gem ID must be between 1 and 6");
123
+ }
124
+ return {
125
+ contractAddress: this.contractAddress,
126
+ contractName: this.contractName,
127
+ functionName: "pluck",
128
+ functionArgs: [(0, transactions_1.uintCV)(gemId)],
129
+ };
130
+ }
131
+ }
132
+ exports.GemPluckClient = GemPluckClient;
@@ -0,0 +1,2 @@
1
+ export { GemPluckClient } from "./client";
2
+ export { GemCount, UserStats, GemInfo, GemPluckConfig, GEMS } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GEMS = exports.GemPluckClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "GemPluckClient", { enumerable: true, get: function () { return client_1.GemPluckClient; } });
6
+ var types_1 = require("./types");
7
+ Object.defineProperty(exports, "GEMS", { enumerable: true, get: function () { return types_1.GEMS; } });
@@ -0,0 +1,19 @@
1
+ export interface GemCount {
2
+ gemId: number;
3
+ count: number;
4
+ }
5
+ export interface UserStats {
6
+ totalPlucks: number;
7
+ lastGem: number | null;
8
+ }
9
+ export interface GemInfo {
10
+ id: number;
11
+ name: string;
12
+ color: string;
13
+ }
14
+ export interface GemPluckConfig {
15
+ contractAddress: string;
16
+ contractName: string;
17
+ network?: "mainnet" | "testnet";
18
+ }
19
+ export declare const GEMS: GemInfo[];
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GEMS = void 0;
4
+ exports.GEMS = [
5
+ { id: 1, name: "Ruby", color: "#e02060" },
6
+ { id: 2, name: "Sapphire", color: "#2060e0" },
7
+ { id: 3, name: "Emerald", color: "#20c060" },
8
+ { id: 4, name: "Topaz", color: "#e0a020" },
9
+ { id: 5, name: "Amethyst", color: "#a020e0" },
10
+ { id: 6, name: "Onyx", color: "#404040" },
11
+ ];
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "gem-pluck-sdk",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for interacting with the Gem Pluck smart contract on Stacks blockchain",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "prepare": "npm run build",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "stacks",
15
+ "blockchain",
16
+ "clarity",
17
+ "smart-contract",
18
+ "sdk",
19
+ "web3",
20
+ "gems"
21
+ ],
22
+ "author": "wurlelham531-svg",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/wurlelham531-svg/gem-pluck-sdk"
27
+ },
28
+ "dependencies": {
29
+ "@stacks/transactions": "^6.0.0",
30
+ "@stacks/network": "^6.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.0.0"
34
+ }
35
+ }