dice-roll-sdk 1.0.0 → 1.0.2

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 brventonbeshers-ship-it
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 CHANGED
@@ -1,23 +1,25 @@
1
- # dice-roll-sdk
2
-
3
- TypeScript SDK for interacting with the Dice Roll contract on Stacks.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install dice-roll-sdk
9
- ```
10
-
11
- ## Usage
12
-
13
- ```ts
14
- import { getLeaderboard, getTotalRolls, createRollCall } from "dice-roll-sdk";
15
-
16
- const total = await getTotalRolls();
17
- const leaderboard = await getLeaderboard();
18
- const tx = createRollCall();
19
- ```
20
-
21
- ## License
22
-
23
- MIT
1
+ [![npm](https://img.shields.io/npm/v/dice-roll-sdk?color=blueviolet)](https://www.npmjs.com/package/dice-roll-sdk) ![Stacks Mainnet](https://img.shields.io/badge/Stacks-Mainnet-blueviolet) ![license](https://img.shields.io/badge/license-MIT-blue)
2
+
3
+ # dice-roll-sdk
4
+
5
+ TypeScript SDK for interacting with the Dice Roll contract on Stacks.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install dice-roll-sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { getLeaderboard, getTotalRolls, createRollCall } from "dice-roll-sdk";
17
+
18
+ const total = await getTotalRolls();
19
+ const leaderboard = await getLeaderboard();
20
+ const tx = createRollCall();
21
+ ```
22
+
23
+ ## License
24
+
25
+ MIT
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "dice-roll-sdk",
3
- "version": "1.0.0",
4
- "description": "TypeScript SDK for interacting with the Dice Roll smart contract on Stacks blockchain",
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
- "dice-roll",
18
- "sdk",
19
- "smart-contract",
20
- "web3",
21
- "dapp",
22
- "stacks-blockchain",
23
- "typescript",
24
- "on-chain",
25
- "dice-game"
26
- ],
27
- "author": "brventonbeshers-ship-it",
28
- "license": "MIT",
29
- "repository": {
30
- "type": "git",
31
- "url": "git+https://github.com/brventonbeshers-ship-it/dice-roll-sdk.git"
32
- },
33
- "bugs": {
34
- "url": "https://github.com/brventonbeshers-ship-it/dice-roll-sdk/issues"
35
- },
36
- "homepage": "https://github.com/brventonbeshers-ship-it/dice-roll-sdk#readme",
37
- "engines": {
38
- "node": ">=18.0.0"
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "dependencies": {
44
- "@stacks/network": "^7.3.1",
45
- "@stacks/transactions": "^7.3.1"
46
- },
47
- "devDependencies": {
48
- "typescript": "^5.0.0"
49
- }
50
- }
1
+ {
2
+ "name": "dice-roll-sdk",
3
+ "version": "1.0.2",
4
+ "description": "TypeScript SDK for interacting with the Dice Roll smart contract on Stacks blockchain",
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
+ "dice-roll",
18
+ "sdk",
19
+ "smart-contract",
20
+ "web3",
21
+ "dapp",
22
+ "stacks-blockchain",
23
+ "typescript",
24
+ "on-chain",
25
+ "dice-game"
26
+ ],
27
+ "author": "brventonbeshers-ship-it",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/brventonbeshers-ship-it/dice-roll-sdk.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/brventonbeshers-ship-it/dice-roll-sdk/issues"
35
+ },
36
+ "homepage": "https://github.com/brventonbeshers-ship-it/dice-roll-sdk#readme",
37
+ "engines": {
38
+ "node": ">=18.0.0"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@stacks/network": "^7.3.1",
45
+ "@stacks/transactions": "^7.3.1"
46
+ },
47
+ "devDependencies": {
48
+ "typescript": "^5.0.0"
49
+ }
50
+ }
package/dist/client.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { DiceRollConfig, LeaderEntry, ReadOnlyResponse, RollCall } from "./types";
2
- export declare const DEFAULT_CONFIG: Required<DiceRollConfig>;
3
- export declare function callReadOnly(functionName: string, args?: string[], config?: DiceRollConfig): Promise<ReadOnlyResponse>;
4
- export declare function getTotalRolls(config?: DiceRollConfig): Promise<number>;
5
- export declare function getUserRolls(userAddress: string, config?: DiceRollConfig): Promise<number>;
6
- export declare function getUserLastResult(userAddress: string, config?: DiceRollConfig): Promise<number>;
7
- export declare function getLeaderboard(config?: DiceRollConfig): Promise<LeaderEntry[]>;
8
- export declare function createRollCall(config?: DiceRollConfig): RollCall;
9
- export declare class DiceRollClient {
10
- private readonly config;
11
- constructor(config?: DiceRollConfig);
12
- getTotalRolls(): Promise<number>;
13
- getUserRolls(userAddress: string): Promise<number>;
14
- getUserLastResult(userAddress: string): Promise<number>;
15
- getLeaderboard(): Promise<LeaderEntry[]>;
16
- createRollCall(): RollCall;
17
- }
package/dist/client.js DELETED
@@ -1,136 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiceRollClient = exports.DEFAULT_CONFIG = void 0;
4
- exports.callReadOnly = callReadOnly;
5
- exports.getTotalRolls = getTotalRolls;
6
- exports.getUserRolls = getUserRolls;
7
- exports.getUserLastResult = getUserLastResult;
8
- exports.getLeaderboard = getLeaderboard;
9
- exports.createRollCall = createRollCall;
10
- const network_1 = require("@stacks/network");
11
- const transactions_1 = require("@stacks/transactions");
12
- exports.DEFAULT_CONFIG = {
13
- contractAddress: "SP1Q7YR67R6WGP28NXDJD1WZ11REPAAXRJJ3V6RKM",
14
- contractName: "dice-roll",
15
- apiBase: "https://api.mainnet.hiro.so",
16
- network: network_1.STACKS_MAINNET,
17
- };
18
- function resolveConfig(overrides = {}) {
19
- return { ...exports.DEFAULT_CONFIG, ...overrides };
20
- }
21
- function serializeCvToHex(cv) {
22
- const serialized = (0, transactions_1.serializeCV)(cv);
23
- if (typeof serialized === "string") {
24
- return serialized.startsWith("0x") ? serialized : `0x${serialized}`;
25
- }
26
- return `0x${Buffer.from(serialized).toString("hex")}`;
27
- }
28
- async function callReadOnly(functionName, args = [], config = {}) {
29
- const resolved = resolveConfig(config);
30
- const response = await fetch(`${resolved.apiBase}/v2/contracts/call-read/${resolved.contractAddress}/${resolved.contractName}/${functionName}`, {
31
- method: "POST",
32
- headers: { "Content-Type": "application/json" },
33
- body: JSON.stringify({
34
- sender: resolved.contractAddress,
35
- arguments: args,
36
- }),
37
- });
38
- if (!response.ok) {
39
- throw new Error(`Read-only call failed with status ${response.status}`);
40
- }
41
- return response.json();
42
- }
43
- function normalizeLeaderboardValue(raw) {
44
- const entries = Array.isArray(raw) ? raw : [];
45
- return entries
46
- .map(item => {
47
- const entry = item && typeof item === "object" && "value" in item
48
- ? item.value
49
- : item;
50
- const record = entry;
51
- return {
52
- who: String(record?.who && typeof record.who === "object" ? record.who.value ?? "" : record?.who ?? ""),
53
- rolls: Number(record?.rolls && typeof record.rolls === "object"
54
- ? record.rolls.value ?? 0
55
- : record?.rolls ?? 0),
56
- };
57
- })
58
- .filter(entry => entry.who && entry.rolls > 0);
59
- }
60
- async function getTotalRolls(config = {}) {
61
- const data = await callReadOnly("get-total-rolls", [], config);
62
- if (!data.okay || !data.result) {
63
- return 0;
64
- }
65
- const clarityValue = (0, transactions_1.hexToCV)(data.result);
66
- const parsed = (0, transactions_1.cvToValue)(clarityValue, true);
67
- return Number(parsed && typeof parsed === "object" && "value" in parsed
68
- ? parsed.value ?? 0
69
- : parsed ?? 0);
70
- }
71
- async function getUserRolls(userAddress, config = {}) {
72
- const principalArg = serializeCvToHex((0, transactions_1.principalCV)(userAddress));
73
- const data = await callReadOnly("get-user-rolls", [principalArg], config);
74
- if (!data.okay || !data.result) {
75
- return 0;
76
- }
77
- const clarityValue = (0, transactions_1.hexToCV)(data.result);
78
- const parsed = (0, transactions_1.cvToValue)(clarityValue, true);
79
- return Number(parsed && typeof parsed === "object" && "value" in parsed
80
- ? parsed.value ?? 0
81
- : parsed ?? 0);
82
- }
83
- async function getUserLastResult(userAddress, config = {}) {
84
- const principalArg = serializeCvToHex((0, transactions_1.principalCV)(userAddress));
85
- const data = await callReadOnly("get-user-last-result", [principalArg], config);
86
- if (!data.okay || !data.result) {
87
- return 0;
88
- }
89
- const clarityValue = (0, transactions_1.hexToCV)(data.result);
90
- const parsed = (0, transactions_1.cvToValue)(clarityValue, true);
91
- return Number(parsed && typeof parsed === "object" && "value" in parsed
92
- ? parsed.value ?? 0
93
- : parsed ?? 0);
94
- }
95
- async function getLeaderboard(config = {}) {
96
- const data = await callReadOnly("get-leaderboard", [], config);
97
- if (!data.okay || !data.result) {
98
- return [];
99
- }
100
- const clarityValue = (0, transactions_1.hexToCV)(data.result);
101
- const parsed = (0, transactions_1.cvToValue)(clarityValue, true);
102
- return normalizeLeaderboardValue(parsed);
103
- }
104
- function createRollCall(config = {}) {
105
- const resolved = resolveConfig(config);
106
- return {
107
- contractAddress: resolved.contractAddress,
108
- contractName: resolved.contractName,
109
- functionName: "roll",
110
- functionArgs: [],
111
- postConditionMode: transactions_1.PostConditionMode.Deny,
112
- postConditions: [],
113
- network: resolved.network,
114
- };
115
- }
116
- class DiceRollClient {
117
- constructor(config = {}) {
118
- this.config = resolveConfig(config);
119
- }
120
- getTotalRolls() {
121
- return getTotalRolls(this.config);
122
- }
123
- getUserRolls(userAddress) {
124
- return getUserRolls(userAddress, this.config);
125
- }
126
- getUserLastResult(userAddress) {
127
- return getUserLastResult(userAddress, this.config);
128
- }
129
- getLeaderboard() {
130
- return getLeaderboard(this.config);
131
- }
132
- createRollCall() {
133
- return createRollCall(this.config);
134
- }
135
- }
136
- exports.DiceRollClient = DiceRollClient;
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { DiceRollClient } from "./client";
2
- export { DiceRollClient, DEFAULT_CONFIG, callReadOnly, createRollCall, getLeaderboard, getTotalRolls, getUserRolls, getUserLastResult, } from "./client";
3
- export type { DiceRollConfig, LeaderEntry, ReadOnlyResponse, RollCall, } from "./types";
4
- export type TotalRollsResult = Awaited<ReturnType<DiceRollClient["getTotalRolls"]>>;
package/dist/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserLastResult = exports.getUserRolls = exports.getTotalRolls = exports.getLeaderboard = exports.createRollCall = exports.callReadOnly = exports.DEFAULT_CONFIG = exports.DiceRollClient = void 0;
4
- var client_1 = require("./client");
5
- Object.defineProperty(exports, "DiceRollClient", { enumerable: true, get: function () { return client_1.DiceRollClient; } });
6
- Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return client_1.DEFAULT_CONFIG; } });
7
- Object.defineProperty(exports, "callReadOnly", { enumerable: true, get: function () { return client_1.callReadOnly; } });
8
- Object.defineProperty(exports, "createRollCall", { enumerable: true, get: function () { return client_1.createRollCall; } });
9
- Object.defineProperty(exports, "getLeaderboard", { enumerable: true, get: function () { return client_1.getLeaderboard; } });
10
- Object.defineProperty(exports, "getTotalRolls", { enumerable: true, get: function () { return client_1.getTotalRolls; } });
11
- Object.defineProperty(exports, "getUserRolls", { enumerable: true, get: function () { return client_1.getUserRolls; } });
12
- Object.defineProperty(exports, "getUserLastResult", { enumerable: true, get: function () { return client_1.getUserLastResult; } });
package/dist/types.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import type { StacksNetwork } from "@stacks/network";
2
- import type { PostConditionMode } from "@stacks/transactions";
3
- export interface DiceRollConfig {
4
- contractAddress?: string;
5
- contractName?: string;
6
- apiBase?: string;
7
- network?: StacksNetwork;
8
- }
9
- export interface LeaderEntry {
10
- who: string;
11
- rolls: number;
12
- }
13
- export interface ReadOnlyResponse {
14
- okay?: boolean;
15
- result?: string;
16
- cause?: string;
17
- }
18
- export interface RollCall {
19
- contractAddress: string;
20
- contractName: string;
21
- functionName: "roll";
22
- functionArgs: [];
23
- postConditionMode: PostConditionMode;
24
- postConditions: [];
25
- network: StacksNetwork;
26
- }
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });