Initialization

Before you can interact with entities like Store an Invoice, you need to initialize the SDK. This can be done in just one line of code:

tonpay_sdk = Tonpay.create(TonNetwork.MAINNET, Sender())

Done! Now you can access everything that our SDK provides using the tonpay_sdk object.

It's highly recommended to use Ton Connect 2.0 in the Sender as it's a network-wide standard.

Short FAQ

You may be wondering - "what is sender?". The answer is simple - sender is an entity that is responsible for sending transactions to the TON Blockchain. You might want to use TON Connect 2.0 for this, or implement a custom sender that uses your seed phrase to sign transactions and send them. Here's an example:

from tonsdk.boc import Cell
from tonsdk.utils import Address, bytes_to_b64str
from tonsdk.contract.wallet import WalletVersionEnum, Wallets
from TonTools.Providers.TonCenterClient import TonCenterClient

from tonpay import Sender, get_http_endpoint

class MnemonicSender(Sender):

    def __init__(self, mnemonic: list): # list of words
        self.mnemonic = mnemonic

    async def send(self, value: int, address: Address, body: Cell, state_init: Cell = None):
        endpoint = await get_http_endpoint({'network': "mainnet", 'protocol': "rest"})
        client = TonCenterClient(base_url=endpoint)
        mnemonics, _pub_k, _priv_k, wallet = Wallets.from_mnemonics(self.mnemonic, WalletVersionEnum('v4r2'), 0)
        seqno = await client.get_wallet_seqno(wallet.address.to_string(True, True, True))
        query = wallet.create_transfer_message(
            address.to_string(True, True, True),
            value,
            seqno,
            body,
            state_init=state_init
        )
        boc = bytes_to_b64str(query["message"].to_boc(False))
        await client.send_boc(boc)

Last updated

Was this helpful?