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

create_simple_transfer did't send ton to dest wallet address. #133

Closed
jackbbhua opened this issue Jan 5, 2025 · 1 comment
Closed

create_simple_transfer did't send ton to dest wallet address. #133

jackbbhua opened this issue Jan 5, 2025 · 1 comment

Comments

@jackbbhua
Copy link

`
use anyhow::anyhow;
use num_bigint::BigUint;
use std::time::SystemTime;
use std::sync::Arc;

use tonlib_core::TonAddress;
use tonlib_core::cell::BagOfCells;
use tonlib_core::message::TransferMessage;
use tonlib_core::wallet::TonWallet;
use tonlib_client::client::TonClient;
use tonlib_client::client::TonClientInterface;
use tonlib_core::mnemonic::KeyPair;
use tonlib_core::mnemonic::Mnemonic;
use tonlib_core::wallet::WalletVersion;
use tonlib_core::message::TonMessage;
use tonlib_core::message::CommonMsgInfo;
use tonlib_core::message::ExternalIncomingMessage;

async fn create_simple_transfer() -> anyhow::Result<()> {
let mnemonic = Mnemonic::new(
vec![
"dose", "ice", "enrich", "trigger", "test", "dove", "century", "still", "betray",
"gas", "diet", "dune",
],
&None,
)?;
let key_pair = mnemonic.to_key_pair()?;
let seqno = 30000000;

let client = TonClient::default().await?;
let wallet = TonWallet::derive_default(WalletVersion::V4R2, &key_pair)?;
let src: TonAddress = "<source wallet address>".parse()?;
let dest: TonAddress = "<destination wallet address>".parse()?;
let value = BigUint::from(10000000u64); // 0.01 TON
let external_msg_info = ExternalIncomingMessage{
    src,
    dest,
    import_fee: value,
};
let common_msg_info = CommonMsgInfo::ExternalIncomingMessage(external_msg_info);
let transfer = TransferMessage::new(common_msg_info).build()?;
let now = SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH)?
    .as_secs() as u32;
let body = wallet.create_external_body(now + 60, seqno, vec![Arc::new(transfer)])?;
let signed = wallet.sign_external_body(&body)?;
let wrapped = wallet.wrap_signed_body(signed, true)?;
let boc = BagOfCells::from_root(wrapped);
let tx = boc.serialize(true)?;
let hash = client.send_raw_message_return_hash(tx.as_slice()).await?;

Ok(())

}`

I use this code, and the send ton result like this:
https://testnet.tonviewer.com/transaction/40078342e4f95883f9a8b54195687f41327d1b8defcf46bb776239c48af0aaac

Please check the error. thanks.

@jackbbhua
Copy link
Author

jackbbhua commented Jan 9, 2025

is there has any update? I use testnet for testing right now.

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

2 participants
@jackbbhua and others