celo-dice-roll-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 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 ADDED
@@ -0,0 +1,13 @@
1
+ # celo-dice-roll-sdk
2
+
3
+ TypeScript SDK for reading the Celo Dice Roll contract from Celo mainnet.
4
+
5
+ ```ts
6
+ import { CeloDiceRollClient } from "celo-dice-roll-sdk";
7
+
8
+ const client = new CeloDiceRollClient({
9
+ contractAddress: "0x943DfC4aFe76B2042031556516799ba03396B3F3",
10
+ });
11
+
12
+ const totalRolls = await client.getTotalRolls();
13
+ ```
@@ -0,0 +1,12 @@
1
+ import { CeloDiceRollConfig, DiceRollStats, LeaderboardEntry } from "./types";
2
+ declare const ABI: string[];
3
+ export declare class CeloDiceRollClient {
4
+ private provider;
5
+ private contract;
6
+ contractAddress: string;
7
+ constructor(config: CeloDiceRollConfig);
8
+ getTotalRolls(): Promise<number>;
9
+ getUserStats(address: string): Promise<DiceRollStats>;
10
+ getLeaderboard(): Promise<LeaderboardEntry[]>;
11
+ }
12
+ export { ABI as CELO_DICE_ROLL_ABI };
package/dist/client.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CELO_DICE_ROLL_ABI = exports.CeloDiceRollClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const ABI = [
6
+ "function roll(uint256 target) external",
7
+ "function totalRolls() external view returns (uint256)",
8
+ "function userRolls(address) external view returns (uint256)",
9
+ "function userWins(address) external view returns (uint256)",
10
+ "function getUserStats(address player) external view returns (uint256 rolls, uint256 wins, uint256 latestTarget, uint256 latestRoll)",
11
+ "function getLeaderboard() external view returns (address[10], uint256[10])",
12
+ ];
13
+ exports.CELO_DICE_ROLL_ABI = ABI;
14
+ class CeloDiceRollClient {
15
+ constructor(config) {
16
+ const rpcUrl = config.rpcUrl || "https://forno.celo.org";
17
+ this.provider = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
18
+ this.contractAddress = config.contractAddress;
19
+ this.contract = new ethers_1.ethers.Contract(config.contractAddress, ABI, this.provider);
20
+ }
21
+ async getTotalRolls() {
22
+ const total = await this.contract.totalRolls();
23
+ return Number(total);
24
+ }
25
+ async getUserStats(address) {
26
+ const [rolls, wins, lastTarget, lastRoll] = await this.contract.getUserStats(address);
27
+ const rollCount = Number(rolls);
28
+ const winCount = Number(wins);
29
+ return {
30
+ rolls: rollCount,
31
+ wins: winCount,
32
+ lastTarget: Number(lastTarget),
33
+ lastRoll: Number(lastRoll),
34
+ winRate: rollCount === 0 ? 0 : Math.round((winCount / rollCount) * 100),
35
+ };
36
+ }
37
+ async getLeaderboard() {
38
+ const [addresses, scores] = await this.contract.getLeaderboard();
39
+ const entries = [];
40
+ for (let i = 0; i < 10; i++) {
41
+ const address = addresses[i];
42
+ const score = Number(scores[i]);
43
+ if (address !== ethers_1.ethers.ZeroAddress && score > 0) {
44
+ entries.push({ address, score, rank: i + 1 });
45
+ }
46
+ }
47
+ return entries;
48
+ }
49
+ }
50
+ exports.CeloDiceRollClient = CeloDiceRollClient;
@@ -0,0 +1,2 @@
1
+ export { CeloDiceRollClient, CELO_DICE_ROLL_ABI } from "./client";
2
+ export type { CeloDiceRollConfig, DiceRollStats, LeaderboardEntry } from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CELO_DICE_ROLL_ABI = exports.CeloDiceRollClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "CeloDiceRollClient", { enumerable: true, get: function () { return client_1.CeloDiceRollClient; } });
6
+ Object.defineProperty(exports, "CELO_DICE_ROLL_ABI", { enumerable: true, get: function () { return client_1.CELO_DICE_ROLL_ABI; } });
@@ -0,0 +1,16 @@
1
+ export interface LeaderboardEntry {
2
+ address: string;
3
+ score: number;
4
+ rank: number;
5
+ }
6
+ export interface DiceRollStats {
7
+ rolls: number;
8
+ wins: number;
9
+ lastTarget: number;
10
+ lastRoll: number;
11
+ winRate: number;
12
+ }
13
+ export interface CeloDiceRollConfig {
14
+ contractAddress: string;
15
+ rpcUrl?: string;
16
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "celo-dice-roll-sdk",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for the Celo Dice Roll MiniApp",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [
8
+ "celo",
9
+ "blockchain",
10
+ "web3",
11
+ "sdk",
12
+ "smart-contract",
13
+ "solidity",
14
+ "evm",
15
+ "dapp",
16
+ "typescript",
17
+ "minipay",
18
+ "dice",
19
+ "game"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "dependencies": {
26
+ "ethers": "^6.9.0"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.3.0"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "author": "brventonbeshers-ship-it",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/brventonbeshers-ship-it/celo-dice-roll-sdk.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/brventonbeshers-ship-it/celo-dice-roll-sdk/issues"
42
+ },
43
+ "homepage": "https://github.com/brventonbeshers-ship-it/celo-dice-roll-sdk#readme",
44
+ "engines": {
45
+ "node": ">=18.0.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }