Comments (1)
@fruitoiz, to send TON to another person using our library pytonapi, you'll also need a library for message construction, such as tonsdk. Below is an example code you can use:
import asyncio
from pytonapi import AsyncTonapi
from tonsdk.utils import bytes_to_b64str, to_nano
from tonsdk.contract.wallet import Wallets, WalletVersionEnum
# Tonapi Key
API_KEY = "AE33EX7D5...K2AO3FYQ" # noqa
# Wallet Mnemonics
MNEMONICS = "word1 word2 word3 ..." # noqa
# Destination Address
DESTINATION_ADDRESS = "EQC...Ness" # noqa
async def main():
# Initialize AsyncTonapi with the provided API key and set it to use the testnet or mainnet
tonapi = AsyncTonapi(api_key=API_KEY, is_testnet=True)
# Create a wallet from the provided mnemonics
mnemonics_list = MNEMONICS.split(" ")
_mnemonics, _pub_k, _priv_k, wallet = Wallets.from_mnemonics(
mnemonics_list, WalletVersionEnum.v4r2, 0,
)
# Get the sequence number of the wallet's current state
method_result = await tonapi.blockchain.execute_get_method(
wallet.address.to_string(False), "seqno"
)
seqno = int(method_result.decoded.get("state", 0))
# Prepare a transfer message to the destination address with the specified amount and sequence number
transfer_amount = to_nano(float("0.1"), 'ton')
query = wallet.create_transfer_message(
to_addr=DESTINATION_ADDRESS,
amount=transfer_amount,
seqno=seqno,
)
# Convert the message to Base64 and send it through the Tonapi blockchain
message_boc = bytes_to_b64str(query["message"].to_boc(False))
data = {'boc': message_boc}
await tonapi.blockchain.send_message(data)
if __name__ == "__main__":
asyncio.run(main())
To use the tonsdk library, make sure to install it using pip:
pip install tonsdk
This code will send 0.1 TON to the specified address when using the correct API key and mnemonic phrase for your wallet. Please make sure you replace the placeholder values (API_KEY, MNEMONICS, DESTINATION_ADDRESS) with your actual values.
from pytonapi.
Related Issues (19)
- fix ClientConnectorCertificateError HOT 1
- pydantic.v1.error_wrappers.ValidationError HOT 3
- Wrong received `int` type in `liteserver.get_account_state` HOT 1
- TypeError: 'type' object is not subscriptable HOT 3
- Send Ton HOT 1
- About pending transaction HOT 2
- Missing method to "Get Jetton balance by owner address"
- tonapi.blockchain.send_message(data) Always Returns False HOT 1
- Write me on telegram @zakhar_petukhov, thanks
- pytonapi.exceptions.TONAPINotFoundError: entity not found HOT 1
- Missing support for v2/sse/blocks HOT 2
- [JettonInfo] object admin missing HOT 1
- lack of raw_body property in Message schema HOT 1
- Wrong error format
- JSONDecodeError on client.blockchain.send_message method HOT 5
- tx hash in send message HOT 2
- httpx.ResponseNotRead: Attempted to access streaming response content, without having called `read()` HOT 7
- SSE with multiple accounts looks suspicious HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytonapi.