[][src]Function hdk::api::send

pub fn send(
    to_agent: Address,
    payload: String,
    timeout: Timeout
) -> ZomeApiResult<String>

Sends a node-to-node message to the given agent, specified by their address. Addresses of agents can be accessed using hdk::AGENT_ADDRESS. This works in conjunction with the receive callback that has to be defined in the define_zome! macro.

This function dispatches a message to the receiver, and will wait up to 60 seconds before returning a timeout error. The send function will return the string returned by the receive callback of the other node.


fn handle_send_message(to_agent: Address, message: String) -> ZomeApiResult<String> {
    // because the function signature of hdk::send is the same as the
    // signature of handle_send_message we can just directly return its' result
    hdk::send(to_agent, message, 60000.into())

define_zome! {
   entries: []

   genesis: || { Ok(()) }

   receive: |payload| {
       // if you want to serialize data as json to pass, use the json! serde macro
           "key": "value"

   functions: [
           send_message: {
               inputs: |to_agent: Address, message: String|,
               outputs: |response: ZomeApiResult<String>|,
               handler: handle_send_message

    traits: {
        hc_public [send_message]