Skip to main content

Namespace Wrapper Methods

Environment Variables

Environment variables are already pre-configured by the @_koii/namespace-wrapper package. You can directly import and use them in your tasks without additional setup. For detailed examples, refer to the Environment Variables Usage documentation.

Database Operations

MethodDescription
getDb(): Promise<void>get the KOIIDB
storeSet(key: string, value: string): Promise<void>Stores a value in the persistent storage
storeGet(key: string): Promise<string | null>Retrieves a value from the persistent storage

File System Operations

MethodDescription
fs(method: string, path: string, ...args: any[]): Promise<any>Executes file system operations in a standardized way
fsStaking(method: string, path: string, ...args: any[]): Promise<any>A decentralized staking platform enabling secure token locking for rewards.
fsWriteStream(imagepath: string): Promise<WriteStream | void>Creates a write stream for file operations
fsReadStream(imagepath: string): Promise<Buffer | void>Creates a read stream for file operations

Blockchain/Transaction Operations

MethodDescription
payloadSigning(body: Record<string, unknown>): Promise<string | void>Signs a payload for blockchain transactions using the main wallet's public key.
verifySignature(signedMessage: string, pubKey: string): Promise<{ data?: string; error?: string }>Verifies a signed message
sendAndConfirmTransactionWrapper(transaction: Transaction, signers: Keypair[]): Promise<string | void>Sends and confirms a transaction on the Koii network
sendTransaction(serviceNodeAccount: PublicKey, beneficiaryAccount: PublicKey, amount: number): Promise<string | void>Sends a transaction between accounts
getProgramAccounts() : Promise<any>Retrieves all program accounts associated with the task
claimReward(stakePotAccount: PublicKey, beneficiaryAccount: PublicKey, claimerKeypair: Keypair): Promise<void>Claims rewards for a specific round
stakeOnChain(taskStateInfoPublicKey: PublicKey, stakingAccKeypair: Keypair, stakePotAccount: PublicKey, stakeAmount: number): Promise<string | void>Stakes tokens for a task.

Task Status

MethodDescription
getTaskState(options: TaskStateOptions): Promise<TaskState | null>Retrieves the current state of the task
getTaskStateById(taskId: string, task_type: TaskType, options: TaskStateOptions): Promise<TaskState | null>Retrieves task state for a specific task ID and the task type
getTaskNodeVersion(): Promise<string>Gets the task node version
getTaskSubmissionInfo(round: number): Promise<TaskSubmissionState | null>Retrieves submission information for the task
getTaskDistributionInfo(round: number): Promise<TaskDistributionInfo | null>Gets distribution information for the task

Network and Task Handling Methods

MethodDescription
getNodes(url: string)Retrieves information about network nodes
getRpcUrl(): Promise<string | void>Gets the current RPC URL for the Koii network
getTaskDBPath(): Promise<string>Gets the path to the task's NeDB database
getBasePath(): Promise<string>Gets the base path to the task folder for performing file operations
getRound(): Promise<number>Gets the current round number
getSubmitterAccount(): Promise<Keypair | null>Gets the submitter's account Keypair
getMainAccountPubkey(): Promise<string | null>Gets the main account's public key
logger(level: LogLevel, message: string, action: string): Promise<boolean>Logs messages based on specified log level (log, warn, error).
getSlot(): Promise<number>Gets the current slot number
getAverageSlotTime(): Promise<number>Gets average slot time for the network

Audit and Distribution Operations

MethodDescription
auditSubmission(candidatePubkey: PublicKey, isValid: boolean, voterKeypair: Keypair, round: number): Promise<void>Audits a submission for a specific round
distributionListSubmissionOnChain(round: number): Promise<string | void>Submits distribution list to the blockchain
uploadDistributionList(distributionList: Record<string, any>, round: number): Promise<boolean | null>Uploads a distribution list for a round
distributionListAuditSubmission(candidatePubkey: PublicKey, isValid: boolean, voterKeypair: Keypair, round: number): Promise<void>Audits a distribution list submission
validateAndVoteOnDistributionList(validateDistribution: (submissionValue: string, round: number, nodePublicKey: string) => Promise<boolean>, round: number): Promise<string | void>Validates and votes on distribution lists
getDistributionList(publicKey: string, round: number): Promise<any | null>Gets the distribution list for a specific round
nodeSelectionDistributionList(round: number, isPreviousFailed: boolean): Promise<string | void>Selects nodes for distribution
payoutTrigger(round: number): Promise<void>Triggers payout for a specific round
selectAndGenerateDistributionList(submitDistributionList: (round: number) => Promise<void>, round: number, isPreviousRoundFailed: boolean): Promise<void>Generates and selects distribution list
validateAndVoteOnNodes(validate: (submissionValue: string, round: number, nodePublicKey: string,) => Promise<boolean>, round: number): Promise<void | string>Validates and votes on node submissions
checkSubmissionAndUpdateRound(submissionValue: string = 'default', round: number): Promise<void>Verifies submissions and updates the current round