forked from andelf/tronpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
The Async API | ||
============= | ||
|
||
TronPy offers a standard synchronous API by default, | ||
but also introduces an async client via `httpx <https://www.python-httpx.org/>`_. | ||
|
||
The async client is ``AsyncTron``. It almost uses the same API as the synchronous client ``Tron``. | ||
|
||
.. code-block:: python | ||
import asyncio | ||
from tronpy import AsyncTron | ||
from tronpy.keys import PrivateKey | ||
# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z | ||
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888")) | ||
async def transfer(): | ||
async with AsyncTron(network='nile') as client: | ||
print(client) | ||
txb = ( | ||
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000) | ||
.memo("test memo") | ||
.fee_limit(100_000_000) | ||
) | ||
txn = await txb.build() | ||
print(txn) | ||
txn_ret = await txn.sign(priv_key).broadcast() | ||
print(txn_ret) | ||
# > {'result': True, 'txid': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b'} | ||
print(await txn_ret.wait()) | ||
# > {'id': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b', 'blockNumber': 10163821, | ||
# > 'blockTimeStamp': 1603368072000, 'contractResult': [''], 'receipt': {'net_usage': 283}} | ||
if __name__ == '__main__': | ||
asyncio.run(transfer()) | ||
API reference | ||
------------- | ||
|
||
.. autoclass:: tronpy.AsyncTron | ||
:members: | ||
|
||
.. autoclass:: tronpy.async_tron.AsyncTrx | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters