checkers-on-stacks 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/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @stack-draft/checkers-sdk
2
+
3
+ JavaScript/TypeScript SDK for interacting with the [Checkers on Stacks](https://github.com/devJaja/Stacks-Draft) smart contract on Stacks mainnet.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @stack-draft/checkers-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { CheckersSDK } from '@stack-draft/checkers-sdk';
15
+
16
+ const sdk = new CheckersSDK();
17
+
18
+ // Get game state
19
+ const game = await sdk.getGame(0);
20
+ console.log(game);
21
+ // { isActive: true, player1: 'SP...', player2: 'SP...', currentTurn: 'SP...', winner: null }
22
+
23
+ // Get full board (64-element array)
24
+ const board = await sdk.getBoard(0);
25
+
26
+ // Get piece at a specific position
27
+ const piece = await sdk.getPiece(0, 17);
28
+ // 0 = empty, 1 = p1, 2 = p1 king, 3 = p2, 4 = p2 king
29
+ ```
30
+
31
+ ## Contract
32
+
33
+ Deployed on Stacks mainnet: `SP2DWWDVSSKZ5X37BBV3RV0GY0A0FFZZESYHEVQZ9.checkers`
34
+
35
+ ## License
36
+
37
+ MIT
@@ -0,0 +1,30 @@
1
+ import { StacksNetwork } from '@stacks/network';
2
+ export declare const CONTRACT_ADDRESS = "SP2DWWDVSSKZ5X37BBV3RV0GY0A0FFZZESYHEVQZ9";
3
+ export declare const CONTRACT_NAME = "checkers";
4
+ export type PieceType = 0 | 1 | 2 | 3 | 4;
5
+ export interface GameState {
6
+ isActive: boolean;
7
+ player1: string;
8
+ player2: string | null;
9
+ currentTurn: string;
10
+ winner: string | null;
11
+ }
12
+ export interface CheckersSDKOptions {
13
+ network?: StacksNetwork;
14
+ contractAddress?: string;
15
+ contractName?: string;
16
+ }
17
+ export declare class CheckersSDK {
18
+ private network;
19
+ private contractAddress;
20
+ private contractName;
21
+ constructor(options?: CheckersSDKOptions);
22
+ private readOnly;
23
+ /** Get game state by ID. Returns null if game does not exist. */
24
+ getGame(gameId: number): Promise<GameState | null>;
25
+ /** Get the piece type at a board position (0–63). */
26
+ getPiece(gameId: number, position: number): Promise<PieceType>;
27
+ /** Get the full 64-square board as an array of PieceType. */
28
+ getBoard(gameId: number): Promise<PieceType[]>;
29
+ }
30
+ export default CheckersSDK;
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckersSDK = exports.CONTRACT_NAME = exports.CONTRACT_ADDRESS = void 0;
4
+ const transactions_1 = require("@stacks/transactions");
5
+ const network_1 = require("@stacks/network");
6
+ exports.CONTRACT_ADDRESS = 'SP2DWWDVSSKZ5X37BBV3RV0GY0A0FFZZESYHEVQZ9';
7
+ exports.CONTRACT_NAME = 'checkers';
8
+ class CheckersSDK {
9
+ constructor(options = {}) {
10
+ var _a, _b, _c;
11
+ this.network = (_a = options.network) !== null && _a !== void 0 ? _a : new network_1.StacksMainnet();
12
+ this.contractAddress = (_b = options.contractAddress) !== null && _b !== void 0 ? _b : exports.CONTRACT_ADDRESS;
13
+ this.contractName = (_c = options.contractName) !== null && _c !== void 0 ? _c : exports.CONTRACT_NAME;
14
+ }
15
+ async readOnly(fn, args) {
16
+ return (0, transactions_1.callReadOnlyFunction)({
17
+ network: this.network,
18
+ contractAddress: this.contractAddress,
19
+ contractName: this.contractName,
20
+ functionName: fn,
21
+ functionArgs: args,
22
+ senderAddress: this.contractAddress,
23
+ });
24
+ }
25
+ /** Get game state by ID. Returns null if game does not exist. */
26
+ async getGame(gameId) {
27
+ var _a, _b, _c, _d;
28
+ const result = (0, transactions_1.cvToJSON)(await this.readOnly('get-game', [(0, transactions_1.uintCV)(gameId)]));
29
+ if (!result.value)
30
+ return null;
31
+ const v = result.value;
32
+ return {
33
+ isActive: v['is-active'].value,
34
+ player1: v['player1'].value,
35
+ player2: (_b = (_a = v['player2'].value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null,
36
+ currentTurn: v['current-turn'].value,
37
+ winner: (_d = (_c = v['winner'].value) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null,
38
+ };
39
+ }
40
+ /** Get the piece type at a board position (0–63). */
41
+ async getPiece(gameId, position) {
42
+ const result = (0, transactions_1.cvToJSON)(await this.readOnly('get-piece', [(0, transactions_1.uintCV)(gameId), (0, transactions_1.uintCV)(position)]));
43
+ return result.value;
44
+ }
45
+ /** Get the full 64-square board as an array of PieceType. */
46
+ async getBoard(gameId) {
47
+ const result = (0, transactions_1.cvToJSON)(await this.readOnly('get-board', [(0, transactions_1.uintCV)(gameId)]));
48
+ const board = Array(64).fill(0);
49
+ if (result.success && result.value) {
50
+ Object.keys(result.value).forEach((key) => {
51
+ const pos = parseInt(key.replace('p', ''));
52
+ const val = result.value[key];
53
+ board[pos] = (typeof val === 'object' ? val.value : val);
54
+ });
55
+ }
56
+ return board;
57
+ }
58
+ }
59
+ exports.CheckersSDK = CheckersSDK;
60
+ exports.default = CheckersSDK;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "checkers-on-stacks",
3
+ "version": "1.0.0",
4
+ "description": "JavaScript/TypeScript SDK for interacting with the Checkers on Stacks smart contract",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "keywords": [
15
+ "stacks",
16
+ "blockchain",
17
+ "checkers",
18
+ "draughts",
19
+ "clarity",
20
+ "web3",
21
+ "bitcoin"
22
+ ],
23
+ "author": "devJaja",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/devJaja/Stacks-Draft.git"
28
+ },
29
+ "homepage": "https://github.com/devJaja/Stacks-Draft#readme",
30
+ "peerDependencies": {
31
+ "@stacks/network": ">=6.0.0",
32
+ "@stacks/transactions": ">=6.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@stacks/network": "6.13.0",
36
+ "@stacks/transactions": "6.13.0",
37
+ "typescript": "5.4.5"
38
+ }
39
+ }