Перейти к содержанию

Операции с Jetton

Этот раздел предоставляет полное руководство по работе с Jetton с использованием библиотеки tonutils. Описаны операции как с Stablecoin Jetton (by Notcoin), так и со Standard Jetton, включая развёртывание, выпуск, сжигание, администрирование и обмен через децентрализованные биржи, такие как STON.fi и DeDust.io.


Stablecoin Jetton

Развёртывание Jetton Master

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.jetton.content import JettonStablecoinContent
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the administrator for managing the Jetton Master
ADMIN_ADDRESS = "UQ..."

# URI for the off-chain content of the Jetton
# https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-example-offchain
URI = "https://example.com/jetton.json"


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    jetton_master = JettonMasterStablecoin(
        content=JettonStablecoinContent(URI),
        admin_address=ADMIN_ADDRESS,
    )

    tx_hash = await wallet.transfer(
        destination=jetton_master.address,
        amount=0.05,
        state_init=jetton_master.state_init,
    )

    print(f"Successfully deployed Jetton Master at address: {jetton_master.address.to_str()}")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обновление контракта

from pytoniq_core import Cell

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# Cell containing the updated contract code
NEW_CODE_CELL = Cell.one_from_boc("code hex")

# Cell containing the updated contract data
NEW_DATA_CELL = Cell.one_from_boc("data hex")


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStablecoin.build_upgrade_message_body(
        new_code=NEW_CODE_CELL,
        new_data=NEW_DATA_CELL,
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully upgraded the contract!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Выпуск Jetton

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# The amount of Jettons to mint (in base units, considering decimals)
JETTON_AMOUNT = 1000000


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStablecoin.build_mint_body(
        destination=wallet.address,
        jetton_amount=int(JETTON_AMOUNT * (10 ** 9)),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.1,
        body=body,
    )

    print(f"Successfully minted {JETTON_AMOUNT} Jettons!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Сжигание Jetton

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin, JettonWalletStablecoin
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# The amount of Jettons to burn (in base units, considering decimals)
JETTON_AMOUNT = 0.01


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    jetton_wallet_address = await JettonMasterStablecoin.get_wallet_address(
        client=client,
        owner_address=wallet.address.to_str(),
        jetton_master_address=JETTON_MASTER_ADDRESS,
    )
    body = JettonWalletStablecoin.build_burn_body(
        jetton_amount=int(JETTON_AMOUNT * (10 ** 9)),
        response_address=wallet.address,
    )

    tx_hash = await wallet.transfer(
        destination=jetton_wallet_address,
        amount=0.05,
        body=body,
    )

    print(f"Successfully burned {JETTON_AMOUNT} Jettons!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Смена администратора

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract where the admin will be changed
JETTON_MASTER_ADDRESS = "EQ..."

# The new administrator address to be set for the Jetton Master contract
NEW_ADMIN_ADDRESS = "UQ..."


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStablecoin.build_change_admin_body(
        new_admin_address=Address(NEW_ADMIN_ADDRESS),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully changed the admin of the Jetton Master!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Удаление администратора

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract where the admin will be changed
JETTON_MASTER_ADDRESS = "EQ..."


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStablecoin.build_drop_admin_body()

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Jetton Master admin has been successfully dropped!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Изменение контента

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStablecoin
from tonutils.jetton.content import JettonStablecoinContent
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# New URI for the Jetton offchain content
# https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-example-offchain
NEW_URI = "https://example.com/new-jetton.json"


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStablecoin.build_change_content_body(
        new_content=JettonStablecoinContent(NEW_URI),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully updated Jetton content!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Standard Jetton

Развёртывание Jetton Master (ончейн)

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard
from tonutils.jetton.content import JettonOnchainContent
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the administrator for managing the Jetton Master
ADMIN_ADDRESS = "UQ..."


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    jetton_master = JettonMasterStandard(
        content=JettonOnchainContent(
            name="Ness Jetton",
            symbol="NESS",
            description="Probably nothing",
            decimals=9,
            image="https://example.com/image.png",
        ),
        admin_address=ADMIN_ADDRESS,
    )

    tx_hash = await wallet.transfer(
        destination=jetton_master.address,
        amount=0.05,
        state_init=jetton_master.state_init,
    )

    print(f"Successfully deployed Jetton Master at address: {jetton_master.address.to_str()}")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Развёртывание Jetton Master (оффчейн)

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard
from tonutils.jetton.content import JettonOffchainContent
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the administrator for managing the Jetton Master
ADMIN_ADDRESS = "UQ..."

# URI for the off-chain content of the Jetton
# https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-example-offchain
URI = "https://example.com/jetton.json"


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    jetton_master = JettonMasterStandard(
        content=JettonOffchainContent(URI),
        admin_address=ADMIN_ADDRESS,
    )

    tx_hash = await wallet.transfer(
        destination=jetton_master.address,
        amount=0.05,
        state_init=jetton_master.state_init,
    )

    print(f"Successfully deployed Jetton Master at address: {jetton_master.address.to_str()}")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Выпуск Jetton

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# The amount of Jettons to mint (in base units, considering decimals)
JETTON_AMOUNT = 1000000

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStandard.build_mint_body(
        destination=wallet.address,
        jetton_amount=int(JETTON_AMOUNT * (10 ** JETTON_DECIMALS)),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully minted {JETTON_AMOUNT} Jettons!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Сжигание Jetton

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard, JettonWalletStandard
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# The number of decimal places for the Jetton
JETTON_DECIMALS = 9

# The amount of Jettons to burn (in base units, considering decimals)
JETTON_AMOUNT = 0.01


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    jetton_wallet_address = await JettonMasterStandard.get_wallet_address(
        client=client,
        owner_address=wallet.address.to_str(),
        jetton_master_address=JETTON_MASTER_ADDRESS,
    )
    body = JettonWalletStandard.build_burn_body(
        jetton_amount=int(JETTON_AMOUNT * (10 ** JETTON_DECIMALS)),
        response_address=wallet.address,
    )

    tx_hash = await wallet.transfer(
        destination=jetton_wallet_address,
        amount=0.05,
        body=body,
    )

    print(f"Successfully burned {JETTON_AMOUNT} Jettons!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Смена администратора

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract where the admin will be changed
JETTON_MASTER_ADDRESS = "EQ..."

# The new administrator address to be set for the Jetton Master contract
NEW_ADMIN_ADDRESS = "UQ..."


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStandard.build_change_admin_body(
        new_admin_address=Address(NEW_ADMIN_ADDRESS),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully changed the admin of the Jetton Master!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Изменение контента

from tonutils.client import ToncenterV3Client
from tonutils.jetton import JettonMasterStandard
from tonutils.jetton.content import JettonOffchainContent
from tonutils.wallet import WalletV4R2

# Set to True for test network, False for main network
IS_TESTNET = True

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# The address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."

# New URI for the Jetton offchain content
# https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#jetton-metadata-example-offchain
NEW_URI = "https://example.com/new-jetton.json"


async def main() -> None:
    client = ToncenterV3Client(is_testnet=IS_TESTNET, rps=1, max_retries=1)
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    body = JettonMasterStandard.build_change_content_body(
        new_content=JettonOffchainContent(NEW_URI),
    )

    tx_hash = await wallet.transfer(
        destination=JETTON_MASTER_ADDRESS,
        amount=0.05,
        body=body,
    )

    print(f"Successfully updated Jetton content!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обмен Jetton

Через STON.fi

Обмен TON → Jetton

Note

Перед использованием обязательно ознакомьтесь с официальной документацией STON.fi. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.stonfi import StonfiRouterV2, StonfiRouterV1
from tonutils.jetton.dex.stonfi.utils import get_stonfi_router_details
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Address of the Jetton Master for swapping (TON > USD₮)
TO_JETTON_MASTER_ADDRESS = "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"  # noqa

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9

# Amount of TON to swap (in base units, considering decimals)
TON_AMOUNT = 1

# Minimum amount of Jettons to receive (in base units, considering decimals)
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    version, router_address, pton_address = await get_stonfi_router_details(
        offer_address="ton",
        ask_address=TO_JETTON_MASTER_ADDRESS,
        amount=TON_AMOUNT,
        decimals=9,
        is_testnet=client.is_testnet,
    )

    if version == 1:
        router_v1 = StonfiRouterV1(client, router_address, pton_address)

        to, value, body = await router_v1.get_swap_ton_to_jetton_tx_params(
            user_wallet_address=wallet.address,
            ask_jetton_address=Address(TO_JETTON_MASTER_ADDRESS),
            offer_amount=to_nano(TON_AMOUNT),
            min_ask_amount=to_nano(MIN_AMOUNT, JETTON_DECIMALS),
        )
    else:
        router_v2 = StonfiRouterV2(client, router_address, pton_address)

        to, value, body = await router_v2.get_swap_ton_to_jetton_tx_params(
            user_wallet_address=wallet.address,
            receiver_address=wallet.address,
            ask_jetton_address=Address(TO_JETTON_MASTER_ADDRESS),
            offer_amount=to_nano(TON_AMOUNT),
            min_ask_amount=to_nano(MIN_AMOUNT, JETTON_DECIMALS),
            refund_address=wallet.address,
        )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped TON to Jetton!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обмен Jetton → TON

Note

Перед использованием обязательно ознакомьтесь с официальной документацией STON.fi. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.stonfi import StonfiRouterV2, StonfiRouterV1
from tonutils.jetton.dex.stonfi.utils import get_stonfi_router_details
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Addresses of the Jetton Masters for swapping
FROM_JETTON_MASTER_ADDRESS = "EQ..."  # noqa

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9

# Amount of Jettons to swap (in base units, considering decimals)
JETTON_AMOUNT = 1

# Minimum amount of TON to receive
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    version, router_address, pton_address = await get_stonfi_router_details(
        offer_address=FROM_JETTON_MASTER_ADDRESS,
        ask_address="ton",
        amount=JETTON_AMOUNT,
        decimals=JETTON_DECIMALS,
        is_testnet=client.is_testnet,
    )

    if version == 1:
        router_v1 = StonfiRouterV1(client, router_address, pton_address)

        to, value, body = await router_v1.get_swap_jetton_to_ton_tx_params(
            offer_jetton_address=Address(FROM_JETTON_MASTER_ADDRESS),
            user_wallet_address=wallet.address,
            offer_amount=to_nano(JETTON_AMOUNT, JETTON_DECIMALS),
            min_ask_amount=to_nano(MIN_AMOUNT),
        )
    else:
        router_v2 = StonfiRouterV2(client, router_address, pton_address)

        to, value, body = await router_v2.get_swap_jetton_to_ton_tx_params(
            offer_jetton_address=Address(FROM_JETTON_MASTER_ADDRESS),
            receiver_address=wallet.address,
            user_wallet_address=wallet.address,
            offer_amount=to_nano(JETTON_AMOUNT, JETTON_DECIMALS),
            min_ask_amount=to_nano(MIN_AMOUNT),
            refund_address=wallet.address,
        )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped Jetton to TON!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обмен Jetton → Jetton

Note

Перед использованием обязательно ознакомьтесь с официальной документацией STON.fi. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.stonfi import StonfiRouterV2, StonfiRouterV1
from tonutils.jetton.dex.stonfi.utils import get_stonfi_router_details
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Addresses of the Jetton Masters for swapping
FROM_JETTON_MASTER_ADDRESS = "EQ..."  # noqa
TO_JETTON_MASTER_ADDRESS = "EQ..."  # noqa

# Number of decimal places for the Jetton
FROM_JETTON_DECIMALS = 6
TO_JETTON_DECIMALS = 9

# Amount of Jettons to swap (in base units, considering decimals)
JETTON_AMOUNT = 1

# Minimum amount of Jettons to receive (in base units, considering decimals)
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    version, router_address, pton_address = await get_stonfi_router_details(
        offer_address=FROM_JETTON_MASTER_ADDRESS,
        ask_address=TO_JETTON_MASTER_ADDRESS,
        amount=JETTON_AMOUNT,
        decimals=FROM_JETTON_DECIMALS,
        is_testnet=client.is_testnet,
    )

    if version == 1:
        router_v1 = StonfiRouterV1(client, router_address, pton_address)
        to, value, body = await router_v1.get_swap_jetton_to_jetton_tx_params(
            user_wallet_address=wallet.address,
            offer_jetton_address=Address(FROM_JETTON_MASTER_ADDRESS),
            ask_jetton_address=Address(TO_JETTON_MASTER_ADDRESS),
            offer_amount=to_nano(JETTON_AMOUNT, FROM_JETTON_DECIMALS),
            min_ask_amount=to_nano(MIN_AMOUNT, TO_JETTON_DECIMALS),
        )
    else:
        router_v2 = StonfiRouterV2(client, router_address, pton_address)
        to, value, body = await router_v2.get_swap_jetton_to_jetton_tx_params(
            user_wallet_address=wallet.address,
            receiver_address=wallet.address,
            refund_address=wallet.address,
            offer_jetton_address=Address(FROM_JETTON_MASTER_ADDRESS),
            ask_jetton_address=Address(TO_JETTON_MASTER_ADDRESS),
            offer_amount=to_nano(JETTON_AMOUNT, FROM_JETTON_DECIMALS),
            min_ask_amount=to_nano(MIN_AMOUNT, TO_JETTON_DECIMALS),
        )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped Jetton to Jetton!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Через DeDust.io

Обмен TON → Jetton

Note

Перед использованием обязательно ознакомьтесь с официальной документацией DeDust.io. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.dedust import Factory
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."  # noqa

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9

# Amount of TON to swap
TON_AMOUNT = 1

# Minimum amount of Jettons to receive (in base units, considering decimals)
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    to, value, body = await Factory(client).get_swap_ton_to_jetton_tx_params(
        recipient_address=wallet.address,
        offer_jetton_address=Address(JETTON_MASTER_ADDRESS),
        offer_amount=to_nano(TON_AMOUNT),
        min_ask_amount=to_nano(MIN_AMOUNT, JETTON_DECIMALS),
    )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped TON to Jetton!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обмен Jetton → TON

Note

Перед использованием обязательно ознакомьтесь с официальной документацией DeDust.io. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.dedust import Factory
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Address of the Jetton Master contract
JETTON_MASTER_ADDRESS = "EQ..."  # noqa

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9

# Amount of Jettons to swap (in base units, considering decimals)
JETTON_AMOUNT = 1

# Minimum amount of TON to receive
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    to, value, body = await Factory(client).get_swap_jetton_to_ton_tx_params(
        recipient_address=wallet.address,
        offer_jetton_address=Address(JETTON_MASTER_ADDRESS),
        offer_amount=to_nano(JETTON_AMOUNT, JETTON_DECIMALS),
        min_ask_amount=to_nano(MIN_AMOUNT),
    )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped Jetton to TON!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Обмен Jetton → Jetton

Note

Перед использованием обязательно ознакомьтесь с официальной документацией DeDust.io. Используйте с осторожностью и всегда тестируйте сначала в тестовой сети. Автор не несёт никакой ответственности за возможные потери средств. Нашли ошибку или есть предложения — создайте pull request.

from pytoniq_core import Address

from tonutils.client import ToncenterV3Client
from tonutils.jetton.dex.dedust import Factory
from tonutils.utils import to_nano, to_amount
from tonutils.wallet import WalletV4R2

# Mnemonic phrase
MNEMONIC = "word1 word2 word3 ..."

# Addresses of the Jetton Masters for swapping
FROM_JETTON_MASTER_ADDRESS = "EQ..."  # noqa
TO_JETTON_MASTER_ADDRESS = "EQ..."  # noqa

# Number of decimal places for the Jetton
FROM_JETTON_DECIMALS = 6
TO_JETTON_DECIMALS = 9

# Amount of Jettons to swap (in base units, considering decimals)
JETTON_AMOUNT = 1

# Number of decimal places for the Jetton
JETTON_DECIMALS = 9

# Minimum amount of Jettons to receive (in base units, considering decimals)
MIN_AMOUNT = 0


async def main() -> None:
    client = ToncenterV3Client()
    wallet, _, _, _ = WalletV4R2.from_mnemonic(client, MNEMONIC)

    to, value, body = await Factory(client).get_swap_jetton_to_jetton_tx_params(
        recipient_address=wallet.address,
        offer_jetton_address=Address(FROM_JETTON_MASTER_ADDRESS),
        ask_jetton_address=Address(TO_JETTON_MASTER_ADDRESS),
        offer_amount=to_nano(JETTON_AMOUNT, FROM_JETTON_DECIMALS),
        min_ask_amount=to_nano(MIN_AMOUNT, TO_JETTON_DECIMALS),
    )

    tx_hash = await wallet.transfer(
        destination=to,
        amount=to_amount(value),
        body=body,
    )

    print("Successfully swapped Jetton to Jetton!")
    print(f"Transaction hash: {tx_hash}")


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())