ston-fi / tonlib-rs

Rust SDK for The Open Network
https://github.com/ston-fi/tonlib-rs
MIT License
194 stars 42 forks source link

read me sample not work #73

Open StewartYe opened 4 months ago

StewartYe commented 4 months ago

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 commented 1 month ago

UQAgrdnJW3hgY_8lwnKVJhffo8vmNmtfXHcpr0FZM9M0Bj95