Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send bounceable transaction? #27

Open
mahnunchik opened this issue Feb 20, 2024 · 2 comments
Open

How to send bounceable transaction? #27

mahnunchik opened this issue Feb 20, 2024 · 2 comments

Comments

@mahnunchik
Copy link

How to send bounceable transfer of native TON?

According to the documentation:

To send bounceable transfer it is required to set bounce flag in internal message and use sending mode +16.

+16 | In the case of action fail - bounce transaction

It is uninitialized wallet: https://testnet.tonviewer.com/EQAfs3mJctSyXlJpR89j6h1T7fYJ_nBt8hGbfkDUaET7x9p8

Code sample:

import { WalletContractV4, TonClient, internal } from '@ton/ton';

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

const walletContract = client.open(wallet);
const seqno = await walletContract.getSeqno();

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 16,
  messages: [
    internal({
      to: 'EQAfs3mJctSyXlJpR89j6h1T7fYJ_nBt8hGbfkDUaET7x9p8',
      value: 12345,
      bounce: true,
      // sender is fresh wallet so init it
      init: wallet.init,
    })
  ],
});

await walletContract.send(transfer);

Expected behaviour

Transaction amount is returned to sender minus fee

Actual bahaviour

An infinite number of attempts has spent the sender's entire balance https://testnet.tonviewer.com/0QA3tr_6AZK9qMQy46a7ULtriizI7iXeiPufNxib4a7b6eU8

@mahnunchik mahnunchik changed the title How to send **bounceable** transaction? How to send *bounceable* transaction? Feb 20, 2024
@mahnunchik mahnunchik changed the title How to send *bounceable* transaction? How to send bounceable transaction? Feb 20, 2024
@mahnunchik
Copy link
Author

@mahnunchik
Copy link
Author

mahnunchik commented Feb 21, 2024

Ok, i'm trying to send bounce: true transaction with sendMode set to 2 and 3.

sendMode=3 and amount=100 000

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 3,
  messages: [
    internal({
      to: 'EQC2u1E2lxn_p1HZH61ByEOs706E0ijCNXOXnDTXoZ31-hNw',
      value: 100_000,
      bounce: true,
    }),
  ],
});

Transaction NOT bounced back and destination account received 0.0001 TON https://testnet.tonviewer.com/transaction/31ee4bdef19efa45a37b24f59ab500817187e1fe40681eb0bbfaf7fa21284cba

How it is possible?

sendMode=2 and amount=1 000 000

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 2,
  messages: [
    internal({
      to: 'EQBQRxKlTcoc_ZVpBiLyfauHxL3MO2TNefrKnr7s-OqKP_Go',
      value: 1_000_000,
      bounce: true,
    }),
  ],
});

Transaction NOT bounced back (the entire amount was spent on fee): https://testnet.tonviewer.com/transaction/5a91a594a5c5d5714481aecfca6fb7bff354100b34e5f22af139201c2fa24b82

sendMode=2 and amount=10 000 000

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 2,
  messages: [
    internal({
      to: 'EQDDzK-DSq5YMABLNYk4S3ZkivasHhOWe9JJqDcVLSUnQ6qf',
      value: 10_000_000,
      bounce: true,
    }),
  ],
});

Transaction successfully bounced back: https://testnet.tonviewer.com/transaction/9719e6c60ab9992366c465cf49358efaab0e93ac743d986b01afa01438ef2aaf

sendMode=3 and amount=10 000 000

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 3,
  messages: [
    internal({
      to: 'EQDDzK-DSq5YMABLNYk4S3ZkivasHhOWe9JJqDcVLSUnQ6qf',
      value: 10_000_000,
      bounce: true,
    }),
  ],
});

Transaction successfully bounced back: https://testnet.tonviewer.com/transaction/3fcff5b741b6e7bbd02b493afd32bb7c218fc9a518c1c819dd7ba337ef9c0207

sendMode=3 and amount=1 000 000

const transfer = await walletContract.createTransfer({
  secretKey: key.secretKey,
  seqno: seqno,
  sendMode: 3,
  messages: [
    internal({
      to: 'EQBQRxKlTcoc_ZVpBiLyfauHxL3MO2TNefrKnr7s-OqKP_Go',
      value: 1_000_000,
      bounce: true,
    }),
  ],
});

Transaction successfully bounced back (the entire amount was spent on fee): https://testnet.tonviewer.com/transaction/ef610379982ad3334407c5c9ae35dd7f3529b354b21855f39b45db65b7658756

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant