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

read me sample not work #73

Open
StewartYe opened this issue Jul 12, 2024 · 1 comment
Open

read me sample not work #73

StewartYe opened this issue Jul 12, 2024 · 1 comment

Comments

@StewartYe
Copy link

I use the code in readme to create a jetton transfer. but the message is rejected by Ton

use num_bigint::BigUint;
use std::time::SystemTime;

use tonlib::address::TonAddress;
use tonlib::cell::BagOfCells;
use tonlib::client::TonClient;
use tonlib::client::TonClientInterface;
use tonlib::contract::TonContractFactory;
use tonlib::contract::JettonMasterContract;
use tonlib::message::JettonTransferMessage;

use tonlib::message::TransferMessage;
use tonlib::mnemonic::KeyPair;
use tonlib::mnemonic::Mnemonic;
use tonlib::wallet::TonWallet;
use tonlib::wallet::WalletVersion;

async fn create_jetton_transfer() -> anyhow::Result<()> {

let seqno:i32 = 30000000;

let self_address: TonAddress = "EQB2BtXDXaQuIcMYW7JEWhHmwHfPPwa-eoCdefiAxOhU3pQg "
    .parse()
    .unwrap();
let mnemonic_str = "mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic mnemonic";
let mnemonic: Mnemonic = Mnemonic::from_str(mnemonic_str, &None).unwrap();
let key_pair: KeyPair = mnemonic.to_key_pair().unwrap();
let jetton_master_address: TonAddress = "EQDCJL0iQHofcBBvFBHdVG233Ri2V4kCNFgfRT-gqAd3Oc86"
    .parse()
    .unwrap();

let client = TonClient::default().await?;
    let contract_factory = TonContractFactory::builder(&client).build().await?;
let jetton_master =
    contract_factory.get_contract(&jetton_master_address);
let self_jetton_wallet_addr = jetton_master.get_wallet_address(&self_address).await?;
let wallet = TonWallet::derive_default(WalletVersion::V4R2, &key_pair)?;
let dest: TonAddress = "<destination wallet address>".parse()?;
let src: TonAddress = "<source wallet address>".parse()?;
let jetton_amount = BigUint::from(1000000u64);
let jetton_transfer = JettonTransferMessage::new(&dest, &jetton_amount)
    .with_query_id(100500)
    .with_response_destination(&self_address)
    .build()?;
let ton_amount = BigUint::from(200000000u64); // 0.2 TON
let transfer = TransferMessage::new(&src, &ton_amount)
    .with_data(jetton_transfer)
    .build()?;
let now = SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH)?
    .as_secs() as u32;
let body = wallet.create_external_body(now + 60, seqno.try_into().unwrap(), vec![transfer])?;
let signed = wallet.sign_external_body(&body)?;
let wrapped = wallet.wrap_signed_body(signed)?;
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 don't known which address is src address

@Ali3219
Copy link

Ali3219 commented Sep 29, 2024

UQAgrdnJW3hgY_8lwnKVJhffo8vmNmtfXHcpr0FZM9M0Bj95

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