Struct flow_sdk::client::FlowClient[][src]

pub struct FlowClient<T> { /* fields omitted */ }
Expand description

A gRPC client wrapper. Has utility functions for sending requests.

Implementations

Wraps the inner client to gain access to helper functions to send requests.

Retrieve the inner client from this instance.

Gets the inner client as a mutable reference.

Sends a request over the client.

Sends a ping over the network.

Examples found in repository
examples/parse_transaction_arguments.rs (line 7)
 5
 6
 7
 8
 9
10
11
12
13
14
async fn run(tx_id: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let decoded_tx_id = hex::decode(tx_id)?;

    let txn = client.transaction_by_id(&decoded_tx_id).await?;
    println!("{:#?}", txn);
    Ok(())
}
More examples
examples/blocks.rs (line 8)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::testnet().await?;
    client.ping().await?;

    let latest_block = client.latest_block(Seal::Sealed).await?;

    let block_by_id = client.block_by_id(&latest_block.id).await?;

    let block_by_height = client.block_by_height(latest_block.height).await?;

    assert_eq!(latest_block, block_by_id);
    assert_eq!(latest_block, block_by_height);

    println!("OK: {:#?}", latest_block);

    Ok(())
}
examples/scripts.rs (line 37)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let ret = client
        .execute_script_at_latest_block(
            SIMPLE_SCRIPT,
            [ValueRef::Int(cadence_json::BigInt::from(32))],
        )
        .await?
        .parse()?;

    println!("{:#?}", ret);

    let ret = client
        .execute_script_at_latest_block(COMPLEX_SCRIPT, [ValueRef::String("John Doe")])
        .await?
        .parse()?;

    println!("{:#?}", ret);

    Ok(())
}
examples/helloworld.rs (line 10)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut net = TonicHyperFlowClient::testnet().await?;
    let _ = net.ping().await?;
    let latest_block_header = net.latest_block_header(Seal::Sealed).await?;
    println!("{:?}", latest_block_header);
    let Timestamp { nanos, seconds } = latest_block_header.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    println!("----------------");

    let block_header2 = net
        .block_header_by_height(latest_block_header.height)
        .await?;
    println!("{:?}", block_header2);
    let Timestamp { nanos, seconds } = block_header2.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    assert_eq!(latest_block_header, block_header2);

    Ok(())
}
examples/collections.rs (line 8)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let mut latest_block = client.latest_block(Seal::Sealed).await?;

    // traverse latest blocks until we find a collection guarantee.
    let collection_guarrantee = loop {
        if latest_block.collection_guarantees.is_empty() {
            // Go to the next block
            latest_block = client.block_by_id(&latest_block.parent_id).await?;
        } else {
            break latest_block.collection_guarantees.pop().unwrap();
        }
    };

    // retrieve the collection by id.
    let collection = client
        .collection_by_id(&collection_guarrantee.collection_id)
        .await?;

    println!("OK: {:#?}", collection);

    Ok(())
}
examples/events.rs (line 8)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 20;

    println!(
        "Searching for accounts created within the last 20 blocks ({}-{})...",
        start_height, latest_block_height
    );

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        if events.events.is_empty() {
            continue;
        }
        println!(
            "\nBlock #{} ({}):",
            events.block_height,
            hex::encode(&events.block_id)
        );
        for event in events.events.iter() {
            let val = event.parse_payload()?;

            println!("  - {:#?}", val);
        }
    }

    Ok(())
}

Retrieves events with the specified type within the specified range.

Examples found in repository
examples/events.rs (line 19)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 20;

    println!(
        "Searching for accounts created within the last 20 blocks ({}-{})...",
        start_height, latest_block_height
    );

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        if events.events.is_empty() {
            continue;
        }
        println!(
            "\nBlock #{} ({}):",
            events.block_height,
            hex::encode(&events.block_id)
        );
        for event in events.events.iter() {
            let val = event.parse_payload()?;

            println!("  - {:#?}", val);
        }
    }

    Ok(())
}
More examples
examples/accounts.rs (line 21)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 100;

    println!(
        "Searching for accounts created within the last 100 blocks ({}-{})...",
        start_height, latest_block_height
    );

    let mut accounts = Vec::new();

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        for event in events.events.iter() {
            let val: cadence_json::ValueOwned = serde_json::from_slice(&event.payload)?;

            if let cadence_json::ValueOwned::Event(c) = val {
                for field in c.fields.into_iter().filter(|f| f.name == "address") {
                    if let cadence_json::ValueOwned::Address(addr) = field.value {
                        accounts.push(client.account_at_latest_block(&addr.data).await?);
                    }
                }
            }
        }
    }

    println!("Found {} accounts.", accounts.len());

    if let Some(acc) = accounts.into_iter().max_by_key(|acc| acc.balance) {
        println!(
            "\nThe richest account is 0x{} with a balance of {}.",
            hex::encode(acc.address),
            acc.balance
        );
    }

    Ok(())
}

Retrieves events with the specified type with the specified block ids.

Executes Cadence script at the latest block and returns the result.

Examples found in repository
examples/scripts.rs (lines 40-43)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let ret = client
        .execute_script_at_latest_block(
            SIMPLE_SCRIPT,
            [ValueRef::Int(cadence_json::BigInt::from(32))],
        )
        .await?
        .parse()?;

    println!("{:#?}", ret);

    let ret = client
        .execute_script_at_latest_block(COMPLEX_SCRIPT, [ValueRef::String("John Doe")])
        .await?
        .parse()?;

    println!("{:#?}", ret);

    Ok(())
}

Executes Cadence script at a specific block height and returns the result.

Executes Cadence script at a specific block height and returns the result.

Sends a transaction over the network.

Retrieves a transaction’s result by its ID.

Retrieves a transaction by its ID.

Examples found in repository
examples/parse_transaction_arguments.rs (line 11)
 5
 6
 7
 8
 9
10
11
12
13
14
async fn run(tx_id: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let decoded_tx_id = hex::decode(tx_id)?;

    let txn = client.transaction_by_id(&decoded_tx_id).await?;
    println!("{:#?}", txn);
    Ok(())
}

Retrieves information about an account at the latest block.

Examples found in repository
examples/get_account_info.rs (line 22)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    println!("Enter the account's address:");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let mut net = TonicHyperFlowClient::mainnet().await?;

    let account = net.account_at_latest_block(&address.data).await?;

    let latest_block_height = net.latest_block_header(Seal::Sealed).await?.height;

    let account1 = net
        .account_at_block_height(&address.data, latest_block_height)
        .await?;

    println!("{:#?}", account);

    assert_eq!(account, account1);

    Ok(())
}
More examples
examples/accounts.rs (line 32)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 100;

    println!(
        "Searching for accounts created within the last 100 blocks ({}-{})...",
        start_height, latest_block_height
    );

    let mut accounts = Vec::new();

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        for event in events.events.iter() {
            let val: cadence_json::ValueOwned = serde_json::from_slice(&event.payload)?;

            if let cadence_json::ValueOwned::Event(c) = val {
                for field in c.fields.into_iter().filter(|f| f.name == "address") {
                    if let cadence_json::ValueOwned::Address(addr) = field.value {
                        accounts.push(client.account_at_latest_block(&addr.data).await?);
                    }
                }
            }
        }
    }

    println!("Found {} accounts.", accounts.len());

    if let Some(acc) = accounts.into_iter().max_by_key(|acc| acc.balance) {
        println!(
            "\nThe richest account is 0x{} with a balance of {}.",
            hex::encode(acc.address),
            acc.balance
        );
    }

    Ok(())
}

Retrieves information about an account at the specified block height.

Examples found in repository
examples/get_account_info.rs (line 27)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    println!("Enter the account's address:");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let mut net = TonicHyperFlowClient::mainnet().await?;

    let account = net.account_at_latest_block(&address.data).await?;

    let latest_block_height = net.latest_block_header(Seal::Sealed).await?.height;

    let account1 = net
        .account_at_block_height(&address.data, latest_block_height)
        .await?;

    println!("{:#?}", account);

    assert_eq!(account, account1);

    Ok(())
}

Retrieves header information of the latest block.

Examples found in repository
examples/get_account_info.rs (line 24)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    println!("Enter the account's address:");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let mut net = TonicHyperFlowClient::mainnet().await?;

    let account = net.account_at_latest_block(&address.data).await?;

    let latest_block_height = net.latest_block_header(Seal::Sealed).await?.height;

    let account1 = net
        .account_at_block_height(&address.data, latest_block_height)
        .await?;

    println!("{:#?}", account);

    assert_eq!(account, account1);

    Ok(())
}
More examples
examples/helloworld.rs (line 11)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut net = TonicHyperFlowClient::testnet().await?;
    let _ = net.ping().await?;
    let latest_block_header = net.latest_block_header(Seal::Sealed).await?;
    println!("{:?}", latest_block_header);
    let Timestamp { nanos, seconds } = latest_block_header.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    println!("----------------");

    let block_header2 = net
        .block_header_by_height(latest_block_header.height)
        .await?;
    println!("{:?}", block_header2);
    let Timestamp { nanos, seconds } = block_header2.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    assert_eq!(latest_block_header, block_header2);

    Ok(())
}
examples/events.rs (line 10)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 20;

    println!(
        "Searching for accounts created within the last 20 blocks ({}-{})...",
        start_height, latest_block_height
    );

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        if events.events.is_empty() {
            continue;
        }
        println!(
            "\nBlock #{} ({}):",
            events.block_height,
            hex::encode(&events.block_id)
        );
        for event in events.events.iter() {
            let val = event.parse_payload()?;

            println!("  - {:#?}", val);
        }
    }

    Ok(())
}
examples/accounts.rs (line 10)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 100;

    println!(
        "Searching for accounts created within the last 100 blocks ({}-{})...",
        start_height, latest_block_height
    );

    let mut accounts = Vec::new();

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        for event in events.events.iter() {
            let val: cadence_json::ValueOwned = serde_json::from_slice(&event.payload)?;

            if let cadence_json::ValueOwned::Event(c) = val {
                for field in c.fields.into_iter().filter(|f| f.name == "address") {
                    if let cadence_json::ValueOwned::Address(addr) = field.value {
                        accounts.push(client.account_at_latest_block(&addr.data).await?);
                    }
                }
            }
        }
    }

    println!("Found {} accounts.", accounts.len());

    if let Some(acc) = accounts.into_iter().max_by_key(|acc| acc.balance) {
        println!(
            "\nThe richest account is 0x{} with a balance of {}.",
            hex::encode(acc.address),
            acc.balance
        );
    }

    Ok(())
}

Retrieves header information of a block specified by its height.

Examples found in repository
examples/helloworld.rs (line 19)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut net = TonicHyperFlowClient::testnet().await?;
    let _ = net.ping().await?;
    let latest_block_header = net.latest_block_header(Seal::Sealed).await?;
    println!("{:?}", latest_block_header);
    let Timestamp { nanos, seconds } = latest_block_header.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    println!("----------------");

    let block_header2 = net
        .block_header_by_height(latest_block_header.height)
        .await?;
    println!("{:?}", block_header2);
    let Timestamp { nanos, seconds } = block_header2.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    assert_eq!(latest_block_header, block_header2);

    Ok(())
}

Retrieves header information of a block specified by its ID.

Retrieves full information of the latest block.

Examples found in repository
examples/blocks.rs (line 10)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::testnet().await?;
    client.ping().await?;

    let latest_block = client.latest_block(Seal::Sealed).await?;

    let block_by_id = client.block_by_id(&latest_block.id).await?;

    let block_by_height = client.block_by_height(latest_block.height).await?;

    assert_eq!(latest_block, block_by_id);
    assert_eq!(latest_block, block_by_height);

    println!("OK: {:#?}", latest_block);

    Ok(())
}
More examples
examples/collections.rs (line 10)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let mut latest_block = client.latest_block(Seal::Sealed).await?;

    // traverse latest blocks until we find a collection guarantee.
    let collection_guarrantee = loop {
        if latest_block.collection_guarantees.is_empty() {
            // Go to the next block
            latest_block = client.block_by_id(&latest_block.parent_id).await?;
        } else {
            break latest_block.collection_guarantees.pop().unwrap();
        }
    };

    // retrieve the collection by id.
    let collection = client
        .collection_by_id(&collection_guarrantee.collection_id)
        .await?;

    println!("OK: {:#?}", collection);

    Ok(())
}

Retrieves full information of a block specified by its height.

Examples found in repository
examples/blocks.rs (line 14)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::testnet().await?;
    client.ping().await?;

    let latest_block = client.latest_block(Seal::Sealed).await?;

    let block_by_id = client.block_by_id(&latest_block.id).await?;

    let block_by_height = client.block_by_height(latest_block.height).await?;

    assert_eq!(latest_block, block_by_id);
    assert_eq!(latest_block, block_by_height);

    println!("OK: {:#?}", latest_block);

    Ok(())
}

Retrieves full information of a block specified by its ID.

Examples found in repository
examples/blocks.rs (line 12)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::testnet().await?;
    client.ping().await?;

    let latest_block = client.latest_block(Seal::Sealed).await?;

    let block_by_id = client.block_by_id(&latest_block.id).await?;

    let block_by_height = client.block_by_height(latest_block.height).await?;

    assert_eq!(latest_block, block_by_id);
    assert_eq!(latest_block, block_by_height);

    println!("OK: {:#?}", latest_block);

    Ok(())
}
More examples
examples/collections.rs (line 16)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let mut latest_block = client.latest_block(Seal::Sealed).await?;

    // traverse latest blocks until we find a collection guarantee.
    let collection_guarrantee = loop {
        if latest_block.collection_guarantees.is_empty() {
            // Go to the next block
            latest_block = client.block_by_id(&latest_block.parent_id).await?;
        } else {
            break latest_block.collection_guarantees.pop().unwrap();
        }
    };

    // retrieve the collection by id.
    let collection = client
        .collection_by_id(&collection_guarrantee.collection_id)
        .await?;

    println!("OK: {:#?}", collection);

    Ok(())
}

Retrieves information of a collection specified by its ID.

Examples found in repository
examples/collections.rs (line 24)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let mut latest_block = client.latest_block(Seal::Sealed).await?;

    // traverse latest blocks until we find a collection guarantee.
    let collection_guarrantee = loop {
        if latest_block.collection_guarantees.is_empty() {
            // Go to the next block
            latest_block = client.block_by_id(&latest_block.parent_id).await?;
        } else {
            break latest_block.collection_guarantees.pop().unwrap();
        }
    };

    // retrieve the collection by id.
    let collection = client
        .collection_by_id(&collection_guarrantee.collection_id)
        .await?;

    println!("OK: {:#?}", collection);

    Ok(())
}

Connects to a static endpoint URI.

Connects to an endpoint

Connects to the Mainnet access node provided by Dapper Labs.

Examples found in repository
examples/parse_transaction_arguments.rs (line 6)
 5
 6
 7
 8
 9
10
11
12
13
14
async fn run(tx_id: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let decoded_tx_id = hex::decode(tx_id)?;

    let txn = client.transaction_by_id(&decoded_tx_id).await?;
    println!("{:#?}", txn);
    Ok(())
}
More examples
examples/scripts.rs (line 36)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let ret = client
        .execute_script_at_latest_block(
            SIMPLE_SCRIPT,
            [ValueRef::Int(cadence_json::BigInt::from(32))],
        )
        .await?
        .parse()?;

    println!("{:#?}", ret);

    let ret = client
        .execute_script_at_latest_block(COMPLEX_SCRIPT, [ValueRef::String("John Doe")])
        .await?
        .parse()?;

    println!("{:#?}", ret);

    Ok(())
}
examples/get_account_info.rs (line 20)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    println!("Enter the account's address:");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let mut net = TonicHyperFlowClient::mainnet().await?;

    let account = net.account_at_latest_block(&address.data).await?;

    let latest_block_height = net.latest_block_header(Seal::Sealed).await?.height;

    let account1 = net
        .account_at_block_height(&address.data, latest_block_height)
        .await?;

    println!("{:#?}", account);

    assert_eq!(account, account1);

    Ok(())
}
examples/collections.rs (line 7)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let mut latest_block = client.latest_block(Seal::Sealed).await?;

    // traverse latest blocks until we find a collection guarantee.
    let collection_guarrantee = loop {
        if latest_block.collection_guarantees.is_empty() {
            // Go to the next block
            latest_block = client.block_by_id(&latest_block.parent_id).await?;
        } else {
            break latest_block.collection_guarantees.pop().unwrap();
        }
    };

    // retrieve the collection by id.
    let collection = client
        .collection_by_id(&collection_guarrantee.collection_id)
        .await?;

    println!("OK: {:#?}", collection);

    Ok(())
}
examples/events.rs (line 7)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 20;

    println!(
        "Searching for accounts created within the last 20 blocks ({}-{})...",
        start_height, latest_block_height
    );

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        if events.events.is_empty() {
            continue;
        }
        println!(
            "\nBlock #{} ({}):",
            events.block_height,
            hex::encode(&events.block_id)
        );
        for event in events.events.iter() {
            let val = event.parse_payload()?;

            println!("  - {:#?}", val);
        }
    }

    Ok(())
}
examples/accounts.rs (line 7)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::mainnet().await?;
    client.ping().await?;

    let latest_block_height = client.latest_block_header(Seal::Sealed).await?.height;
    let start_height = latest_block_height - 100;

    println!(
        "Searching for accounts created within the last 100 blocks ({}-{})...",
        start_height, latest_block_height
    );

    let mut accounts = Vec::new();

    for events in client
        .events_for_height_range("flow.AccountCreated", start_height, latest_block_height)
        .await?
        .results
        .iter()
    {
        for event in events.events.iter() {
            let val: cadence_json::ValueOwned = serde_json::from_slice(&event.payload)?;

            if let cadence_json::ValueOwned::Event(c) = val {
                for field in c.fields.into_iter().filter(|f| f.name == "address") {
                    if let cadence_json::ValueOwned::Address(addr) = field.value {
                        accounts.push(client.account_at_latest_block(&addr.data).await?);
                    }
                }
            }
        }
    }

    println!("Found {} accounts.", accounts.len());

    if let Some(acc) = accounts.into_iter().max_by_key(|acc| acc.balance) {
        println!(
            "\nThe richest account is 0x{} with a balance of {}.",
            hex::encode(acc.address),
            acc.balance
        );
    }

    Ok(())
}

Connects to the Testnet access node provided by Dapper Labs.

Examples found in repository
examples/blocks.rs (line 7)
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut client = TonicHyperFlowClient::testnet().await?;
    client.ping().await?;

    let latest_block = client.latest_block(Seal::Sealed).await?;

    let block_by_id = client.block_by_id(&latest_block.id).await?;

    let block_by_height = client.block_by_height(latest_block.height).await?;

    assert_eq!(latest_block, block_by_id);
    assert_eq!(latest_block, block_by_height);

    println!("OK: {:#?}", latest_block);

    Ok(())
}
More examples
examples/helloworld.rs (line 9)
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let mut net = TonicHyperFlowClient::testnet().await?;
    let _ = net.ping().await?;
    let latest_block_header = net.latest_block_header(Seal::Sealed).await?;
    println!("{:?}", latest_block_header);
    let Timestamp { nanos, seconds } = latest_block_header.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    println!("----------------");

    let block_header2 = net
        .block_header_by_height(latest_block_header.height)
        .await?;
    println!("{:?}", block_header2);
    let Timestamp { nanos, seconds } = block_header2.timestamp;
    println!("{}", Utc.timestamp(seconds, nanos as u32));

    assert_eq!(latest_block_header, block_header2);

    Ok(())
}
examples/transactions.rs (line 41)
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let mut buf = String::new();

    // Let's make a transaction!

    // First, generate a keypair for us to use.
    let secp = Secp256k1::signing_only();

    // `EntropyRng` is a secure random number generator.
    let mut rng = secp256k1::rand::rngs::EntropyRng::new();
    let secret_key = SecretKey::new(&mut rng);
    let public_key = PublicKey::from_secret_key(&secp, &secret_key);

    // Print the public key as a hexadecimal.
    println!("This is your public key:");
    let public_key_bytes = public_key.serialize_uncompressed();
    // There is a leading 0x04 which we don't need to emit
    // https://bitcoin.stackexchange.com/a/3043
    for ch in &public_key_bytes[1..] {
        print!("{:02x}", *ch);
    }
    println!();
    println!("Go to https://flow-faucet.vercel.app/, select secp256k1 and sha3 and create your testnet account.");
    println!("Paste the address you get and press ENTER to continue");

    stdin.read_line(&mut buf)?;

    let addr = buf.trim();

    let address: AddressOwned = addr.parse()?;
    let net = TonicHyperFlowClient::testnet().await?;

    let mut account = Account::<_, _>::new(net, &address.data, secret_key).await?;

    let create_account = CreateAccountTransaction {
        public_keys: &[public_key],
    };

    let create_account_header = create_account.to_header::<_, tiny_keccak::Sha3>(account.signer());
    let res = account
        .send_transaction_header(&create_account_header)
        .await?;

    println!(
        "Just made {} to create another account :p",
        hex::encode(&res.id)
    );

    let response = res.finalize(account.client()).await?;

    match response {
        Some(res) => {
            for ev in res.events.iter() {
                if ev.ty == "flow.AccountCreated" {
                    let payload = ev.parse_payload()?;

                    let addr = payload
                        .fields
                        .into_iter()
                        .find(|field| field.name == "address")
                        .map(|field| field.value)
                        .unwrap();
                    if let ValueOwned::Address(addr) = addr {
                        println!("Created account's address is: {}", addr);
                    }
                }
            }
        }
        None => {
            panic!("The transaction did not get sealed... Perhaps the network is malfunctioning?")
        }
    }

    Ok(())
}

Connects to a static endpoint URI. Does not connect until we try to send a request.

Note: You must have entered the tokio runtime context before calling this function. You can do so by writing the code down below, or it will automatically be entered, if you have an .await before calling this. Consider using the async functions instead.

let handle = tokio::runtime::Handle::current();
handle.enter();

Connects to an endpoint. Does not connect until we try to send a request.

Note: You must have entered the tokio runtime context before calling this function. You can do so by writing the code down below, or it will automatically be entered, if you have an .await before calling this. Consider using the async functions instead.

let handle = tokio::runtime::Handle::current();
handle.enter();

Builds a lazy connection to the Mainnet access node provided by Dapper Labs.

Note: You must have entered the tokio runtime context before calling this function. You can do so by writing the code down below, or it will automatically be entered, if you have an .await before calling this. Consider using the async functions instead.

let handle = tokio::runtime::Handle::current();
handle.enter();

Builds a lazy connection to the Testnet access node provided by Dapper Labs.

Note: You must have entered the tokio runtime context before calling this function. You can do so by writing the code down below, or it will automatically be entered, if you have an .await before calling this. Consider using the async functions instead.

let handle = tokio::runtime::Handle::current();
handle.enter();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The error type of the client.

Sends a request with the client. Returns a future that evaluates a Result, potentially containing the output. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Wrap the input message T in a tonic::Request

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more