toncenter / examples

TON JS examples
MIT License
106 stars 31 forks source link

Ton Network Blockchain transfer method is not working #2

Open Shivam-Vatshayan opened 1 year ago

Shivam-Vatshayan commented 1 year ago

My Code :

const transfer = async () => {
    try {
        const WalletClass = tonweb.wallet.all['v4R2'];
        const wallet = new WalletClass(tonweb.provider, {
            publicKey: HOT_WALLET_ADDRESS,
            wc: 0
        });
        // const seqno = await wallet.methods.seqno().call() || 0;
        let string_private_key = JSON.parse(HOT_WALLET_PRIVATE_KEY)

        const keyPair = TonWeb.utils.nacl.sign.keyPair.fromSecretKey(Buffer.from(string_private_key), "hex");
        let amountsToTransfer = TonWeb.utils.toNano('0.01');
        console.log(amountsToTransfer);
        // Create transfer
        const transfer = await wallet.methods.transfer({
            secretKey: keyPair.secretKey,
            toAddress: 'EQDQfus9g97M88HUtU8JHDPHk_YKGo8u7Zs6yrhOHbqXvImS',
            amount: amountsToTransfer, // 0.01 TON
            seqno: 0,
            payload: 'The aim of this text is to provide a brief',
        });
        // get estimate fee of transfer
        const transferFee = await transfer.estimateFee();
        console.log(transferFee);
        // send transfer query to blockchain
        const transferSended = await transfer.send();
        console.log(transferSended);

        const query = await transfer.getQuery();
        console.log(query);

        // const boc = TonWeb.utils.bytesToBase64(await query.toBoc(false)); // serialized query
        // // await tonweb.provider.sendBoc(boc); // send query to network

        // // Parse query

        // try {
        //     const parsed = WalletClass.parseTransferQuery(TonWeb.boc.Cell.oneFromBoc(TonWeb.utils.base64ToBytes(boc)));

        //     parsed.value = parsed.value.toString();
        //     parsed.fromAddress = parsed.fromAddress.toString(true, true, true);
        //     parsed.toAddress = parsed.toAddress.toString(true, true, true);
        //     console.log(parsed);
        // } catch (e) {
        //     console.error(e); // not valid wallet transfer query
        // }
    } catch (error) {
        console.log('catch error => ', error)
    }
}
transfer();

Getting Issue after running ton transfer method is :

BN { negative: 0, words: [ 10000000 ], length: 1, red: null } catch error => Error: Invalid character at assert (/home/charvik/codes/tests/ton/node_modules/bn.js/lib/bn.js:6:21) at parseBase (/home/charvik/codes/tests/ton/node_modules/bn.js/lib/bn.js:269:7) at BN._parseBase (/home/charvik/codes/tests/ton/node_modules/bn.js/lib/bn.js:305:14) at BN.init [as _init] (/home/charvik/codes/tests/ton/node_modules/bn.js/lib/bn.js:99:12) at new BN (/home/charvik/codes/tests/ton/node_modules/bn.js/lib/bn.js:39:12) at BitString.writeUint (/home/charvik/codes/tests/ton/node_modules/tonweb/src/boc/BitString.js:118:18) at BitString.writeUint8 (/home/charvik/codes/tests/ton/node_modules/tonweb/src/boc/BitString.js:167:14) at BitString.writeBytes (/home/charvik/codes/tests/ton/node_modules/tonweb/src/boc/BitString.js:176:18) at WalletV4ContractR2.createDataCell (/home/charvik/codes/tests/ton/node_modules/tonweb/src/contract/wallet/WalletContractV4R2.js:66:19) at WalletV4ContractR2.createStateInit (/home/charvik/codes/tests/ton/node_modules/tonweb/src/contract/index.js:51:31)

seshorenkinjutsushi commented 8 months ago

UQA0pnYTNKx6u2XJIEOy31yzmmvDMxMnNPXaedQPXr3XfPIP

kraken7984 commented 8 months ago

****https://github.com/toncenter/examples/issues/2#issue-1717091775[](url)parsed.value