Skip to content

Submit a script and parse the response

MarshallBelles edited this page Oct 15, 2021 · 1 revision

Example:

use flow_rust_sdk::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut connection = FlowConnection::new("grpc://localhost:3569").await?;

    let script = b"
        pub fun main(): String {
            return \"Hello World!\"
        }
    ";
    let arguments: Vec<Vec<u8>> = vec![];
    let result: Value = from_slice(
        &connection
            .execute_script(script.to_vec(), arguments)
            .await?
            .value,
    )?;
    println!("Script result: {}", result["value"]);
    Ok(())
}