{"id":13338227,"url":"https://github.com/ndatg/ton-http-api","last_synced_at":"2025-03-11T08:32:40.330Z","repository":{"id":221361888,"uuid":"754174846","full_name":"ndatg/ton-http-api","owner":"ndatg","description":"The lightweight TON Typescript Library","archived":true,"fork":false,"pushed_at":"2024-07-18T15:36:49.000Z","size":388,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T14:38:54.792Z","etag":null,"topics":["api","blockchain","client","crypto","http","library","lightweight","nodejs","telegram","ton","typescript"],"latest_commit_sha":null,"homepage":"https://ndatg.github.io/ton-http-api/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndatg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-07T14:46:53.000Z","updated_at":"2025-02-19T07:42:34.000Z","dependencies_parsed_at":"2024-07-18T18:29:34.188Z","dependency_job_id":null,"html_url":"https://github.com/ndatg/ton-http-api","commit_stats":null,"previous_names":["ndatg/ton-http-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndatg%2Fton-http-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndatg%2Fton-http-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndatg%2Fton-http-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndatg%2Fton-http-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndatg","download_url":"https://codeload.github.com/ndatg/ton-http-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243001015,"owners_count":20219791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","blockchain","client","crypto","http","library","lightweight","nodejs","telegram","ton","typescript"],"created_at":"2024-07-29T19:15:37.518Z","updated_at":"2025-03-11T08:32:40.008Z","avatar_url":"https://github.com/ndatg.png","language":"TypeScript","readme":"# ton-http-api\n\n[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)\n\nThe lightweight TON typescript library includes api, subscribers, and clients for interacting with smart contracts.\n\n## Documentation\n\nGo to the [documentation](https://ndatg.github.io/ton-http-api/) for detailed information.\n\n## Migration\n\nIf you need an older version of the library, use the [migrate](https://github.com/ndatg/ton-http-api/tree/migrate) branch.\n\n## Components\n\n| Component             | Status                                                                |\n| ----------------- | ------------------------------------------------------------------ |\n| [Toncenter API V2](https://toncenter.com/api/v2/) | ✅ |\n| [Toncenter API V3](https://toncenter.com/api/v3/) | ✅ |\n| Client for toncenter API V2 | ✅ |\n| Client for toncenter API V3 | ✅ |\n| Block subscriber for toncenter API V2 | ✅ |\n| Block subscriber for toncenter API V3 | ✅ |\n\n\n## Installation\n\n\n```bash\nnpm install ton-http-api --save\n```\n\n## Usage/Examples\n\nSome of the examples can be found in the [examples](https://github.com/ndatg/ton-http-api/tree/main/examples) directory.\n\nRegister your API key in the [@tonapibot](https://t.me/tonapibot) to get access with higher limits.\n\n### Api V3\n\nIn most cases, I recommend using toncenter `TonHttpApiV3`, this is the new and improved version.\n\n```javascript\nimport { TonHttpApiV3 } from \"ton-http-api\";\n\nconst api = new TonHttpApiV3({\n    endpoint: \"https://toncenter.com/\",\n    apiKey: \"\" // optional\n});\n\nconst masterchainInfo = await api.getMasterchainInfo();\nconsole.log(masterchainInfo);\n\nconst nftCollections = await api.getNftCollections({\n    collection_address: \"EQCA14o1-VWhS2efqoh_9M1b_A9DtKTuoqfmkn83AbJzwnPi\"\n});\nconsole.log(nftCollections);\n\nconst nftItems = await api.getNftItems({\n    collection_address: \"EQCA14o1-VWhS2efqoh_9M1b_A9DtKTuoqfmkn83AbJzwnPi\"\n});\nconsole.log(nftItems);\n\nconst jettonWallets = await api.getJettonWallets({\n    jetton_address: \"EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA\"\n});\nconsole.log(jettonWallets);\n```\n\n### Api V2\n\nYou can also use the old toncenter `TonHttpApiV2`.\n\n```javascript\nimport { TonHttpApiV2 } from \"ton-http-api\";\n\nconst api = new TonHttpApiV2({\n    endpoint: \"https://toncenter.com/\",\n    apiKey: \"\" // optional\n});\n\nconst data = await api.getMasterchainInfo();\nconsole.log(data);\n\nconst data = await api.getTransactions(\"EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N\");\nconsole.log(data);\n```\n\n### Client V2 / V3\n\n`TonClientV2` and `TonClientV3` provide compatibility with other libraries (e.g. deploy and test smart contracts).\n\n`TonClientV2` works in the same way as `TonClientV3`, but uses `TonHttpApiV2`.\n\nYou can use `client.api` to work with api methods.\n\nFor example, let's do a highload wallet deploy!\n\n```bash\nnpm install ton-highload-wallet-contract @ton/crypto @ton/core --save\n```\n\n```javascript\nimport { TonClientV3 } from \"ton-http-api\";\nimport { HighloadWalletContractV2 } from \"ton-highload-wallet-contract\";\nimport { mnemonicToPrivateKey } from \"@ton/crypto\";\nimport { internal } from \"@ton/core\";\n\nconst client = new TonClientV3({\n    endpoint: \"https://toncenter.com/\",\n    apiKey: \"\", // optional\n});\n\nconst mnemonic = [ /* ... */ ];\n\n// create contract\nconst key = await mnemonicToPrivateKey(mnemonic);\nconst contract = client.open(HighloadWalletContractV2.create({ publicKey: key.publicKey, workchain: 0 }));\nconsole.log(`send test coins to the address: ${contract.address}`);\n\n// send transfer\nawait contract.sendTransfer({\n    secretKey: key.secretKey,\n    messages: [\n        internal({\n            to: \"EQBYivdc0GAk-nnczaMnYNuSjpeXu2nJS3DZ4KqLjosX5sVC\",\n            value: \"0.2\",\n            body: \"test 1\",\n            bounce: false,\n        }),\n        internal({\n            to: \"EQBYivdc0GAk-nnczaMnYNuSjpeXu2nJS3DZ4KqLjosX5sVC\",\n            value: \"0.2\",\n            body: \"test 2\",\n            bounce: false,\n        })\n    ],\n});\n\n```\n\n### Subscriber V3\n\nYou can use `TonSubscriberV3` to listen blocks in the blockchain, it uses the `TonHttpApiV3`.\n\nThe `getTransactionsByMasterchainBlock` method gets transactions from both masterchain and shardchains.\n\n```javascript\nimport { \n    TonHttpApiV3, TonSubscriberV3, \n    TonMemoryBlockStorageV3, SchemaV3 \n} from \"ton-http-api\";\n\nconst api = new TonHttpApiV3({\n    endpoint: \"https://toncenter.com/\",\n    apiKey: \"\" // optional\n});\n\nconst storage = new TonMemoryBlockStorageV3();\n\nconst subscriber = new TonSubscriberV3({\n    api: api,\n    storage: storage,\n    // logger: logger,\n    // masterchainTickSleepTime: 3000,\n    // startSeqno: 35744539\n});\nawait subscriber.start();\n\nsubscriber.on(\"block\", async (args: { block: SchemaV3.Block }) =\u003e {\n    try {\n\n        let offset = 0;\n        let stopped = false;\n        let transactions: any = [];\n\n        do {\n            try {\n                const data = await api.getTransactionsByMasterchainBlock(args.block.seqno, {\n                    limit: 256,\n                    offset\n                });\n                transactions = [...transactions, ...data.transactions];\n\n                if (data.transactions.length \u003c 256) {\n                    stopped = true;\n                    break;\n                }\n\n                offset += 256;\n            } catch (error) {\n                console.log(error);\n            }\n        } while(!stopped);\n\n        console.log(`seqno: ${args.block.seqno} / transactions: ${transactions.length}`);\n\n    } catch (error) {\n        console.log(error);\n    }\n});\n```\n\n### Subscriber V2\n\nYou can use `TonSubscriberV2` to listen blocks in the blockchain, it uses the `TonHttpApiV2`.\n\n```javascript\nimport { \n    TonHttpApiV2, TonSubscriberV2, \n    TonMemoryBlockStorageV2, SchemaV2 \n} from \"ton-http-api\";\n\nconst api = new TonHttpApiV2({\n    endpoint: \"https://toncenter.com/\",\n    apiKey: \"\" // optional\n});\n\nconst storage = new TonMemoryBlockStorageV2();\n\nconst subscriber = new TonSubscriberV2({\n    api: api,\n    storage: storage,\n    // logger: logger,\n    // masterchainTickSleepTime: 3000,\n    // shardchainTickSleepTime: 100,\n    // startSeqno: 35744539\n});\n\nsubscriber.on(\"block\", async (args: { block: SchemaV2.BlockHeader, shards?: SchemaV2.BlockShards }) =\u003e {\n    try {\n\n        const { workchain, shard, seqno } = args.block.id;\n\n        let stopped = false;\n        let transactions: any = [];\n        do {\n            try {\n                const data = await api.getBlockTransactions(workchain, shard, seqno, {\n                    count: 1024,\n                });\n                transactions = [...transactions, ...data.transactions];\n                stopped = true;\n            } catch (error) {\n                console.log(error);\n            }\n        } while(!stopped);\n\n        console.log(`workchain: ${workchain} / seqno: ${seqno} / transactions: ${transactions.length}`);\n\n    } catch (error) {\n        console.log(error);\n    }\n});\n```\n## Feedback\n\nIf you have any feedback, please reach out to me at telegram [@ndatg](https://t.me/ndatg).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndatg%2Fton-http-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndatg%2Fton-http-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndatg%2Fton-http-api/lists"}