npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@coin-unknown/lottery-core

v0.0.32

Published

My awesome typescript library

Downloads

13

Readme

Lottery Smart Contract SDK

This SDK provides a set of functions to interact with a TON blockchain-based lottery system. The SDK facilitates operations such as buying tickets, claiming rewards, creating lottery rounds, and managing referral programs.

More details can be found at Lottery Platform.

Installation

Ensure you have installed the necessary dependencies:

npm install @ton/core @tonconnect/sdk

Functions Overview

Factory Instance

async getFactory(): Promise<OpenedContract<LotteryFactory>>

Returns a singleton instance of the lottery factory contract.


Referral Wallet Instance

async getRefWallet(address: Address): Promise<OpenedContract<ReferralWallet>>

Retrieves an instance of the referral wallet contract associated with the provided address.


Lottery Instance

async getLottery(roundIdx: number): Promise<OpenedContract<Lottery>>

Gets a lottery contract instance for a specific round index.


TonConnect Sender Instance

getSender(tonconnect: TonConnect): TonConnectProvider

Initializes and returns an instance of TonConnectProvider for blockchain interaction.


Utility Functions

getReadableTicketNumber(number: number | bigint): string

Formats ticket numbers by adding leading zeros.

getTicketMatch(ticket: string, draw: string): number

Calculates the number of matching digits between a ticket and a draw result.

async getLastRoundId(): Promise<number>

Returns the index of the last created lottery round.

getRoundStatus(status: bigint): RoundStatus

Converts a numerical status code to a readable RoundStatus enum.


Round Information

async getRound(wallet: Wallet, roundIdx?: number): Promise<IRound>

Retrieves detailed information about a lottery round, including ticket sales, draw time, and user data.


Referral Wallet Operations

async createReferralWallet(tonConnect: TonConnect)

Creates a referral wallet with a small transaction fee.

async claimReferralReward(tonConnect: TonConnect)

Withdraws referral rewards from the referral wallet.


Ticket Operations

async getTicketsPrice(roundIdx: number, qty: number): Promise<string>

Calculates the price of purchasing a specific number of tickets.

async buyTicket(tonConnect: TonConnect, roundIdx: number, qty: number, cost: number, refWallet?: Address)

Purchases lottery tickets for the sender.

async buyTicketFor(tonConnect: TonConnect, roundIdx: number, qty: number, cost: number, recipient: Address, refWallet?: Address)

Purchases lottery tickets for another wallet.

async claimTickets(tonConnect: TonConnect, roundIdx: number, winTicketsIds: number[])

Claims winnings for specified ticket IDs.


Admin Operations

async claimPlatformComission(tonConnect: TonConnect, roundIdx: number)

Claims the commission earned from a lottery round.

async createRound(tonConnect: TonConnect)

Creates a new lottery round.

async closeRound(tonConnect: TonConnect, roundIdx: number)

Closes an ongoing lottery round.

async drawRound(tonConnect: TonConnect, roundIdx: number)

Initiates the draw process for a lottery round.

async moveFunds(tonConnect: TonConnect, roundIdx: number)

Transfers the remaining funds to the next lottery round.


Internal Function

async _buyTicket(tonConnect: TonConnect, params: BuyTicketParams): Promise<boolean>

Helper function to handle ticket purchase transactions internally.


Usage Example

import TonConnect from '@tonconnect/sdk';
import { buyTicket, getRound } from '@coin-unknown/lottery-core';

const tonConnect = new TonConnect();
const roundInfo = await getRound(tonConnect.wallet);

await buyTicket(tonConnect, roundInfo.id, 2, 10);
console.log(roundInfo);

License

This SDK is released under the MIT License.