ton-org / ton

Most popular TON Typescript Library
MIT License
181 stars 44 forks source link

How do you know if the transfer was successful or failed? #57

Open 3lang3 opened 2 months ago

3lang3 commented 2 months ago

I used the following code to transfer money, but it was actually unsuccessful but the code did not throw an error

import { TonClient, WalletContractV4, internal , toNano} from "@ton/ton";
import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";

// Create Client
const client = new TonClient({
  endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});

let keyPair = await mnemonicToPrivateKey(" "); // balance 1ton

// Create wallet contract
let workchain = 0; // Usually you need a workchain 0
let wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey }); 
let contract = client.open(wallet);

// Get balance
let balance: bigint = await contract.getBalance();

// Create a transfer
let seqno: number = await contract.getSeqno();
let transfer = await contract.createTransfer({
  seqno,
  secretKey: keyPair.secretKey,
  messages: [internal({
    value: toNano('100'), // send 100 ton to receiver
    to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
    body: 'Hello world',
  })]
});
await client.sendExternalMessage(contract, transfer)

There is not enough balance in the sender's wallet, but the code will not throw an error

3lang3 commented 2 months ago

It's so strange that I can't find any documents about this at all.

3lang3 commented 2 months ago

anynone can help me?

bluezdot commented 2 months ago

@3lang3 I have the same problem. Maybe there's not a method to get tx status at this time. 

3lang3 commented 2 months ago

@3lang3 I have the same problem. Maybe there's not a method to get tx status at this time.

I don't know how others solved it, it's a very basic function

bluezdot commented 1 month ago

@3lang3 I have the same problem. Maybe there's not a method to get tx status at this time.

I don't know how others solved it, it's a very basic function

I'm personally using this api to check tx fail or not. It's a bit complicated (need to process data and call the api many time).