使用tonweb和Node.JS在TON区块链中交易失败

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

我正在尝试将一笔交易从我的钱包发送到其他地址,金额为 10 NOT。我正在使用 tonweb,我的应用程序位于 node.js 上。 这是代码:

const TonWeb = require('tonweb');
const tonMnemonic = require('tonweb-mnemonic');
const { JettonMinter, JettonWallet } = TonWeb.token.jetton;
const crypto = require('crypto');

const mnemonic = '';

const JETTON_CONTRACT_ADDRESS = 'EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT';
const WALLET2_ADDRESS = '';

const API_KEY = '';
const tonweb = new TonWeb(new TonWeb.HttpProvider('https://toncenter.com/api/v2/jsonRPC', { apiKey: API_KEY }));

const generateUniqueQueryId = () => {
    const buffer = crypto.randomBytes(8);
    return buffer.readBigUInt64BE().toString();
};

const main = async () => {
    try {
        console.log("Starting transaction process...");

        const keyPair = await tonMnemonic.mnemonicToKeyPair(mnemonic.split(' '));
        console.log("Key pair generated:", keyPair);

        const WalletClass = tonweb.wallet.all.v4R2;
        const wallet = new WalletClass(tonweb.provider, {
            publicKey: keyPair.publicKey
        });
        const walletAddress = await wallet.getAddress();
        console.log("Wallet address:", walletAddress.toString(true, true, true));

        const jettonMinter = new JettonMinter(tonweb.provider, { address: new TonWeb.utils.Address(JETTON_CONTRACT_ADDRESS) });
        const jettonWalletAddress = await jettonMinter.getJettonWalletAddress(walletAddress);
        console.log("Jetton wallet address:", jettonWalletAddress.toString(true, true, true));

        const jettonWallet = new JettonWallet(tonweb.provider, { address: jettonWalletAddress });

        const seqno = (await wallet.methods.seqno().call()) || 0;
        console.log("Seqno:", seqno);

        const query_id = generateUniqueQueryId();

        const transferBody = await jettonWallet.createTransferBody({
            queryId: query_id,
            jettonAmount: TonWeb.utils.toNano('10'),
            toAddress: new TonWeb.utils.Address(WALLET2_ADDRESS),
            responseAddress: walletAddress,
            forwardAmount: '1'
        });

        console.log("Transfer body created:", JSON.stringify(transferBody, null, 2));

        const transferResult = await wallet.methods.transfer({
            secretKey: keyPair.secretKey,
            toAddress: jettonWalletAddress,
            amount: TonWeb.utils.toNano('0.01'), // Комиссия за перевод
            seqno: seqno,
            payload: transferBody,
            sendMode: 3,
        }).send();
        console.log("Transfer result:", transferResult);
    } catch (error) {
        console.error("Error during transaction:", error);
    }
};

main().catch(console.error);

这是我在日志中得到的内容:

Transfer result: { '@type': 'ok', '@extra': '1719774172.7632153:1:0.99                                                                                                                                                             25906308061954' }

但是交易失败! 以下是其中一些交易的示例: https://tonviewer.com/transaction/08c4618cde57d25ccb2d492c1dee6761a45cd248b32d9a825ff60f693c4cb601 https://tonviewer.com/transaction/aa443e512407108f863d9cac53a6756133a4819a89999b01ef815ba9e6402c49

我做错了什么?花了 3 天,仍然无法解决问题:) 请帮助我

我预计交易状态会是“成功”,并且会成功发送到区块链

javascript node.js blockchain ton
1个回答
0
投票

комиссию 0.1 поставь, остатки вернутся

© www.soinside.com 2019 - 2024. All rights reserved.