Skip to content

Commit 2ea7e4f

Browse files
committed
Add Kotlin example for fetching transactions and update Java example
Signed-off-by: andreypfau <[email protected]>
1 parent af858b0 commit 2ea7e4f

File tree

6 files changed

+91
-127
lines changed

6 files changed

+91
-127
lines changed

Writerside/topics/Overview.md

Lines changed: 22 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ hands‑on guides and API details, see the other topics in this documentation se
1010

1111
## What is TON SDK?
1212

13-
A collection of modular libraries published on Maven Central under the `org.ton.kotlin` group. Each module focuses on a
13+
A collection of modular libraries published on Maven Central under the `org.ton.sdk` group. Each module focuses on a
1414
well‑defined layer of the TON stack, from low‑level binary formats up to ready‑to‑use APIs.
1515

1616
### Key features
@@ -43,147 +43,48 @@ README for the latest coordinates and versions.
4343

4444
- Indexers and backends that need to parse blocks/transactions and verify proofs.
4545
- Wallets and apps that compose and serialize messages and contracts.
46-
- Services querying blockchain data via the Lite Client.
46+
- Services querying blockchain data via the Lite Client or TON Center http client.
4747
- Tooling and middleware that rely on TL‑B codecs and BOC manipulation.
4848

4949
## Installation
5050

51-
Add TON SDK modules from Maven Central. Use the coordinates under the org.ton.kotlin group. Keep module versions
52-
aligned (e.g., 0.5.0).
53-
54-
Gradle (Kotlin DSL):
55-
56-
```kotlin
57-
val tonVersion = "0.5.0"
58-
59-
dependencies {
60-
implementation("org.ton.kotlin:ton-kotlin-tvm:$tonVersion") // Cells/BOC
61-
implementation("org.ton.kotlin:ton-kotlin-crypto:$tonVersion") // Crypto
62-
implementation("org.ton.kotlin:ton-kotlin-tlb:$tonVersion") // TL-B codec
63-
implementation("org.ton.kotlin:ton-kotlin-liteclient:$tonVersion") // Lite client API
64-
// Optional:
65-
implementation("org.ton.kotlin:ton-kotlin-contract:$tonVersion") // Contracts helpers
66-
implementation("org.ton.kotlin:ton-kotlin-adnl:$tonVersion") // ADNL transport
67-
}
68-
```
69-
70-
Gradle (Groovy DSL):
71-
72-
```groovy
73-
def tonVersion = '0.5.0'
74-
75-
dependencies {
76-
implementation "org.ton.kotlin:ton-kotlin-tvm:$tonVersion"
77-
implementation "org.ton.kotlin:ton-kotlin-crypto:$tonVersion"
78-
implementation "org.ton.kotlin:ton-kotlin-tlb:$tonVersion"
79-
implementation "org.ton.kotlin:ton-kotlin-liteclient:$tonVersion"
80-
// Optional:
81-
implementation "org.ton.kotlin:ton-kotlin-contract:$tonVersion"
82-
implementation "org.ton.kotlin:ton-kotlin-adnl:$tonVersion"
83-
}
84-
```
85-
86-
Maven:
87-
88-
```xml
89-
90-
<dependencies>
91-
<dependency>
92-
<groupId>org.ton.kotlin</groupId>
93-
<artifactId>ton-kotlin-tvm</artifactId>
94-
<version>0.5.0</version>
95-
</dependency>
96-
<dependency>
97-
<groupId>org.ton.kotlin</groupId>
98-
<artifactId>ton-kotlin-crypto</artifactId>
99-
<version>0.5.0</version>
100-
</dependency>
101-
<dependency>
102-
<groupId>org.ton.kotlin</groupId>
103-
<artifactId>ton-kotlin-tlb</artifactId>
104-
<version>0.5.0</version>
105-
</dependency>
106-
<dependency>
107-
<groupId>org.ton.kotlin</groupId>
108-
<artifactId>ton-kotlin-liteclient</artifactId>
109-
<version>0.5.0</version>
110-
</dependency>
111-
<!-- Optional -->
112-
<dependency>
113-
<groupId>org.ton.kotlin</groupId>
114-
<artifactId>ton-kotlin-contract</artifactId>
115-
<version>0.5.0</version>
116-
</dependency>
117-
<dependency>
118-
<groupId>org.ton.kotlin</groupId>
119-
<artifactId>ton-kotlin-adnl</artifactId>
120-
<version>0.5.0</version>
121-
</dependency>
122-
</dependencies>
123-
```
51+
Add TON SDK modules from Maven Central. Use the coordinates under the org.ton.sdk group. Keep module versions
52+
aligned (e.g., 0.6.0).
53+
54+
<tabs>
55+
<tab id="maven" title="Maven">
56+
<code-block lang="xml" src="../../examples/java-maven-project/pom.xml" include-symbol="dependencies"/>
57+
</tab>
58+
<tab id="gradle-kts" title="build.gradle.kts">
59+
<code-block lang="kotlin" src="../../examples/build.gradle.kts" include-lines="10-12"/>
60+
</tab>
61+
</tabs>
12462

12563
## Quick start
12664

12765
Add the artifacts you need from Maven Central and start from the level that fits your use case.
12866

129-
### Kotlin (JVM/Android)
130-
131-
Creating a Cell and serializing to BOC:
132-
133-
```kotlin
134-
val cell = org.ton.cell.buildCell {
135-
storeUInt(0xDEADBEEFu, 32)
136-
}
137-
val boc: ByteArray = org.ton.boc.BagOfCells.of(cell).toByteArray()
138-
```
139-
140-
Decoding a TL‑B object (schema provided by block‑tlb module):
141-
142-
```kotlin
143-
val block = org.ton.tlb.loadTlb<Block>(boc)
144-
```
145-
146-
### Java (JVM)
147-
148-
Creating a Cell and serializing to BOC:
149-
150-
```java
151-
public class Example {
152-
static void main(String[] args) {
153-
var builder = org.ton.cell.CellBuilderKt.beginCell();
154-
builder.storeUInt(0xDEADBEEF, 32);
155-
org.ton.cell.Cell cell = builder.endCell();
156-
byte[] boc = org.ton.boc.BagOfCells.Companion.of(new org.ton.cell.Cell[]{cell}).toByteArray();
157-
}
158-
}
159-
```
67+
<tabs>
68+
<tab id="java" title="Java">
69+
<code-block lang="Java" src="../../examples/java-maven-project/src/main/java/org/ton/sdk/example/GetTransactionExample.java" include-symbol="main"/>
70+
</tab>
71+
<tab id="kotlin" title="Kotlin">
72+
<code-block lang="kotlin" src="../../examples/kotlin-gradle-project/src/jvmMain/kotlin/GetTransactionExample.kt" include-symbol="main"/>
73+
</tab>
74+
</tabs>
16075

16176
See examples/ and tests in the repository for more scenarios.
16277

16378
## Supported platforms
16479

16580
- JVM / Android — Kotlin and Java (first‑class)
16681
- iOS — Swift via Kotlin Multiplatform bindings (availability may vary by module)
167-
- Desktop/ServerJVM
82+
- Desktop/Server — JVM (JDK 8+)
16883
- Other Kotlin targets may be available per‑module; check each module’s README or Gradle metadata.
16984

170-
## Versioning and compatibility
171-
172-
- Semantic‑like versioning across modules. Prefer matching versions (e.g., 0.5.x) for best compatibility.
173-
- Wire formats (BOC, TLB) follow TON specifications; backwards compatibility is preserved unless TON protocol changes.
174-
17585
## Where to go next
17686

17787
- Project README: architecture, badges, and links
17888
- Wiki/Docs: deeper guides and API references
17989
- Examples directory: runnable samples
18090
- Telegram chat: community support and announcements
181-
182-
## Glossary
183-
184-
- CellThe fundamental immutable binary structure in TON used by TVM.
185-
- BOC (Bag of Cells) — A container format for serializing graphs of Cells.
186-
- TLBType language for describing binary data structures in TON.
187-
- ADNLAbstract Datagram Network Layer, a TON network transport.
188-
- RLDPReliable Link over Datagram Protocol used over ADNL.
189-
- Lite ClientA client that queries TON blockchain data without running a full node.

examples/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ kotlin {
88
sourceSets {
99
commonMain {
1010
dependencies {
11-
api(projects.tonKotlinLiteclient)
12-
api(projects.tonKotlinContract)
11+
api("org.ton.sdk:ton-sdk-toncenter-client:0.6.0-SNAPSHOT")
1312
}
1413
}
1514
}

examples/java-maven-project/src/main/java/org/ton/sdk/example/GetTransactionExample.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@
99

1010
import java.math.BigInteger;
1111
import java.util.concurrent.ExecutionException;
12+
import java.util.concurrent.Future;
1213

1314
public class GetTransactionExample {
1415
public static void main(String[] args) throws ExecutionException, InterruptedException {
16+
// create TON Center v3 http client
1517
TonCenterV3Client client = TonCenterV3Client.create();
16-
TonCenterTransactionsResponse response = client.transactionsAsync(
18+
19+
// Get 10 last transactions for account
20+
Future<TonCenterTransactionsResponse> response = client.transactionsAsync(
1721
new TonCenterTransactionsRequestBuilder()
1822
.address(AddressStd.parse("UQAKtVj024T9MfYaJzU1xnDAkf_GGbHNu-V2mgvyjTuP6uYH"))
19-
.limit(15)
20-
).get();
21-
for (TonCenterTransaction transaction : response.transactions()) {
23+
.limit(10)
24+
);
25+
26+
// Print transactions info and balance after transaction
27+
for (TonCenterTransaction transaction : response.get().transactions()) {
2228
Coins balance = transaction.accountStateAfter().balance();
2329

2430
BigInteger value = BigInteger.ZERO;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
mavenCentral()
8+
}
9+
10+
kotlin {
11+
jvm()
12+
13+
sourceSets {
14+
jvmMain {
15+
dependencies {
16+
api("org.ton.sdk:ton-sdk-toncenter-client-jvm:0.6.0-SNAPSHOT")
17+
}
18+
}
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@file:Suppress("OPT_IN_USAGE")
2+
3+
package org.ton.sdk.example
4+
5+
import kotlinx.coroutines.Deferred
6+
import kotlinx.coroutines.GlobalScope
7+
import kotlinx.coroutines.async
8+
import kotlinx.coroutines.runBlocking
9+
import org.ton.sdk.bigint.toBigInt
10+
import org.ton.sdk.blockchain.address.AddressStd
11+
import org.ton.sdk.toncenter.client.TonCenterV3Client
12+
import org.ton.sdk.toncenter.client.transactions
13+
import org.ton.sdk.toncenter.model.TonCenterTransactionsResponse
14+
15+
object GetTransactionExample {
16+
@JvmStatic
17+
fun main(args: Array<String>) = runBlocking {
18+
// create TON Center v3 http client
19+
val client: TonCenterV3Client = TonCenterV3Client.create()
20+
21+
// Get 10 last transactions for account
22+
val response: Deferred<TonCenterTransactionsResponse> = GlobalScope.async {
23+
client.transactions {
24+
account += AddressStd.parse("UQAKtVj024T9MfYaJzU1xnDAkf_GGbHNu-V2mgvyjTuP6uYH")
25+
limit = 10
26+
}
27+
}
28+
29+
// Print transactions info and balance after transaction
30+
response.await().transactions.forEach { transaction ->
31+
val balance = transaction.accountStateAfter.balance
32+
val value = balance?.value ?: 0.toBigInt()
33+
println("hash=${transaction.hash} lt=${transaction.lt} balance=$value")
34+
}
35+
}
36+
}

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ submodule("liteclient")
3939
submodule("contract")
4040
submodule("dict")
4141

42+
submodule("examples-kotlin-gradle-project", path = "examples/kotlin-gradle-project", "sdk")
43+
4244
//submodule("provider", group = "sdk")
4345
//submodule("provider-core", "provider/core", group = "sdk")
4446
//submodule("provider-liteapi", "provider/liteapi")

0 commit comments

Comments
 (0)