使用 Python 在 TON 区块链上发送硬币/jettons

问题描述 投票:0回答:1

如何使用 Python 将硬币/jettons(例如 Notcoin)从一个 TON 区块链钱包发送到另一个钱包? 没有一个 SDK 有可行的示例。 😞

python blockchain ton
1个回答
0
投票

ton 社区提供了

asset-sdk
及其使用示例。

以下代码是转移jettons的示例:

import {Address, toNano} from "@ton/core";
import {AssetsSDK, createApi, createSender, importKey, PinataStorageParams} from "../src";

async function main() {
    const NETWORK = 'testnet';
    const api = await createApi(NETWORK);

    const keyPair = await importKey(process.env.MNEMONIC!);
    const sender = await createSender('highload-v2', keyPair, api);

    const storage: PinataStorageParams = {
        pinataApiKey: process.env.PINATA_API_KEY!,
        pinataSecretKey: process.env.PINATA_SECRET!,
    }

    const sdk = AssetsSDK.create({
        api: api,
        storage: storage,
        sender: sender,
    });

    console.log('Using wallet', sdk.sender?.address);

    const JETTON_ADDRESS = Address.parse('MY_JETTON_ADDRESS');
    const jetton = await sdk.openJetton(JETTON_ADDRESS);

    const RECEIVER_ADDRESS = Address.parse('RECEIVER_ADDRESS');
    const myJettonWallet = await jetton.getWallet(sdk.sender!.address!);
    await myJettonWallet.send(sender, RECEIVER_ADDRESS, toNano(10));
}

main().catch(console.error);
© www.soinside.com 2019 - 2024. All rights reserved.