mitinarseny / toner

🦀 + 💎 Rust SDK for TON blockchain
https://docs.rs/toner
MIT License
8 stars 2 forks source link

wallet v5r1 `create_external_message` send boc error #6

Open alexlee85 opened 3 weeks ago

alexlee85 commented 3 weeks ago

I use V5R1 Wallet to send some TON, but when I use toncenter api to send base64 encoded boc, it failed. code

    let keypair = mnemonic.generate_keypair(None)?;
    let wallet = Wallet::<V5R1>::derive(0, keypair, V5R1_MAINNET_WALLET_ID)?;

    let transfer_val = 30_000_000.to_biguint().unwrap();
    let msg = Message::transfer(wallet2.address(), transfer_val, false).normalize()?;
    let action = SendMsgAction {
        mode: 3,
        message: msg,
    };
    let external_msg = wallet.create_external_message(Default::default(), 8, [action], false)?;

    let boc = BagOfCells::from_root(external_msg.to_cell()?);
    println!("boc: {boc:?}");
    let packed = pack_with(
        boc,
        BagOfCellsArgs {
            has_idx: false,
            has_crc32c: true,
        },
    )?;

    let bytes = packed.as_raw_slice();

    let boc_bs64 = base64::engine::general_purpose::STANDARD.encode(bytes);
    println!("base64: {boc_bs64}");

anything I'm wrong? need help !

mitinarseny commented 3 days ago

Hi, @alexlee85! Thank you for your feedback!

TonCenter and other TON APIs usually just ignore the messages that fail at the stage of simulation, as it makes no sense to actually propagate this message further to the validators as it would likely fail there as well.

It seems like there can be either two reasons for it:

  1. You generate the keypair right before sending the transaction. So, there is no code deployed on this address. Therefore, you should pass state_init = true on wallet.create_external_message(...)
  2. The address of the wallet contract that is about to be deployed would also have zero TON balance, so it would fail to pay the state_init fees. You have to deposit some TON to this address first by sending non-bouncible transfer to this address. This type of transfer is usually done by wallet applications like Tonkeeper.

There can also be something wrong with impl WalletVersion for V5R1, but I would start with fixing these two mentioned above first.

If the problem still occurs, please let me know and I'll investigate further!