tx_cost/
tx_cost.rs

1use multiversx_sdk::{
2    chain_core::std::Bech32Address, data::transaction::Transaction, utils::base64_encode,
3};
4use multiversx_sdk_http::{DEVNET_GATEWAY, GatewayHttpProxy};
5
6#[tokio::main]
7async fn main() {
8    let tx = Transaction {
9        nonce: 1,
10        value: "50".to_string(),
11        receiver: Bech32Address::from_bech32_string(
12            "erd1rh5ws22jxm9pe7dtvhfy6j3uttuupkepferdwtmslms5fydtrh5sx3xr8r".to_owned(),
13        ),
14        sender: Bech32Address::from_bech32_string(
15            "erd1rh5ws22jxm9pe7dtvhfy6j3uttuupkepferdwtmslms5fydtrh5sx3xr8r".to_owned(),
16        ),
17        data: Some(base64_encode("hello")),
18        chain_id: "1".to_string(),
19        version: 1,
20        options: 0,
21        gas_limit: 0,
22        gas_price: 0,
23        signature: None,
24    };
25
26    let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
27    let cost = blockchain.request_transaction_cost(&tx).await.unwrap();
28
29    println!("tx cost: {cost:#?}");
30
31    assert_eq!(
32        cost.tx_gas_units, 57500,
33        "receive cost {}",
34        cost.tx_gas_units
35    );
36}