Torch DEX
WebsiteSwap
  • Overview
  • Terms of Use
  • Getting Started
    • Introduction
    • Challenges on TON
    • Solution for TON
    • Architecture
      • Concept
      • Core Components
        • Factory
        • Vault
        • Pool
        • LP Account
        • Oracle
      • Comparison
      • Interoperability
      • Meesage Flows
        • Deposit
        • Swap
        • Withdraw
        • Cross-Pool Operations
  • Developer Guide
    • DEX SDK Guide
      • Setup
      • Perform Swap
      • Deposit Liquidity
      • Withdraw Liquidity
      • How to send transaction
        • Mnemonic (Node JS)
        • TonConnect (React)
      • Deployments
  • USER Guide
    • Getting Started
  • Protocol
    • Audits
    • Tokenomics
  • Other
    • Brand Kit
    • Contacts
    • Achievements
  • FAQ
    • How to get Transaction hash by Message hash
    • React (Vite) - Buffer Issues
Powered by GitBook
On this page
  1. Developer Guide
  2. DEX SDK Guide
  3. How to send transaction

Mnemonic (Node JS)

PreviousHow to send transactionNextTonConnect (React)

Last updated 8 months ago

CtrlK
import { mnemonicToWalletKey } from '@ton/crypto';
import {
  internal,
  SenderArguments,
  SendMode,
  TonClient4,
  WalletContractV5R1,
} from '@ton/ton';
import { getMsgHash } from './utils';

export const getWalletV5 = async (client: TonClient4, mnemonic: string[]) => {
  const keyPair = await mnemonicToWalletKey(mnemonic);
  const wallet = client.open(
    WalletContractV5R1.create({
      workchain: 0,
      publicKey: keyPair.publicKey,
      walletId: {
        networkGlobalId: -3,
      },
    })
  );

  const send = async (
    args: SenderArguments | SenderArguments[]
  ): Promise<string> => {
    args = Array.isArray(args) ? args : [args];
    const msg = wallet.createTransfer({
      seqno,
      secretKey: keyPair.secretKey,
      messages: args.map(arg => {
        return internal({
          to: arg.to,
          value: arg.value,
          body: arg.body,
        });
      }),
      sendMode: SendMode.PAY_GAS_SEPARATELY,
      timeout: Math.floor(Date.now() / 1000) + 60,
    });
    await wallet.send(msg);
    const msgHash = getMsgHash(wallet.address.toString(), msg);
    return msgHash;
  };

  return {
    keyPair,
    wallet,
    send,
  };
};