Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
psylopunk committed May 28, 2022
2 parents 9c84ee1 + fbe162a commit ac3d9b6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,51 @@

This library is built entirely according to the standards of the selected language in order to admire the functionality.

[![PyPI version](https://badge.fury.io/py/ton.svg)](https://badge.fury.io/py/ton)

Install TON using pip:

```
```bash
$ pip install ton
```
or (if error with illegal instructions):
```

or (if error with illegal instructions):

```bash
$ git clone https://github.com/psylopunk/ton && cd ton
$ chmod +x build_tonlib.sh && ./build_tonlib.sh # docker is needed
```

### Now, let's get started:

```python
>>> from ton.sync import TonlibClient
>>> from ton import TonlibClient
>>>
>>> # Initiate module
>>> client = TonlibClient()
>>> client.init_tonlib()
>>> await client.init_tonlib()
>>>
>>> # Wallet generation
>>> wallet = client.create_wallet()
>>> wallet = await client.create_wallet()
>>> wallet
Wallet<EQCi-D5OSmueD61_ZCw7D_tcMMjB8E5e5AECZT7lCM2Gm6O1>
>>>
>>> # Get a word list
>>> seed = wallet.export()
>>> seed = await wallet.export()
>>>
>>> # Importing wallet
>>> wallet = client.import_wallet(seed)
>>> wallet = await client.import_wallet(seed)
>>>
>>> # Get saved wallet from Keystore
>>> path = wallet.path
>>> wallet = client.find_wallet(path)
>>> wallet = await client.find_wallet(path)
>>>
>>> # Getting an address
>>> wallet.account_address.account_address
EQCi-D5OSmueD61_ZCw7D_tcMMjB8E5e5AECZT7lCM2Gm6O1
>>>
>>> # Viewing transactions
>>> txs = wallet.get_transactions()
>>> txs = await wallet.get_transactions()
>>> in_msg = txs[0].in_msg
>>> in_msg.source.account_address # Sender
EQBPhcJanCxCYc-eiSxUVcm7I4-PfHODzBNhY1Cd3R5IP041
Expand All @@ -54,24 +58,30 @@ EQCi-D5OSmueD61_ZCw7D_tcMMjB8E5e5AECZT7lCM2Gm6O1
>>>
>>> # Sending transaction
>>> from ton.utils import to_nano
>>> wallet.transfer('EQBPhcJanCxCYc-eiSxUVcm7I4-PfHODzBNhY1Cd3R5IP041', to_nano(0.3), comment='test')
>>> await wallet.transfer('EQBPhcJanCxCYc-eiSxUVcm7I4-PfHODzBNhY1Cd3R5IP041', to_nano(0.3), comment='test')
{
"@type": "ok",
"@extra": "1648032761.9897776:0:0.6654941473285754"
}
>>> # View account
>>> account = await client.find_account('EQBPhcJanCxCYc-eiSxUVcm7I4-PfHODzBNhY1Cd3R5IP041')
>>> txs = await account.get_transactions()
```

### Documentation <a href="#documentation" id="documentation"></a>

To get acquainted with all the basics, go to [Developer Interface](developer-interface/)

### Troubleshooting

Read more about this in [Troubleshooting](troubleshooting.md)

### Dependencies <a href="#dependencies" id="dependencies"></a>

The TON library relies on these excellent libraries:

* `crc16` - Library for calculating CRC16
* `poetry` - Python packaging and dependency management made easy
* `httpx` _- A next-generation HTTP client for Python_
* `requests` _- HTTP interface for python_
* `ujson` - Ultra fast JSON encoder and decoder
* `ed25519` - Public-key signature system
* `mnemonic` - Mnemonic code for generating deterministic keys
2 changes: 2 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
* [Introduction](README.md)
* [Developer Interface](developer-interface/README.md)
* [Client](developer-interface/client.md)
* [Synchronous](synchronous.md)
* [Troubleshooting](troubleshooting.md)
8 changes: 4 additions & 4 deletions developer-interface/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _class_ `ton.TonlibClient`_(ls\_index: int=0, config='https://newton-blockchain.
> \
> **Parameters:**
>
> * **keystore** - (optional) Directory with keys, need 777 rights. Default is `.keystore`
> * **ls\_index** - (optional) Light server index
> * **config** - (optional) File or URL with the TON config
> * **work**_**chain\_id** - (optional) Workchain ID_
> * **keystore** - (str, optional) Directory with keys, need 777 rights. Default is `.keystore`
> * **ls\_index** - (int, optional) Light server index
> * **config** - (str, optional) File or URL with the TON config
> * **work**_**chain\_id** - (int, optional) Workchain ID_
12 changes: 12 additions & 0 deletions synchronous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Synchronous

To use the library without asyncio, we can use similar code:

```python
from ton.sync import TonlibClient
client = TonlibClient()
client.init_tonlib()

# then all methods can be used without await
wallet = client.create_wallet()
```
24 changes: 24 additions & 0 deletions troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Troubleshooting

Library functions make requests via `ton.tl.functions`. Each of the classes is a reference to the `libtonlibjson` method ([full list](https://github.com/newton-blockchain/ton/blob/master/tl/generate/scheme/tonlib\_api.tl)).

To enable debugging of library actions, need to do this:

```python
import logging
logging.getLogger('ton').disabled = False
logging.getLogger('ton').setLevel(logging.DEBUG)
```

But apart from visible errors, the action can simply last indefinitely in time. This means that the error occurred inside `libtonlibjson` OR the selected liteserver is not responding. In that case, we need to see what's going on inside:

```python
await client.set_verbosity_level(5)
```

If it seems that the problem is in the lite server, you need to change it, reinitialize the library with a different ls\_index:

```python
client = TonlibClient(ls_index=N)
await client.init_tonlib()
```

0 comments on commit ac3d9b6

Please sign in to comment.