diff --git a/client.ts b/client.ts index d4b632d..0eddcce 100644 --- a/client.ts +++ b/client.ts @@ -2,6 +2,7 @@ import { TonClient, TonClient4 } from "@ton/ton" import axios from "axios" import { LiteClient, LiteSingleEngine, LiteRoundRobinEngine } from "ton-lite-client" import { getHttpEndpoint, getHttpV4Endpoint } from "@orbs-network/ton-access"; +import { HttpClient, Api } from 'tonapi-sdk-js'; let lc4: TonClient4 | undefined = undefined let lc: LiteClient | undefined = undefined @@ -9,7 +10,7 @@ let lc: LiteClient | undefined = undefined let lcOrbs: TonClient4 | undefined = undefined let lcHub: TonClient4 | undefined = undefined -let lcToncenter: TonClient| undefined = undefined +let lcToncenter: TonClient | undefined = undefined let createLiteClient: Promise @@ -93,4 +94,20 @@ export async function getLiteClient(_configUrl): Promise { await createLiteClient return lc as any +} + +export async function getTonapiClient(): Promise> { + const httpClient = new HttpClient({ + baseUrl: 'https://tonapi.io/', + baseApiParams: { + headers: { + Authorization: `Bearer ${process.env.TONAPI_TOKEN}`, + 'Content-type': 'application/json' + } + } + }); + + // Initialize the API client + const client = new Api(httpClient); + return client } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ec2420e..ce876e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "axios": "^1.6.7", "dotenv": "^16.4.1", "ton-lite-client": "npm:@truecarry/ton-lite-client@^3.1.1", + "tonapi-sdk-js": "^1.0.1", "ts-node": "^10.9.2", "typescript": "^5.3.3" } @@ -545,6 +546,11 @@ "pegjs": "^0.10.0" } }, + "node_modules/tonapi-sdk-js": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tonapi-sdk-js/-/tonapi-sdk-js-1.0.1.tgz", + "integrity": "sha512-ZFPRZ2JQWQlNQs+ZggzdWS8m1pSFeklPmUt3asdnljMceRPopWUcyU2LGw2/GhIxde7XKqF/kimF/1EkSUV/og==" + }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", diff --git a/package.json b/package.json index c0b5887..9d9a7c7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "axios": "^1.6.7", "dotenv": "^16.4.1", "ton-lite-client": "npm:@truecarry/ton-lite-client@^3.1.1", + "tonapi-sdk-js": "^1.0.1", "ts-node": "^10.9.2", "typescript": "^5.3.3" } diff --git a/send_universal.ts b/send_universal.ts index 7b29fd0..af5af2a 100644 --- a/send_universal.ts +++ b/send_universal.ts @@ -211,7 +211,7 @@ async function main() { setInterval(() => { updateBestGivers(liteClient, wallet.address) - }, 1000) + }, 30000) while (go) { const giverAddress = bestGiver.address @@ -288,55 +288,20 @@ async function sendMinedBoc( giverAddress: string, boc: Cell ) { - const liteServerClient = await getLiteClient(args['-c'] ?? 'https://ton-blockchain.github.io/global.config.json') + + const wallets: OpenedContract[] = [] const ton4Client = await getTon4Client() const tonOrbsClient = await getTon4ClientOrbs() - const toncenterClient = await getTonCenterClient() - - const w1 = liteServerClient.open(wallet) const w2 = ton4Client.open(wallet) const w3 = tonOrbsClient.open(wallet) - const w4 = toncenterClient.open(wallet) - - const wallets = [w1, w2, w3] - - - // const transferBoc = w1.createTransfer({ - // seqno, - // secretKey: keyPair.secretKey, - // messages: [internal({ - // to: giverAddress, - // value: toNano('0.05'), - // bounce: true, - // body: boc, - // })], - // sendMode: 3 as any, - // }) - - - // console.log('send seqno', seqno) - // const ext = external({ - // to: Address.parse(giverAddress), - // body: transferBoc - // }) - // const dataBoc = beginCell().store(storeMessage(ext)).endCell() - // toncenterClient.sendFile(dataBoc.toBoc()).then(() => { - // console.log('toncenter success') - // }).catch(e => { - // // - // console.log('toncenter send error', e) - // }) - // w4.sendTransfer({ - // seqno, - // secretKey: keyPair.secretKey, - // messages: [internal({ - // to: giverAddress, - // value: toNano('0.05'), - // bounce: true, - // body: boc, - // })], - // sendMode: 3 as any, - // }) + wallets.push(w2) + wallets.push(w3) + + if (args['--api'] === 'lite') { + const liteServerClient = await getLiteClient(args['-c'] ?? 'https://ton-blockchain.github.io/global.config.json') + const w1 = liteServerClient.open(wallet) + wallets.push(w1) + } for (let i = 0; i < 3; i++) { for (const w of wallets) {