tx_cost/
tx_cost.rs

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