New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@coin-unknown/lottery-core

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coin-unknown/lottery-core

My awesome typescript library

latest
npmnpm
Version
0.0.32
Version published
Maintainers
0
Created
Source

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.

FAQs

Package last updated on 22 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts