UNPKG

@ton/ton

Version:

[![Version npm](https://img.shields.io/npm/v/ton.svg?logo=npm)](https://www.npmjs.com/package/ton)

1,132 lines (1,131 loc) 33.1 kB
/** * Copyright (c) Whales Corp. * All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { AxiosAdapter, InternalAxiosRequestConfig } from "axios"; import { Address, Contract, ContractProvider, OpenedContract, StateInit, Transaction, TupleItem, TupleReader } from "@ton/core"; import { z } from 'zod'; export type TonClient4Parameters = { /** * API endpoint */ endpoint: string; /** * HTTP request timeout in milliseconds. */ timeout?: number; /** * HTTP Adapter for axios */ httpAdapter?: AxiosAdapter; /** * HTTP request interceptor for axios */ requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig; }; export declare class TonClient4 { #private; constructor(args: TonClient4Parameters); /** * Get Last Block * @returns last block info */ getLastBlock(): Promise<{ last: { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }; init: { fileHash: string; rootHash: string; }; stateRootHash: string; now: number; }>; /** * Get block info * @param seqno block sequence number * @returns block info */ getBlock(seqno: number): Promise<{ shards: { workchain: number; shard: string; seqno: number; transactions: { lt: string; hash: string; account: string; }[]; fileHash: string; rootHash: string; }[]; }>; /** * Get block info by unix timestamp * @param ts unix timestamp * @returns block info */ getBlockByUtime(ts: number): Promise<{ shards: { workchain: number; shard: string; seqno: number; transactions: { lt: string; hash: string; account: string; }[]; fileHash: string; rootHash: string; }[]; }>; /** * Get block info by unix timestamp * @param seqno block sequence number * @param address account address * @returns account info */ getAccount(seqno: number, address: Address): Promise<{ account: { balance: { coins: string; currencies: Record<string, string>; }; state: { type: "uninit"; } | { data: string | null; code: string | null; type: "active"; } | { type: "frozen"; stateHash: string; }; last: { lt: string; hash: string; } | null; storageStat: { lastPaid: number; duePayment: string | null; used: { bits: number; cells: number; publicCells: number; }; } | null; }; block: { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }; }>; /** * Get account lite info (without code and data) * @param seqno block sequence number * @param address account address * @returns account lite info */ getAccountLite(seqno: number, address: Address): Promise<{ account: { balance: { coins: string; currencies: Record<string, string>; }; state: { type: "uninit"; } | { type: "active"; codeHash: string; dataHash: string; } | { type: "frozen"; stateHash: string; }; last: { lt: string; hash: string; } | null; storageStat: { lastPaid: number; duePayment: string | null; used: { bits: number; cells: number; publicCells: number; }; } | null; }; }>; /** * Check if contract is deployed * @param address addres to check * @returns true if contract is in active state */ isContractDeployed(seqno: number, address: Address): Promise<boolean>; /** * Check if account was updated since * @param seqno block sequence number * @param address account address * @param lt account last transaction lt * @returns account change info */ isAccountChanged(seqno: number, address: Address, lt: bigint): Promise<{ block: { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }; changed: boolean; }>; /** * Load unparsed account transactions * @param address address * @param lt last transaction lt * @param hash last transaction hash * @returns unparsed transactions */ getAccountTransactions(address: Address, lt: bigint, hash: Buffer): Promise<{ block: { workchain: number; seqno: number; shard: string; rootHash: string; fileHash: string; }; tx: Transaction; }[]>; /** * Load parsed account transactions * @param address address * @param lt last transaction lt * @param hash last transaction hash * @param count number of transactions to load * @returns parsed transactions */ getAccountTransactionsParsed(address: Address, lt: bigint, hash: Buffer, count?: number): Promise<ParsedTransactions>; /** * Get network config * @param seqno block sequence number * @param ids optional config ids * @returns network config */ getConfig(seqno: number, ids?: number[]): Promise<{ config: { cell: string; address: string; globalBalance: { coins: string; }; }; }>; /** * Execute run method * @param seqno block sequence number * @param address account address * @param name method name * @param args method arguments * @returns method result */ runMethod(seqno: number, address: Address, name: string, args?: TupleItem[]): Promise<{ exitCode: number; result: TupleItem[]; resultRaw: string | null; block: { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }; shardBlock: { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }; reader: TupleReader; }>; /** * Send external message * @param message message boc * @returns message status */ sendMessage(message: Buffer): Promise<{ status: any; }>; /** * Open smart contract * @param contract contract * @returns opened contract */ open<T extends Contract>(contract: T): OpenedContract<T>; /** * Open smart contract * @param block block number * @param contract contract * @returns opened contract */ openAt<T extends Contract>(block: number, contract: T): OpenedContract<T>; /** * Create provider * @param address address * @param init optional init data * @returns provider */ provider(address: Address, init?: StateInit | null): ContractProvider; /** * Create provider at specified block number * @param block block number * @param address address * @param init optional init data * @returns provider */ providerAt(block: number, address: Address, init?: StateInit | null): ContractProvider; } declare const blocksCodec: z.ZodArray<z.ZodObject<{ workchain: z.ZodNumber; seqno: z.ZodNumber; shard: z.ZodString; rootHash: z.ZodString; fileHash: z.ZodString; }, "strip", z.ZodTypeAny, { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }, { workchain: number; shard: string; seqno: number; fileHash: string; rootHash: string; }>, "many">; declare const parsedTransactionCodec: z.ZodObject<{ address: z.ZodString; lt: z.ZodString; hash: z.ZodString; prevTransaction: z.ZodObject<{ lt: z.ZodString; hash: z.ZodString; }, "strip", z.ZodTypeAny, { lt: string; hash: string; }, { lt: string; hash: string; }>; time: z.ZodNumber; outMessagesCount: z.ZodNumber; oldStatus: z.ZodUnion<[z.ZodLiteral<"uninitialized">, z.ZodLiteral<"frozen">, z.ZodLiteral<"active">, z.ZodLiteral<"non-existing">]>; newStatus: z.ZodUnion<[z.ZodLiteral<"uninitialized">, z.ZodLiteral<"frozen">, z.ZodLiteral<"active">, z.ZodLiteral<"non-existing">]>; fees: z.ZodString; update: z.ZodObject<{ oldHash: z.ZodString; newHash: z.ZodString; }, "strip", z.ZodTypeAny, { oldHash: string; newHash: string; }, { oldHash: string; newHash: string; }>; inMessage: z.ZodUnion<[z.ZodObject<{ body: z.ZodString; info: z.ZodUnion<[z.ZodObject<{ type: z.ZodLiteral<"internal">; value: z.ZodString; dest: z.ZodString; src: z.ZodString; bounced: z.ZodBoolean; bounce: z.ZodBoolean; ihrDisabled: z.ZodBoolean; createdAt: z.ZodNumber; createdLt: z.ZodString; fwdFee: z.ZodString; ihrFee: z.ZodString; }, "strip", z.ZodTypeAny, { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; }, { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; }>, z.ZodObject<{ type: z.ZodLiteral<"external-in">; dest: z.ZodString; src: z.ZodUnion<[z.ZodObject<{ bits: z.ZodNumber; data: z.ZodString; }, "strip", z.ZodTypeAny, { data: string; bits: number; }, { data: string; bits: number; }>, z.ZodNull]>; importFee: z.ZodString; }, "strip", z.ZodTypeAny, { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; }, { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; }>, z.ZodObject<{ type: z.ZodLiteral<"external-out">; dest: z.ZodUnion<[z.ZodObject<{ bits: z.ZodNumber; data: z.ZodString; }, "strip", z.ZodTypeAny, { data: string; bits: number; }, { data: string; bits: number; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { type: "external-out"; dest: { data: string; bits: number; } | null; }, { type: "external-out"; dest: { data: string; bits: number; } | null; }>]>; init: z.ZodUnion<[z.ZodObject<{ splitDepth: z.ZodUnion<[z.ZodNumber, z.ZodNull]>; code: z.ZodUnion<[z.ZodString, z.ZodNull]>; data: z.ZodUnion<[z.ZodString, z.ZodNull]>; special: z.ZodUnion<[z.ZodObject<{ tick: z.ZodBoolean; tock: z.ZodBoolean; }, "strip", z.ZodTypeAny, { tick: boolean; tock: boolean; }, { tick: boolean; tock: boolean; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; }, { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }, { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }>, z.ZodNull]>; outMessages: z.ZodArray<z.ZodObject<{ body: z.ZodString; info: z.ZodUnion<[z.ZodObject<{ type: z.ZodLiteral<"internal">; value: z.ZodString; dest: z.ZodString; src: z.ZodString; bounced: z.ZodBoolean; bounce: z.ZodBoolean; ihrDisabled: z.ZodBoolean; createdAt: z.ZodNumber; createdLt: z.ZodString; fwdFee: z.ZodString; ihrFee: z.ZodString; }, "strip", z.ZodTypeAny, { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; }, { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; }>, z.ZodObject<{ type: z.ZodLiteral<"external-in">; dest: z.ZodString; src: z.ZodUnion<[z.ZodObject<{ bits: z.ZodNumber; data: z.ZodString; }, "strip", z.ZodTypeAny, { data: string; bits: number; }, { data: string; bits: number; }>, z.ZodNull]>; importFee: z.ZodString; }, "strip", z.ZodTypeAny, { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; }, { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; }>, z.ZodObject<{ type: z.ZodLiteral<"external-out">; dest: z.ZodUnion<[z.ZodObject<{ bits: z.ZodNumber; data: z.ZodString; }, "strip", z.ZodTypeAny, { data: string; bits: number; }, { data: string; bits: number; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { type: "external-out"; dest: { data: string; bits: number; } | null; }, { type: "external-out"; dest: { data: string; bits: number; } | null; }>]>; init: z.ZodUnion<[z.ZodObject<{ splitDepth: z.ZodUnion<[z.ZodNumber, z.ZodNull]>; code: z.ZodUnion<[z.ZodString, z.ZodNull]>; data: z.ZodUnion<[z.ZodString, z.ZodNull]>; special: z.ZodUnion<[z.ZodObject<{ tick: z.ZodBoolean; tock: z.ZodBoolean; }, "strip", z.ZodTypeAny, { tick: boolean; tock: boolean; }, { tick: boolean; tock: boolean; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; }, { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; }>, z.ZodNull]>; }, "strip", z.ZodTypeAny, { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }, { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }>, "many">; parsed: z.ZodObject<{ seqno: z.ZodUnion<[z.ZodNumber, z.ZodNull]>; body: z.ZodUnion<[z.ZodUnion<[z.ZodObject<{ type: z.ZodLiteral<"comment">; comment: z.ZodString; }, "strip", z.ZodTypeAny, { type: "comment"; comment: string; }, { type: "comment"; comment: string; }>, z.ZodObject<{ type: z.ZodLiteral<"payload">; cell: z.ZodString; }, "strip", z.ZodTypeAny, { type: "payload"; cell: string; }, { type: "payload"; cell: string; }>]>, z.ZodNull]>; status: z.ZodUnion<[z.ZodLiteral<"success">, z.ZodLiteral<"failed">, z.ZodLiteral<"pending">]>; dest: z.ZodUnion<[z.ZodString, z.ZodNull]>; kind: z.ZodUnion<[z.ZodLiteral<"out">, z.ZodLiteral<"in">]>; amount: z.ZodString; resolvedAddress: z.ZodString; bounced: z.ZodBoolean; mentioned: z.ZodArray<z.ZodString, "many">; }, "strip", z.ZodTypeAny, { status: "success" | "failed" | "pending"; seqno: number | null; amount: string; body: { type: "comment"; comment: string; } | { type: "payload"; cell: string; } | null; dest: string | null; bounced: boolean; kind: "out" | "in"; resolvedAddress: string; mentioned: string[]; }, { status: "success" | "failed" | "pending"; seqno: number | null; amount: string; body: { type: "comment"; comment: string; } | { type: "payload"; cell: string; } | null; dest: string | null; bounced: boolean; kind: "out" | "in"; resolvedAddress: string; mentioned: string[]; }>; operation: z.ZodObject<{ address: z.ZodString; comment: z.ZodOptional<z.ZodString>; items: z.ZodArray<z.ZodUnion<[z.ZodObject<{ kind: z.ZodLiteral<"ton">; amount: z.ZodString; }, "strip", z.ZodTypeAny, { amount: string; kind: "ton"; }, { amount: string; kind: "ton"; }>, z.ZodObject<{ kind: z.ZodLiteral<"token">; amount: z.ZodString; }, "strip", z.ZodTypeAny, { amount: string; kind: "token"; }, { amount: string; kind: "token"; }>]>, "many">; op: z.ZodOptional<z.ZodObject<{ type: z.ZodUnion<[z.ZodLiteral<"jetton::excesses">, z.ZodLiteral<"jetton::transfer">, z.ZodLiteral<"jetton::transfer_notification">, z.ZodLiteral<"deposit">, z.ZodLiteral<"deposit::ok">, z.ZodLiteral<"withdraw">, z.ZodLiteral<"withdraw::all">, z.ZodLiteral<"withdraw::delayed">, z.ZodLiteral<"withdraw::ok">, z.ZodLiteral<"airdrop">]>; options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>; }, "strip", z.ZodTypeAny, { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; }, { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; }>>; }, "strip", z.ZodTypeAny, { items: ({ amount: string; kind: "ton"; } | { amount: string; kind: "token"; })[]; address: string; comment?: string | undefined; op?: { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; } | undefined; }, { items: ({ amount: string; kind: "ton"; } | { amount: string; kind: "token"; })[]; address: string; comment?: string | undefined; op?: { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; } | undefined; }>; }, "strip", z.ZodTypeAny, { lt: string; hash: string; fees: string; address: string; prevTransaction: { lt: string; hash: string; }; time: number; outMessagesCount: number; oldStatus: "active" | "uninitialized" | "frozen" | "non-existing"; newStatus: "active" | "uninitialized" | "frozen" | "non-existing"; update: { oldHash: string; newHash: string; }; inMessage: { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; } | null; outMessages: { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }[]; parsed: { status: "success" | "failed" | "pending"; seqno: number | null; amount: string; body: { type: "comment"; comment: string; } | { type: "payload"; cell: string; } | null; dest: string | null; bounced: boolean; kind: "out" | "in"; resolvedAddress: string; mentioned: string[]; }; operation: { items: ({ amount: string; kind: "ton"; } | { amount: string; kind: "token"; })[]; address: string; comment?: string | undefined; op?: { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; } | undefined; }; }, { lt: string; hash: string; fees: string; address: string; prevTransaction: { lt: string; hash: string; }; time: number; outMessagesCount: number; oldStatus: "active" | "uninitialized" | "frozen" | "non-existing"; newStatus: "active" | "uninitialized" | "frozen" | "non-existing"; update: { oldHash: string; newHash: string; }; inMessage: { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; } | null; outMessages: { body: string; init: { data: string | null; code: string | null; splitDepth: number | null; special: { tick: boolean; tock: boolean; } | null; } | null; info: { value: string; type: "internal"; dest: string; src: string; bounced: boolean; bounce: boolean; ihrDisabled: boolean; createdAt: number; createdLt: string; fwdFee: string; ihrFee: string; } | { type: "external-in"; dest: string; src: { data: string; bits: number; } | null; importFee: string; } | { type: "external-out"; dest: { data: string; bits: number; } | null; }; }[]; parsed: { status: "success" | "failed" | "pending"; seqno: number | null; amount: string; body: { type: "comment"; comment: string; } | { type: "payload"; cell: string; } | null; dest: string | null; bounced: boolean; kind: "out" | "in"; resolvedAddress: string; mentioned: string[]; }; operation: { items: ({ amount: string; kind: "ton"; } | { amount: string; kind: "token"; })[]; address: string; comment?: string | undefined; op?: { type: "jetton::excesses" | "jetton::transfer" | "jetton::transfer_notification" | "deposit" | "deposit::ok" | "withdraw" | "withdraw::all" | "withdraw::delayed" | "withdraw::ok" | "airdrop"; options?: Record<string, string> | undefined; } | undefined; }; }>; export type ParsedTransaction = z.infer<typeof parsedTransactionCodec>; export type ParsedTransactions = { blocks: z.infer<typeof blocksCodec>; transactions: ParsedTransaction[]; }; export {};